From e67dd8d856d363caf2d8ead1279c4409ce7bd880 Mon Sep 17 00:00:00 2001 From: Histmy Date: Mon, 24 Jan 2022 19:37:52 +0100 Subject: [PATCH] autoautospink --- src/modules/spink.ts | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/modules/spink.ts b/src/modules/spink.ts index fd8fe35..3c5ce00 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -1,6 +1,6 @@ // Modul dedikovaný funkci spinkáček -import { Client, GuildMember, Message, Presence, Role, VoiceState } from "discord.js"; +import { GuildMember, Message, Presence, Role, TextBasedChannel, VoiceState } from "discord.js"; import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Modul, Spinkackar, SRecord } from "../utils/types"; @@ -8,7 +8,7 @@ import { formatCas, formatter, oddiakritikovat, ping } from "../utils/utils"; let spinkacky: SRecord; const budouciSpinky: SRecord = {}; -const autoSpinky: SRecord = {}; +const autoSpinky: SRecord<[boolean, TextBasedChannel]> = {}; const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => { const options = `heslo=${process.env.spinkPass}&akce=${akce}&id=${id}&nick=${encodeURIComponent(nick)}&avatar=${encodeURIComponent(avatar ?? "")}`; @@ -74,7 +74,7 @@ const exp: Modul = { spinkacek: { als: ["spink", "spoink", "spinkake", "spoinkacek", "gn", emouty.spinkacek, emouty.gn], - run: async (mes) => { + run: async mes => { if (mes.author.bot) return `až někdy${emouty.kapp}`; if (await handleSpink("spinkacek", mes.member!)) { mes.react(emouty.spinkacek); @@ -86,7 +86,7 @@ const exp: Modul = { vstavacek: { als: ["vstavcacek", "gm", "unspinkacek"], - run: async (mes) => { + run: async mes => { if (mes.author.bot) return emouty.sjeta; return tovjemamvolepreceroliky(mes.member!); @@ -149,14 +149,20 @@ const exp: Modul = { zruspgn: { als: ["zpgn", "cancelpgn", "cpgn", "unpgn", `unp${emouty.gn}`], - run: (mes) => { + run: mes => { if (!ifUzRemove(mes)) return `spinkacek ale nemas naplanovanej ty kkte ${mes.author}`; return "to bylo teda trapny debile"; } }, - autospink: (mes) => - `autospink je ${autoSpinky[mes.author.id] ? (delete autoSpinky[mes.author.id], "vypnut") : (autoSpinky[mes.author.id] = mes.channelId, "zapnut")}` + autospink: mes => + `autospink je ${autoSpinky[mes.author.id] ? (delete autoSpinky[mes.author.id], "vypnut") : (autoSpinky[mes.author.id] = [true, mes.channel], "zapnut")}`, + + autoautospink: { + als: ["🚗🚗spink"], + run: mes => + `autoautospink je ${autoSpinky[mes.author.id] ? (delete autoSpinky[mes.author.id], "vypnut") : (autoSpinky[mes.author.id] = [false, mes.channel], "zapnut")}` + } }, on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { @@ -218,17 +224,15 @@ const exp: Modul = { if (!bef) return; const befoff = bef.status == "offline"; const aftoff = aft.status == "offline"; - const mamrdovinka = autoSpinky[aft.userId]; - if (mamrdovinka) { - if (!befoff && aftoff) { - handleSpink("spinkacek", aft.member!); - } - if (befoff && !aftoff) { - const client: Client = module.exports.client; - const kanel = client.channels.cache.get(mamrdovinka); - delete autoSpinky[aft.userId]; - if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!)); - } + const prop = autoSpinky[aft.userId]; + if (!prop) return; + if (!befoff && aftoff) { + handleSpink("spinkacek", aft.member!); + } + if (befoff && !aftoff) { + if (prop[0]) delete autoSpinky[aft.userId]; + const kanel = prop[1]; + if (kanel?.isText()) kanel.send(await tovjemamvolepreceroliky(aft.member!)); } } };