diff --git a/src/modules/spink.ts b/src/modules/spink.ts index d0fb4c1..3d92cd9 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -4,7 +4,7 @@ import { GuildMember, Message, Role, VoiceState } from "discord.js"; import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Modul, Spinkackar } from "../utils/types"; -import { formatCas, formatter, ping } from "../utils/utils"; +import { formatCas, formatter, oddiakritikovat, ping } from "../utils/utils"; let spinkacky: Record; const budouciSpinky: Record = {}; @@ -42,6 +42,17 @@ const handleSpink = async (act: "spinkacek" | "vstavacek", member: GuildMember) 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 = { more_komandy: { @@ -51,11 +62,7 @@ const exp: Modul = { if (mes.author.bot) return `až někdy${emouty.kapp}`; if (await handleSpink("spinkacek", mes.member!)) { mes.react(emouty.spinkacek); - const uz = budouciSpinky[mes.author.id]; - if (uz) { - clearTimeout(uz); - delete budouciSpinky[mes.author.id]; - } + ifUzRemove(mes); } else return 'nespis uz?????'; } @@ -89,8 +96,13 @@ const exp: Modul = { const ted = new Date(); const tedT = Number(ted); 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); else { const cojavim = /^((?\d+)\. ?((?\d+)\.)? ?|(?z([ií]|ej)tra) )?(?\d+)(:(?\d+)(:(?\d+))?)? ?(?

am|pm)?$/.exec(kdy.toLowerCase()); @@ -107,14 +119,11 @@ const exp: Modul = { if (Number(spink) < tedT) return "to uz bylo ty magore"; } - const uzPgn = budouciSpinky[mes.author.id]; - if (uzPgn) { - clearTimeout(uzPgn); - delete budouciSpinky[mes.author.id]; - } + ifUzRemove(mes); 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: { als: ["zpgn", "cancelpgn", "cpgn", "unpgn", `unp${emouty.gn}`], run: (mes) => { - const jehoSpink = budouciSpinky[mes.author.id]; - if (!jehoSpink) return `spinkacek ale nemas naplanovanej ty kkte ${mes.author}`; - clearTimeout(jehoSpink); - delete budouciSpinky[mes.author.id]; + if (!ifUzRemove(mes)) return `spinkacek ale nemas naplanovanej ty kkte ${mes.author}`; return "to bylo teda trapny debile"; } } diff --git a/src/utils/emotes.ts b/src/utils/emotes.ts index c0b04b9..f3e3e52 100644 --- a/src/utils/emotes.ts +++ b/src/utils/emotes.ts @@ -7,5 +7,7 @@ export enum emouty { d3k = "<:D3K:730175107313565717>", kapp = "<:kapp:677916836418813953>", spinkacek = "<:spinkacek:761652251966046208>", - sjeta = "<:sjeta:623216247953424426>" + sjeta = "<:sjeta:623216247953424426>", + gn = "<:gn:887124590583746590>", + lajk = "<:lajk:851556768373932123>" }