ABSOLUTNÍ TYPOVÁNÍ PARAMETRŮ EVENTŮŮ!!!!!

btw, codefactor, doufám že už budeš konečně držet hubu zmrde
This commit is contained in:
Histmy 2023-08-26 21:46:59 +02:00
parent 08fde766c4
commit 70f0f370c5
Signed by untrusted user who does not match committer: Histmy
GPG Key ID: AC2E43C463D8F329
10 changed files with 46 additions and 45 deletions

View File

@ -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<ListenerFunkce[]> = {};
const superEventy: SRecord<SuperListenerFunkce[]> = {};
const eventy: SRecord<ListenerFunkce<any>[]> = {};
const superEventy: SRecord<SuperListenerFunkce<any>[]> = {};
const kuldan_log: SRecord<SRecord<number>> = {};
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 = /^(?<s>super_)?on_(?<h>.+)/.exec(name);
for (const klic in modul) {
const prefix = /^(?<s>super_)?on_(?<h>.+)/.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<keyof Modul, "client" | "more_komandy">]!;
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);
}

View File

@ -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<boolean> | 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 = {

View File

@ -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";

View File

@ -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 }]);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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) {

View File

@ -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)

View File

@ -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;

View File

@ -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<string | MessagePayload | MessageCreateOptions | void>;
@ -20,26 +20,23 @@ export type KomandRaw = BaseKomandProps &
};
export type ListenerFunkce = (...args: any[]) => void;
export type ListenerFunkce<T extends keyof ClientEvents> = (...args: ClientEvents[T]) => void;
export type SuperListenerFunkce = (...args: any[]) => boolean;
export type SuperListenerFunkce<T extends keyof ClientEvents> = (...args: ClientEvents[T]) => boolean;
interface SuperObject {
interface SuperObject<T extends keyof ClientEvents> {
pos: number;
fun: SuperListenerFunkce;
fun: SuperListenerFunkce<T>;
}
type Eventy = keyof ClientEvents | "userPresenceUpdate";
export type EventSOn = `on_${Eventy}` | `super_on_${Eventy}`;
export type SRecord<T> = Record<string, T>;
export type Modul = {
more_komandy?: SRecord<RunFunkce | KomandRaw | string>;
client?: Client<boolean>;
} & { [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> }
& { [key in keyof ClientEvents as `super_on_${key}`]?: SuperObject<key> | SuperListenerFunkce<key>; };
export type Komand = {
run: string | RunFunkce;