jkfdkjlfdslkjfdkjsdfjk ksd
This commit is contained in:
parent
2e37399d86
commit
159bd31323
@ -1,7 +1,6 @@
|
|||||||
// Modul na komand "anketa"
|
// Modul na komand "anketa"
|
||||||
|
|
||||||
import { ActionRowBuilder, APIEmbed, ButtonBuilder, ButtonStyle, Message, MessageComponentInteraction } from "discord.js";
|
import { ActionRowBuilder, APIEmbed, APIEmbedField, ButtonBuilder, ButtonStyle, Message, MessageComponentInteraction } from "discord.js";
|
||||||
import { emouty } from "../utils/emotes";
|
|
||||||
import { Modul } from "../utils/types";
|
import { Modul } from "../utils/types";
|
||||||
import { formatter } from "../utils/utils";
|
import { formatter } from "../utils/utils";
|
||||||
|
|
||||||
@ -9,24 +8,30 @@ const exp: Modul = {
|
|||||||
more_komandy: {
|
more_komandy: {
|
||||||
|
|
||||||
anketa: {
|
anketa: {
|
||||||
arg: "nastavení asi IDK",
|
arg: "([nastaveni]) moznosti...",
|
||||||
run: async (mes, arg) => {
|
run: async (mes, arg) => {
|
||||||
const args = arg.toLocaleLowerCase().split(" ");
|
|
||||||
|
|
||||||
const settings = {
|
const settings = {
|
||||||
time: 60,
|
time: 60,
|
||||||
immediateShow: true
|
immediateShow: true,
|
||||||
|
listNames: false
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (args[0]) {
|
let huuuuuu = -1;
|
||||||
case "custom":
|
if (arg.startsWith("[")) {
|
||||||
case "vlastni":
|
huuuuuu = arg.indexOf("]");
|
||||||
return `tuto jeste neni implemenovany ${emouty.sjeta}`;
|
const hovn = arg.slice(1, huuuuuu);
|
||||||
|
const f = hovn.split(" ");
|
||||||
|
for (const s of f) {
|
||||||
|
const t = Number(s);
|
||||||
|
if (!Number.isNaN(t)) settings.time = t;
|
||||||
|
else if (s == "jmena") settings.listNames = true;
|
||||||
|
else if (s == "neprubezny") settings.immediateShow = false;
|
||||||
|
else return `"${s}" neznam znam jenom jmena a neprubezny`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case "start":
|
const moznosti = arg.slice(huuuuuu + 1).split(arg.includes("|") ? "|" : ",").reduce<string[]>((acc, c) => {
|
||||||
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());
|
if (c.length) acc.push(c.trim());
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
@ -37,9 +42,9 @@ const exp: Modul = {
|
|||||||
|
|
||||||
const embed: APIEmbed = {
|
const embed: APIEmbed = {
|
||||||
title: "Hlasování",
|
title: "Hlasování",
|
||||||
description: settings.immediateShow ? `Končí ${formatter(konec)}` : `Výsledky se zobrazí ${formatter(konec)}`,
|
description: settings.immediateShow ? `Končí ${formatter(konec)}` : `Výsledky se zobrazí ${formatter(konec)}`
|
||||||
fields: []
|
|
||||||
};
|
};
|
||||||
|
const x5fxd55: APIEmbedField[] = [];
|
||||||
const radek = new ActionRowBuilder<ButtonBuilder>();
|
const radek = new ActionRowBuilder<ButtonBuilder>();
|
||||||
const odpovedi: Record<string, number> = {};
|
const odpovedi: Record<string, number> = {};
|
||||||
|
|
||||||
@ -47,20 +52,26 @@ const exp: Modul = {
|
|||||||
function prepocitat(int: MessageComponentInteraction): void;
|
function prepocitat(int: MessageComponentInteraction): void;
|
||||||
function prepocitat(int?: MessageComponentInteraction) {
|
function prepocitat(int?: MessageComponentInteraction) {
|
||||||
const celkem = Object.keys(odpovedi).length;
|
const celkem = Object.keys(odpovedi).length;
|
||||||
embed.fields?.forEach((f, i) => {
|
x5fxd55.forEach((f, i) => {
|
||||||
const hovn = Object.values(odpovedi).filter(n => n == i);
|
const hovn = Object.values(odpovedi).filter(n => n == i);
|
||||||
const dylka = hovn.length;
|
const dylka = hovn.length;
|
||||||
const p = Math.floor(dylka / celkem * 10) || 0;
|
const p = Math.floor(dylka / celkem * 10) || 0;
|
||||||
f.value = `${"█".repeat(p)}${"░".repeat(10 - p)} ${Math.round(dylka / celkem * 100) || 0}% (${dylka})`;
|
const people = Object.keys(odpovedi).reduce<string[]>((pr, cur) => {
|
||||||
|
if (odpovedi[cur] == i) pr.push(cur);
|
||||||
|
return pr;
|
||||||
|
}, []);
|
||||||
|
const kindo = people.map(w => mes.guild?.members.cache.get(w)?.displayName);
|
||||||
|
f.value = `${"█".repeat(p)}${"░".repeat(10 - p)} ${Math.round(dylka / celkem * 100) || 0}% (${dylka}) ${settings.listNames ? " (" + kindo.join(", ") + ")" : ""}`;
|
||||||
});
|
});
|
||||||
int?.update({ embeds: [embed] });
|
int?.update({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
moznosti.forEach((h, i) => {
|
moznosti.forEach((h, i) => {
|
||||||
if (settings.immediateShow) embed.fields?.push({ name: h, value: "" });
|
x5fxd55.push({ name: h, value: "" });
|
||||||
radek.addComponents(new ButtonBuilder({ customId: `${i}`, label: h, style: ButtonStyle.Primary }));
|
radek.addComponents(new ButtonBuilder({ customId: `${i}`, label: h, style: ButtonStyle.Primary }));
|
||||||
});
|
});
|
||||||
prepocitat();
|
prepocitat();
|
||||||
|
if (settings.immediateShow) embed.fields = x5fxd55;
|
||||||
const zprava = await mes.channel.send({ embeds: [embed], components: [radek] });
|
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 });
|
const collector = mes.channel.createMessageComponentCollector({ filter: i => i.message.id == zprava.id, time: settings.time * 1000 });
|
||||||
|
|
||||||
@ -71,21 +82,18 @@ const exp: Modul = {
|
|||||||
if (prev == i) return void d.deferUpdate();
|
if (prev == i) return void d.deferUpdate();
|
||||||
odpovedi[d.user.id] = i;
|
odpovedi[d.user.id] = i;
|
||||||
if (!settings.immediateShow) return void d.deferUpdate();
|
if (!settings.immediateShow) return void d.deferUpdate();
|
||||||
prepocitat(d);
|
prepocitat();
|
||||||
|
d.update({ embeds: [embed] });
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on("end", () => {
|
collector.on("end", () => {
|
||||||
embed.description = `Skončilo ${formatter(konec)}`;
|
embed.description = `Skončilo ${formatter(konec)}`;
|
||||||
if (!settings.immediateShow) prepocitat();
|
prepocitat();
|
||||||
|
embed.fields = x5fxd55;
|
||||||
zprava.edit({ components: [], embeds: [embed] });
|
zprava.edit({ components: [], embeds: [embed] });
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
return `takovi to "${args[0]}" sem moc nepochitil`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
2
start.sh
2
start.sh
@ -8,7 +8,7 @@ do
|
|||||||
git pull
|
git pull
|
||||||
npm i --omit=dev
|
npm i --omit=dev
|
||||||
tsc >/dev/null
|
tsc >/dev/null
|
||||||
unset $neco
|
unset neco
|
||||||
else
|
else
|
||||||
echo exit code byl $?
|
echo exit code byl $?
|
||||||
novejcas=$(date +"%s")
|
novejcas=$(date +"%s")
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
process.env.ignorePresence = "J";
|
process.env.ignorePresence = "J";
|
||||||
const { statusOnFoun } = require("../out/utils/utils.js");
|
const { statusOnFoun } = require("../out/utils/utils.js");
|
||||||
|
|
||||||
const get = (a, b) => statusOnFoun(null, { status: a, clientStatus: b })[1];
|
const stat = (a, b) => statusOnFoun(null, { status: a, clientStatus: b })[1];
|
||||||
|
|
||||||
test("Zobrazovani spravne statusu", () => {
|
test("Zobrazovani spravne statusu", () => {
|
||||||
expect(get("online", { desktop: "online" })).toBe("Online");
|
expect(stat("online", { desktop: "online" })).toBe("Online");
|
||||||
expect(get("online", { mobile: "online" })).toBe("OnlinePhone");
|
expect(stat("online", { mobile: "online" })).toBe("OnlinePhone");
|
||||||
expect(get("online", { web: "idle", desktop: "online" })).toBe("Online");
|
expect(stat("online", { web: "idle", desktop: "online" })).toBe("Online");
|
||||||
expect(get("online", { desktop: "online", mobile: "idle" })).toBe("Online");
|
expect(stat("online", { desktop: "online", mobile: "idle" })).toBe("Online");
|
||||||
expect(get("online", { web: "idle", mobile: "online" })).toBe("OnlinePhone");
|
expect(stat("online", { web: "idle", mobile: "online" })).toBe("OnlinePhone");
|
||||||
expect(get("idle", { web: "idle" })).toBe("Idle");
|
expect(stat("idle", { web: "idle" })).toBe("Idle");
|
||||||
expect(get("dnd", { web: "dnd" })).toBe("DND");
|
expect(stat("dnd", { web: "dnd" })).toBe("DND");
|
||||||
expect(get("offline", {})).toBe("Offline");
|
expect(stat("offline", {})).toBe("Offline");
|
||||||
expect(get("offline", null)).toBe("Offline");
|
expect(stat("offline", null)).toBe("Offline");
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user