diff --git a/src/modules/spink.ts b/src/modules/spink.ts index f586191..cc86ab1 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -4,9 +4,9 @@ import { Guild, GuildMember, Message, VoiceState } from "discord.js"; import fetch from "node-fetch"; import { emouty } from "../utils/emotes"; import { Spinkackar } from "../utils/types"; -import { formatCas } from "../utils/utils"; +import { formatCas, formatter } from "../utils/utils"; -const spinkacky: string[] = []; +let spinkacky: Record; const budouciSpinky: Record = {}; const contactSpinkServer = async (akce: string, id: string, nick: string = "", avatar: string | null = "") => { @@ -17,16 +17,17 @@ const contactSpinkServer = async (akce: string, id: string, nick: string = "", a const syncSpink = () => { fetch("https://spinkacek.ga/api/spinkacky") - .then(r => r.json() as Promise>) + .then(r => r.json() as Promise<{ spinkacky: Record; }>) .then(d => { const data = d.spinkacky; const keys = Object.keys(data); const values = Object.values(data); - spinkacky.splice(0); + spinkacky = {}; for (let i = 0; i < keys.length; i++) { - if (!values[i].spinkacek || keys[i][0] === "i") continue; - spinkacky.push(keys[i].slice(8)); + const k = keys[i]; + if (k[0] != "d") continue; + spinkacky[k.slice(8)] = { spinkacek: values[i].spinkacek, timeup: values[i].timeup * 1000 }; } }); }; @@ -99,7 +100,6 @@ module.exports = { const ted = new Date(); const tedT = Number(ted); const spink = new Date(); - const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" }); if (/^\d+$/.test(kdy) || !kdy) spink.setTime(tedT + Number(kdy || 7200) * 1000); @@ -126,12 +126,19 @@ module.exports = { budouciSpinky[mes.author.id] = setTimeout(() => contactSpinkServer("spinkacek", mes.author.id, mes.author.username, mes.author.avatarURL()), Number(spink) - tedT); return `tvuj spinkacek byl naplanovan na ${formatter.format(spink)}`; + }, + + ps: { + als: ["poslednispink"], + run: (mes: Message) => { + return `naposled si spal ${formatter.format(new Date(spinkacky[mes.author.id].timeup))}`; + } } }, on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { if (!aft.channel || bef.channel) return; - if (spinkacky.includes(aft.id)) aft.disconnect("spinkacek") + if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek") .catch(err => console.log("spinkacek odpojit se nepovedlo nebo co:", err)); }, @@ -151,7 +158,7 @@ module.exports = { } } } - } else if (spinkacky.includes(mes.author.id) && cmd != "vstavacek") { + } else if (spinkacky[mes.author.id]?.spinkacek && cmd != "vstavacek") { mes.delete(); (async () => { const chanel = mes.author.dmChannel ?? await mes.author.createDM(); diff --git a/src/utils/types.ts b/src/utils/types.ts index 3bb7938..e3b36f2 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -31,6 +31,7 @@ export interface Komand { export interface Spinkackar { spinkacek: boolean; + timeup: number; } export interface FakePresence { @@ -47,13 +48,13 @@ export interface UserChange { export type StatusyINaFounu = "Online" | "OnlinePhone" | "Idle" | "IdlePhone" | "DND" | "DNDPhone" | "Offline"; export interface ZmenovejObjekt { - id: string, - nick?: string, - pfp?: string, + id: string; + nick?: string; + pfp?: string; status?: string; } export interface MuzikaFace { - name: string, + name: string; volume: number; } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 5d16e8a..554a99b 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -163,3 +163,5 @@ export function loadEnv() { if (!existsSync("config.json")) throw new Error("config.json neexistuje"); process.env = { ...process.env, ...require("../../config.json") }; } + +export const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: "short", hour: "numeric", minute: "numeric", second: "numeric" });