diff --git a/src/app.ts b/src/app.ts index 7cba00f..da2b294 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ -import { ChannelType, Client, CommandInteraction, GatewayIntentBits, Message, Partials } from "discord.js"; +import { ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js"; import { readdirSync } from "fs"; -import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CClient, HelpServer, KomandRaw } from "./utils/types"; +import { CUser, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CClient, HelpServer, KomandRaw } from "./utils/types"; import { adminLog, formatCas, oddiakritikovat, log, rand, prefix, nabidni } from "./utils/utils.js"; import levenshtein from "js-levenshtein"; import { emouty } from "./utils/emotes"; @@ -12,8 +12,8 @@ const client = new Client({ }) as CClient; const DJ_PREFIX = "dj:"; const modulFolder = `${__dirname}/modules/`; -const eventy: SRecord = {}; -const superEventy: SRecord = {}; +const eventy: SRecord[]> = {}; +const superEventy: SRecord[]> = {}; const kuldan_log: SRecord> = {}; const komandyNaPoslani: KomandNaExport[] = []; const helpServer: HelpServer = require("./utils/helpServer"); @@ -59,8 +59,8 @@ readdirSync(modulFolder).forEach(soubor => { log(`Loaded: ${modulFolder}${soubor}`); modul.client = client; - Object.keys(modul).forEach(name => { - const prefix = /^(?super_)?on_(?.+)/.exec(name); + for (const klic in modul) { + const prefix = /^(?super_)?on_(?.+)/.exec(klic); if (prefix) { const groups = prefix.groups!; const ev = groups.s ? superEventy : eventy; @@ -69,15 +69,16 @@ readdirSync(modulFolder).forEach(soubor => { if (!["messageCreate", "userPresenceUpdate"].includes(groups.h)) client.on(groups.h, (...args) => void runEvent(groups.h, args)); } - const n = modul[name as EventSOn]!; + // Bohužel typescript je tupá píča a musíme mu vysvětlit, že to vlastně jde + const n = modul[klic as Exclude]!; if (typeof n == "object") { const prev = ev[groups.h][n.pos]; ev[groups.h][n.pos] = n.fun; if (prev) ev[groups.h].push(prev); } else ev[groups.h].push(n); - } else if (name === "more_komandy") { - const n = modul[name]!; + } else if (klic == "more_komandy") { + const n = modul[klic]!; Object.keys(n).forEach(cmdName => { const value = n[cmdName]; const toCoExportuju: KomandNaExport = { name: cmdName }; @@ -94,7 +95,7 @@ readdirSync(modulFolder).forEach(soubor => { if (!hide) komandyNaPoslani.push(toCoExportuju); }); } - }); + }; }); helpServer.komandy = komandyNaPoslani; @@ -241,14 +242,14 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm } try { - // @ts-ignore todle prostě musí fungovat a jestli náhodou ne, stejně je tu catch - const result = await akce(mesOrInt, arg); + // Je to absolutní fekálie, ale alespoň to je kompilovatelný narozdíl od předchozí verze (commit 08fde76 a předchozí) + const result = await akce(mesOrInt as never, arg || ""); if (!result) return; - if (mesOrInt instanceof Message) return void mesOrInt.channel.send(result) + if (jeMes) return void mesOrInt.channel.send(result) .catch(e => handle(e, mesOrInt)); - // @ts-ignore a zas ksd - mesOrInt.reply(result); + // další feklo + mesOrInt.reply(result as InteractionReplyOptions); } catch (e) { handle(e, mesOrInt); } diff --git a/src/modules/anketa.ts b/src/modules/anketa.ts index 5395692..a70ece8 100644 --- a/src/modules/anketa.ts +++ b/src/modules/anketa.ts @@ -1,6 +1,6 @@ // Modul na komand "anketa" -import { ActionRowBuilder, APIEmbed, APIEmbedField, ButtonBuilder, ButtonStyle, CommandInteraction, ComponentType, InteractionResponse, Message, MessageComponentInteraction, MessageCreateOptions } from "discord.js"; +import { ActionRowBuilder, APIEmbed, APIEmbedField, ButtonBuilder, ButtonStyle, CommandInteraction, ComponentType, InteractionResponse, Message, MessageComponentInteraction, MessageEditOptions } from "discord.js"; import { Modul, SRecord } from "../utils/types"; import { formatter } from "../utils/utils"; @@ -54,11 +54,10 @@ async function zbytek(settings: { time: number; immediateShow: boolean; listName if (settings.immediateShow) embed.fields = fildy; let zprava: Message | InteractionResponse; - let edit: (c: MessageCreateOptions) => void; + let edit: (c: MessageEditOptions) => void; if (jeMes) { zprava = await mesOrInt.channel.send({ embeds: [embed], components: radky }); - // @ts-ignore seru na to, logicky to musí fungovat a to že to typscript nechápe není můj problém edit = content => { zprava.edit(content); }; } else { zprava = await mesOrInt.reply({ embeds: [embed], components: radky }); @@ -119,7 +118,7 @@ const exp: Modul = { return await zbytek(settings, moznosti, mes); }, - slashRun: async (int) => { + slashRun: async int => { const opt = int.options; const settings = { diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 9860988..8590197 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -187,13 +187,13 @@ const exp: Modul = { } }, - on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { + on_voiceStateUpdate: (bef, aft) => { if (!aft.channel || bef.channel) return; if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek") .catch(err => log("spinkacek odpojit se nepovedlo nebo co:", err)); }, - super_on_messageCreate: (mes: Message, cmd?: string) => { + super_on_messageCreate: (mes, cmd?: string) => { if (mes.author.id === '831318260493844494') { syncSpink(); const uzivatel = mes.content.match(/(?<=discord_)\d+/)?.[0]; @@ -249,7 +249,7 @@ const exp: Modul = { return false; }, - on_userPresenceUpdate: async (bef: Presence | null, aft: Presence) => { + on_userPresenceUpdate: async (bef, aft) => { if (!bef) return; const befoff = bef.status == "offline"; const aftoff = aft.status == "offline"; diff --git a/src/modules/status.ts b/src/modules/status.ts index 9816044..c0120df 100644 --- a/src/modules/status.ts +++ b/src/modules/status.ts @@ -70,7 +70,7 @@ function statusOnFoun(bef: FakePresence | null, aft: FakePresence) { const exp: Modul = { // Změna rolí podle statusu a odeslání statusu - on_presenceUpdate: (bef: Presence, aft: Presence) => { + on_presenceUpdate: (bef, aft) => { if (process.env.ignorePresence) return; const [statusPred, statusPo] = statusOnFoun(bef as FakePresence, aft as FakePresence); @@ -115,7 +115,7 @@ const exp: Modul = { }, // Odeslání statusu při změně jména nebo profilovky - on_userUpdate: (bef: User, aft: User) => { + on_userUpdate: (bef, aft) => { if (!process.env.ignorePresence && bef.id != aft.client.user?.id) prepSend([{ ch: "user", user: aft }]); } diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 698b915..e2f8978 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -153,7 +153,7 @@ const exp: Modul = { }, // Neodposlouchávej - on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => { + on_voiceStateUpdate: (bef, aft) => { const conn = getVoiceConnection(aft.guild.id); if (!aft.channel || !conn || aft.member?.user.id == aft.client.user?.id) return; diff --git a/src/modules/vyhledavac.ts b/src/modules/vyhledavac.ts index bc82455..5f6f816 100644 --- a/src/modules/vyhledavac.ts +++ b/src/modules/vyhledavac.ts @@ -1,3 +1,5 @@ +/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/ + import { APIEmbed, CommandInteractionOption, Message, TextBasedChannel } from "discord.js"; import { CClient, Modul } from "../utils/types"; import { createPool } from "mysql"; @@ -163,7 +165,7 @@ const exp: Modul = { }); }, - on_messageCreate: (mes: Message) => { + on_messageCreate: mes => { if (mes.channelId == "555779161067749448") zpracovatZpravu(mes); } diff --git a/src/modules/zapniVypniSe.ts b/src/modules/zapniVypniSe.ts index 776e5a1..c9053c1 100644 --- a/src/modules/zapniVypniSe.ts +++ b/src/modules/zapniVypniSe.ts @@ -10,7 +10,7 @@ let spim = false; const exp: Modul = { super_on_messageCreate: { pos: 0, - fun: (mes: Message) => { + fun: mes => { const cont = mes.content.toLowerCase(); if (cont == `${prefix} zapni se`) { if (spim) { diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 58c0db0..f0e8a1e 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -91,7 +91,7 @@ const exp: Modul = { super_on_messageCreate: { pos: 1, - fun: (mes: Message) => { + fun: mes => { const ted = Date.now(); const autor = mes.author.id; @@ -172,13 +172,13 @@ const exp: Modul = { }, 60_000); }, - on_userUpdate: (bef: User, aft: User) => { + on_userUpdate: (bef, aft) => { if (bef.avatar == aft.avatar) return; sendDM(aft, "cus bracho vydim ze sis zmenim profilofku na dalsi mrdku estli chces abi se ukazovala na na v3ech sr4kach kterz sou na dedfis.cy tak se tam prosymte prihlas haby se mohla zmnenit syk"); }, - on_userPresenceUpdate: (bef: Presence | null, aft: Presence) => { + on_userPresenceUpdate: (bef, aft) => { if (aft.user?.id != "355053867265818635" || bef?.status == "online" || aft.status != "online") return; (client.channels.cache.get("555779161067749448") as TextChannel) diff --git a/src/utils/sachyServer.ts b/src/utils/sachyServer.ts index 03474d8..e08483a 100644 --- a/src/utils/sachyServer.ts +++ b/src/utils/sachyServer.ts @@ -1,3 +1,5 @@ +/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/ + import { createServer, IncomingMessage, ServerResponse } from "http"; import { SRecord } from "./types"; import { join } from "path"; @@ -25,12 +27,12 @@ function parseCookies(cookies?: string) { if (!cookies) return list; cookies.split(`;`).forEach(function (cookie) { - let [name, ...rest] = cookie.split(`=`); - name = name?.trim(); - if (!name) return; + const [name, ...rest] = cookie.split(`=`); + const nazev = name?.trim(); + if (!nazev) return; const value = rest.join(`=`).trim(); if (!value) return; - list[name] = decodeURIComponent(value); + list[nazev] = decodeURIComponent(value); }); return list; diff --git a/src/utils/types.ts b/src/utils/types.ts index a411036..40739f7 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -1,5 +1,5 @@ import { VoiceConnection } from "@discordjs/voice"; -import { Awaitable, BaseMessageOptions, Client, ClientEvents, ClientPresenceStatusData, CommandInteraction, Message, MessageCreateOptions, MessagePayload, User } from "discord.js"; +import { Awaitable, BaseMessageOptions, Client, ClientEvents, ClientPresenceStatusData, CommandInteraction, Message, MessageCreateOptions, MessagePayload, Presence, User } from "discord.js"; import { EventEmitter } from "events"; export type RunFunkce = (message: Message, argumenty: string) => Awaitable; @@ -20,26 +20,23 @@ export type KomandRaw = BaseKomandProps & }; -export type ListenerFunkce = (...args: any[]) => void; +export type ListenerFunkce = (...args: ClientEvents[T]) => void; -export type SuperListenerFunkce = (...args: any[]) => boolean; +export type SuperListenerFunkce = (...args: ClientEvents[T]) => boolean; -interface SuperObject { +interface SuperObject { pos: number; - fun: SuperListenerFunkce; + fun: SuperListenerFunkce; } -type Eventy = keyof ClientEvents | "userPresenceUpdate"; - -export type EventSOn = `on_${Eventy}` | `super_on_${Eventy}`; - export type SRecord = Record; export type Modul = { more_komandy?: SRecord; client?: Client; -} & { [key in `on_${Eventy}`]?: ListenerFunkce } - & { [key in `super_on_${Eventy}`]?: SuperObject | SuperListenerFunkce; }; + on_userPresenceUpdate?: (bef: Presence | null, aft: Presence) => void; +} & { [key in keyof ClientEvents as `on_${key}`]?: ListenerFunkce } + & { [key in keyof ClientEvents as `super_on_${key}`]?: SuperObject | SuperListenerFunkce; }; export type Komand = { run: string | RunFunkce;