added fekal more anketa
This commit is contained in:
parent
4a539d4b0c
commit
8e4d75f664
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.35.0",
|
"version": "3001.36.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.35.0",
|
"version": "3001.36.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/opus": "github:discordjs/opus",
|
"@discordjs/opus": "github:discordjs/opus",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "denim_3001",
|
"name": "denim_3001",
|
||||||
"version": "3001.35.0",
|
"version": "3001.36.0",
|
||||||
"description": "Toto je velmi kvalitní bot.",
|
"description": "Toto je velmi kvalitní bot.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "https://github.com/Histmy/Denim-Bot/"
|
"url": "https://github.com/Histmy/Denim-Bot/"
|
||||||
|
|||||||
92
src/modules/anketa.ts
Normal file
92
src/modules/anketa.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// Modul na komand "anketa"
|
||||||
|
|
||||||
|
import { Message, MessageActionRow, MessageButton, MessageComponentInteraction, MessageEmbedOptions } from "discord.js";
|
||||||
|
import { emouty } from "../utils/emotes";
|
||||||
|
import { Modul } from "../utils/types";
|
||||||
|
import { formatter } from "../utils/utils";
|
||||||
|
|
||||||
|
const exp: Modul = {
|
||||||
|
more_komandy: {
|
||||||
|
|
||||||
|
anketa: {
|
||||||
|
arg: "nastavení asi IDK",
|
||||||
|
run: async (mes, arg) => {
|
||||||
|
const args = arg.toLocaleLowerCase().split(" ");
|
||||||
|
|
||||||
|
let settings = {
|
||||||
|
time: 60,
|
||||||
|
immediateShow: true
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (args[0]) {
|
||||||
|
case "custom":
|
||||||
|
case "vlastni":
|
||||||
|
return `tuto jeste neni implemenovany ${emouty.sjeta}`;
|
||||||
|
|
||||||
|
case "start":
|
||||||
|
case "zapnout":
|
||||||
|
const temp = args.slice(1).join(" ");
|
||||||
|
const moznosti = temp.split(temp.indexOf("|") > -1 ? "|" : ",").reduce<string[]>((acc, c) => {
|
||||||
|
if (c.length) acc.push(c.trim());
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
if (moznosti.length < 2) return "zadej alespo%n dve moznosti";
|
||||||
|
|
||||||
|
const konec = new Date();
|
||||||
|
konec.setSeconds(konec.getSeconds() + settings.time);
|
||||||
|
|
||||||
|
const embed: MessageEmbedOptions = {
|
||||||
|
title: "Hlasování",
|
||||||
|
description: settings.immediateShow ? `Končí ${formatter(konec)}` : `Výsledky se zobrazí ${formatter(konec)}`,
|
||||||
|
fields: []
|
||||||
|
};
|
||||||
|
const radek = new MessageActionRow();
|
||||||
|
const odpovedi: Record<string, number> = {};
|
||||||
|
|
||||||
|
function prepocitat(): void;
|
||||||
|
function prepocitat(int: MessageComponentInteraction): void;
|
||||||
|
function prepocitat(int?: MessageComponentInteraction) {
|
||||||
|
const celkem = Object.keys(odpovedi).length;
|
||||||
|
embed.fields?.forEach((f, i) => {
|
||||||
|
const hovn = Object.values(odpovedi).filter(n => n == i);
|
||||||
|
const dylka = hovn.length;
|
||||||
|
const p = Math.floor(dylka / celkem * 10) || 0;
|
||||||
|
f.value = `${"█".repeat(p)}${"░".repeat(10 - p)} ${Math.round(dylka / celkem * 100) || 0}% (${dylka})`;
|
||||||
|
});
|
||||||
|
int?.update({ embeds: [embed] });
|
||||||
|
}
|
||||||
|
|
||||||
|
moznosti.forEach((h, i) => {
|
||||||
|
if (settings.immediateShow) embed.fields?.push({ name: h, value: "" });
|
||||||
|
radek.addComponents(new MessageButton({ customId: `${i}`, label: h, style: "PRIMARY" }));
|
||||||
|
});
|
||||||
|
prepocitat();
|
||||||
|
const zprava = await mes.channel.send({ embeds: [embed], components: [radek] });
|
||||||
|
const collector = mes.channel.createMessageComponentCollector({ filter: i => i.message.id == zprava.id, time: settings.time * 1000 });
|
||||||
|
|
||||||
|
collector.on("collect", d => {
|
||||||
|
if (!(d.message instanceof Message)) return;
|
||||||
|
const i = Number(d.customId);
|
||||||
|
const prev = odpovedi[d.user.id];
|
||||||
|
if (prev == i) return d.deferUpdate();
|
||||||
|
odpovedi[d.user.id] = i;
|
||||||
|
if (!settings.immediateShow) return d.deferUpdate();
|
||||||
|
prepocitat(d);
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on("end", () => {
|
||||||
|
embed.description = `Skončilo ${formatter(konec)}`;
|
||||||
|
if (!settings.immediateShow) prepocitat();
|
||||||
|
zprava.edit({ components: [], embeds: [embed] });
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return `takovi to "${args[0]}" sem moc nepochitil`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = exp;
|
||||||
@ -24,26 +24,26 @@ const exp: Modul = {
|
|||||||
|
|
||||||
online: {
|
online: {
|
||||||
als: ["onlajn", "zelenej"],
|
als: ["onlajn", "zelenej"],
|
||||||
run: (mes) => changeStatus(mes, "online")
|
run: mes => changeStatus(mes, "online")
|
||||||
},
|
},
|
||||||
idle: {
|
idle: {
|
||||||
als: ["zlutej", "afk", "idle", "nepritomnej"],
|
als: ["zlutej", "afk", "idle", "nepritomnej"],
|
||||||
run: (mes) => changeStatus(mes, "idle")
|
run: mes => changeStatus(mes, "idle")
|
||||||
},
|
},
|
||||||
dnd: {
|
dnd: {
|
||||||
als: ["nerusit", "cervenej"],
|
als: ["nerusit", "cervenej"],
|
||||||
run: (mes) => changeStatus(mes, "dnd")
|
run: mes => changeStatus(mes, "dnd")
|
||||||
},
|
},
|
||||||
offline: {
|
offline: {
|
||||||
als: ["oflajn", "neviditelnej"],
|
als: ["oflajn", "neviditelnej"],
|
||||||
run: (mes) => changeStatus(mes, "invisible")
|
run: mes => changeStatus(mes, "invisible")
|
||||||
},
|
},
|
||||||
|
|
||||||
hraj: (mes, co) => changeActivity(mes, "PLAYING", co),
|
hraj: (mes, co) => changeActivity(mes, "PLAYING", co),
|
||||||
sleduj: (mes, co) => changeActivity(mes, "WATCHING", co),
|
sleduj: (mes, co) => changeActivity(mes, "WATCHING", co),
|
||||||
poslouchej: (mes, co) => changeActivity(mes, "LISTENING", co),
|
poslouchej: (mes, co) => changeActivity(mes, "LISTENING", co),
|
||||||
soutez: (mes, vcem) => changeActivity(mes, "COMPETING", vcem),
|
soutez: (mes, vcem) => changeActivity(mes, "COMPETING", vcem),
|
||||||
nedelej: (mes) => changeActivity(mes),
|
nedelej: mes => changeActivity(mes),
|
||||||
|
|
||||||
fight: {
|
fight: {
|
||||||
als: ["figh", "fajt"],
|
als: ["figh", "fajt"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user