added pgn random

This commit is contained in:
Histmy 2021-11-16 18:37:49 +01:00
parent cdfe219609
commit 1297ef467e
2 changed files with 26 additions and 18 deletions

View File

@ -4,7 +4,7 @@ import { GuildMember, Message, Role, VoiceState } from "discord.js";
import fetch from "node-fetch"; import fetch from "node-fetch";
import { emouty } from "../utils/emotes"; import { emouty } from "../utils/emotes";
import { Modul, Spinkackar } from "../utils/types"; import { Modul, Spinkackar } from "../utils/types";
import { formatCas, formatter, ping } from "../utils/utils"; import { formatCas, formatter, oddiakritikovat, ping } from "../utils/utils";
let spinkacky: Record<string, Spinkackar>; let spinkacky: Record<string, Spinkackar>;
const budouciSpinky: Record<string, NodeJS.Timeout> = {}; const budouciSpinky: Record<string, NodeJS.Timeout> = {};
@ -42,6 +42,17 @@ const handleSpink = async (act: "spinkacek" | "vstavacek", member: GuildMember)
return ok.startsWith("OK") ? ok : false; return ok.startsWith("OK") ? ok : false;
}; };
const ifUzRemove = (m: Message) => {
const id = m.author.id;
const uzPgn = budouciSpinky[id];
if (uzPgn) {
clearTimeout(uzPgn);
delete budouciSpinky[id];
return true;
}
return false;
};
const exp: Modul = { const exp: Modul = {
more_komandy: { more_komandy: {
@ -51,11 +62,7 @@ const exp: Modul = {
if (mes.author.bot) return `až někdy${emouty.kapp}`; if (mes.author.bot) return `až někdy${emouty.kapp}`;
if (await handleSpink("spinkacek", mes.member!)) { if (await handleSpink("spinkacek", mes.member!)) {
mes.react(emouty.spinkacek); mes.react(emouty.spinkacek);
const uz = budouciSpinky[mes.author.id]; ifUzRemove(mes);
if (uz) {
clearTimeout(uz);
delete budouciSpinky[mes.author.id];
}
} }
else return 'nespis uz?????'; else return 'nespis uz?????';
} }
@ -89,8 +96,13 @@ const exp: Modul = {
const ted = new Date(); const ted = new Date();
const tedT = Number(ted); const tedT = Number(ted);
const spink = new Date(); const spink = new Date();
let random = false;
if (/^\d+$/.test(kdy) || !kdy) if (kdy == "random") {
random = true;
spink.setSeconds(Math.random() * 10740 + 60);
console.log(`random spink pro ${oddiakritikovat(mes.member?.displayName || "neznamejmeno")} byl nastaven na ${formatter(spink)}`);
} else if (/^\d+$/.test(kdy) || !kdy)
spink.setTime(tedT + Number(kdy || 7200) * 1000); spink.setTime(tedT + Number(kdy || 7200) * 1000);
else { else {
const cojavim = /^((?<d>\d+)\. ?((?<mo>\d+)\.)? ?|(?<z>z([ií]|ej)tra) )?(?<h>\d+)(:(?<m>\d+)(:(?<s>\d+))?)? ?(?<p>am|pm)?$/.exec(kdy.toLowerCase()); const cojavim = /^((?<d>\d+)\. ?((?<mo>\d+)\.)? ?|(?<z>z([ií]|ej)tra) )?(?<h>\d+)(:(?<m>\d+)(:(?<s>\d+))?)? ?(?<p>am|pm)?$/.exec(kdy.toLowerCase());
@ -107,14 +119,11 @@ const exp: Modul = {
if (Number(spink) < tedT) return "to uz bylo ty magore"; if (Number(spink) < tedT) return "to uz bylo ty magore";
} }
const uzPgn = budouciSpinky[mes.author.id]; ifUzRemove(mes);
if (uzPgn) {
clearTimeout(uzPgn);
delete budouciSpinky[mes.author.id];
}
budouciSpinky[mes.author.id] = setTimeout(() => handleSpink("spinkacek", mes.member!), Number(spink) - tedT); budouciSpinky[mes.author.id] = setTimeout(() => handleSpink("spinkacek", mes.member!), Number(spink) - tedT);
return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`; if (!random) return `tvuj spinkacek byl naplanovan na ${formatter(spink)}`;
mes.react(emouty.lajk);
} }
}, },
@ -134,10 +143,7 @@ const exp: Modul = {
zruspgn: { zruspgn: {
als: ["zpgn", "cancelpgn", "cpgn", "unpgn", `unp${emouty.gn}`], als: ["zpgn", "cancelpgn", "cpgn", "unpgn", `unp${emouty.gn}`],
run: (mes) => { run: (mes) => {
const jehoSpink = budouciSpinky[mes.author.id]; if (!ifUzRemove(mes)) return `spinkacek ale nemas naplanovanej ty kkte ${mes.author}`;
if (!jehoSpink) return `spinkacek ale nemas naplanovanej ty kkte ${mes.author}`;
clearTimeout(jehoSpink);
delete budouciSpinky[mes.author.id];
return "to bylo teda trapny debile"; return "to bylo teda trapny debile";
} }
} }

View File

@ -7,5 +7,7 @@ export enum emouty {
d3k = "<:D3K:730175107313565717>", d3k = "<:D3K:730175107313565717>",
kapp = "<:kapp:677916836418813953>", kapp = "<:kapp:677916836418813953>",
spinkacek = "<:spinkacek:761652251966046208>", spinkacek = "<:spinkacek:761652251966046208>",
sjeta = "<:sjeta:623216247953424426>" sjeta = "<:sjeta:623216247953424426>",
gn = "<:gn:887124590583746590>",
lajk = "<:lajk:851556768373932123>"
} }