ABSOLUTNÍ TYPOVÁNÍ PARAMETRŮ EVENTŮŮ!!!!!
btw, codefactor, doufám že už budeš konečně držet hubu zmrde
This commit is contained in:
parent
08fde766c4
commit
70f0f370c5
31
src/app.ts
31
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 { 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 { adminLog, formatCas, oddiakritikovat, log, rand, prefix, nabidni } from "./utils/utils.js";
|
||||||
import levenshtein from "js-levenshtein";
|
import levenshtein from "js-levenshtein";
|
||||||
import { emouty } from "./utils/emotes";
|
import { emouty } from "./utils/emotes";
|
||||||
@ -12,8 +12,8 @@ const client = new Client({
|
|||||||
}) as CClient;
|
}) as CClient;
|
||||||
const DJ_PREFIX = "dj:";
|
const DJ_PREFIX = "dj:";
|
||||||
const modulFolder = `${__dirname}/modules/`;
|
const modulFolder = `${__dirname}/modules/`;
|
||||||
const eventy: SRecord<ListenerFunkce[]> = {};
|
const eventy: SRecord<ListenerFunkce<any>[]> = {};
|
||||||
const superEventy: SRecord<SuperListenerFunkce[]> = {};
|
const superEventy: SRecord<SuperListenerFunkce<any>[]> = {};
|
||||||
const kuldan_log: SRecord<SRecord<number>> = {};
|
const kuldan_log: SRecord<SRecord<number>> = {};
|
||||||
const komandyNaPoslani: KomandNaExport[] = [];
|
const komandyNaPoslani: KomandNaExport[] = [];
|
||||||
const helpServer: HelpServer = require("./utils/helpServer");
|
const helpServer: HelpServer = require("./utils/helpServer");
|
||||||
@ -59,8 +59,8 @@ readdirSync(modulFolder).forEach(soubor => {
|
|||||||
log(`Loaded: ${modulFolder}${soubor}`);
|
log(`Loaded: ${modulFolder}${soubor}`);
|
||||||
|
|
||||||
modul.client = client;
|
modul.client = client;
|
||||||
Object.keys(modul).forEach(name => {
|
for (const klic in modul) {
|
||||||
const prefix = /^(?<s>super_)?on_(?<h>.+)/.exec(name);
|
const prefix = /^(?<s>super_)?on_(?<h>.+)/.exec(klic);
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
const groups = prefix.groups!;
|
const groups = prefix.groups!;
|
||||||
const ev = groups.s ? superEventy : eventy;
|
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));
|
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") {
|
if (typeof n == "object") {
|
||||||
const prev = ev[groups.h][n.pos];
|
const prev = ev[groups.h][n.pos];
|
||||||
ev[groups.h][n.pos] = n.fun;
|
ev[groups.h][n.pos] = n.fun;
|
||||||
if (prev) ev[groups.h].push(prev);
|
if (prev) ev[groups.h].push(prev);
|
||||||
}
|
}
|
||||||
else ev[groups.h].push(n);
|
else ev[groups.h].push(n);
|
||||||
} else if (name === "more_komandy") {
|
} else if (klic == "more_komandy") {
|
||||||
const n = modul[name]!;
|
const n = modul[klic]!;
|
||||||
Object.keys(n).forEach(cmdName => {
|
Object.keys(n).forEach(cmdName => {
|
||||||
const value = n[cmdName];
|
const value = n[cmdName];
|
||||||
const toCoExportuju: KomandNaExport = { name: cmdName };
|
const toCoExportuju: KomandNaExport = { name: cmdName };
|
||||||
@ -94,7 +95,7 @@ readdirSync(modulFolder).forEach(soubor => {
|
|||||||
if (!hide) komandyNaPoslani.push(toCoExportuju);
|
if (!hide) komandyNaPoslani.push(toCoExportuju);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
helpServer.komandy = komandyNaPoslani;
|
helpServer.komandy = komandyNaPoslani;
|
||||||
@ -241,14 +242,14 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// @ts-ignore todle prostě musí fungovat a jestli náhodou ne, stejně je tu catch
|
// 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, arg);
|
const result = await akce(mesOrInt as never, arg || "");
|
||||||
if (!result) return;
|
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));
|
.catch(e => handle(e, mesOrInt));
|
||||||
// @ts-ignore a zas ksd
|
// další feklo
|
||||||
mesOrInt.reply(result);
|
mesOrInt.reply(result as InteractionReplyOptions);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handle(e, mesOrInt);
|
handle(e, mesOrInt);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Modul na komand "anketa"
|
// 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 { Modul, SRecord } from "../utils/types";
|
||||||
import { formatter } from "../utils/utils";
|
import { formatter } from "../utils/utils";
|
||||||
|
|
||||||
@ -54,11 +54,10 @@ async function zbytek(settings: { time: number; immediateShow: boolean; listName
|
|||||||
if (settings.immediateShow) embed.fields = fildy;
|
if (settings.immediateShow) embed.fields = fildy;
|
||||||
|
|
||||||
let zprava: Message<boolean> | InteractionResponse;
|
let zprava: Message<boolean> | InteractionResponse;
|
||||||
let edit: (c: MessageCreateOptions) => void;
|
let edit: (c: MessageEditOptions) => void;
|
||||||
|
|
||||||
if (jeMes) {
|
if (jeMes) {
|
||||||
zprava = await mesOrInt.channel.send({ embeds: [embed], components: radky });
|
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); };
|
edit = content => { zprava.edit(content); };
|
||||||
} else {
|
} else {
|
||||||
zprava = await mesOrInt.reply({ embeds: [embed], components: radky });
|
zprava = await mesOrInt.reply({ embeds: [embed], components: radky });
|
||||||
@ -119,7 +118,7 @@ const exp: Modul = {
|
|||||||
return await zbytek(settings, moznosti, mes);
|
return await zbytek(settings, moznosti, mes);
|
||||||
},
|
},
|
||||||
|
|
||||||
slashRun: async (int) => {
|
slashRun: async int => {
|
||||||
|
|
||||||
const opt = int.options;
|
const opt = int.options;
|
||||||
const settings = {
|
const settings = {
|
||||||
|
|||||||
@ -187,13 +187,13 @@ const exp: Modul = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => {
|
on_voiceStateUpdate: (bef, aft) => {
|
||||||
if (!aft.channel || bef.channel) return;
|
if (!aft.channel || bef.channel) return;
|
||||||
if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek")
|
if (spinkacky[aft.id]?.spinkacek) aft.disconnect("spinkacek")
|
||||||
.catch(err => log("spinkacek odpojit se nepovedlo nebo co:", err));
|
.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') {
|
if (mes.author.id === '831318260493844494') {
|
||||||
syncSpink();
|
syncSpink();
|
||||||
const uzivatel = mes.content.match(/(?<=discord_)\d+/)?.[0];
|
const uzivatel = mes.content.match(/(?<=discord_)\d+/)?.[0];
|
||||||
@ -249,7 +249,7 @@ const exp: Modul = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
on_userPresenceUpdate: async (bef: Presence | null, aft: Presence) => {
|
on_userPresenceUpdate: async (bef, aft) => {
|
||||||
if (!bef) return;
|
if (!bef) return;
|
||||||
const befoff = bef.status == "offline";
|
const befoff = bef.status == "offline";
|
||||||
const aftoff = aft.status == "offline";
|
const aftoff = aft.status == "offline";
|
||||||
|
|||||||
@ -70,7 +70,7 @@ function statusOnFoun(bef: FakePresence | null, aft: FakePresence) {
|
|||||||
const exp: Modul = {
|
const exp: Modul = {
|
||||||
|
|
||||||
// Změna rolí podle statusu a odeslání statusu
|
// Změna rolí podle statusu a odeslání statusu
|
||||||
on_presenceUpdate: (bef: Presence, aft: Presence) => {
|
on_presenceUpdate: (bef, aft) => {
|
||||||
if (process.env.ignorePresence) return;
|
if (process.env.ignorePresence) return;
|
||||||
|
|
||||||
const [statusPred, statusPo] = statusOnFoun(bef as FakePresence, aft as FakePresence);
|
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
|
// 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)
|
if (!process.env.ignorePresence && bef.id != aft.client.user?.id)
|
||||||
prepSend([{ ch: "user", user: aft }]);
|
prepSend([{ ch: "user", user: aft }]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,7 +153,7 @@ const exp: Modul = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Neodposlouchávej
|
// Neodposlouchávej
|
||||||
on_voiceStateUpdate: (bef: VoiceState, aft: VoiceState) => {
|
on_voiceStateUpdate: (bef, aft) => {
|
||||||
const conn = getVoiceConnection(aft.guild.id);
|
const conn = getVoiceConnection(aft.guild.id);
|
||||||
if (!aft.channel || !conn || aft.member?.user.id == aft.client.user?.id) return;
|
if (!aft.channel || !conn || aft.member?.user.id == aft.client.user?.id) return;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||||
|
|
||||||
import { APIEmbed, CommandInteractionOption, Message, TextBasedChannel } from "discord.js";
|
import { APIEmbed, CommandInteractionOption, Message, TextBasedChannel } from "discord.js";
|
||||||
import { CClient, Modul } from "../utils/types";
|
import { CClient, Modul } from "../utils/types";
|
||||||
import { createPool } from "mysql";
|
import { createPool } from "mysql";
|
||||||
@ -163,7 +165,7 @@ const exp: Modul = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
on_messageCreate: (mes: Message) => {
|
on_messageCreate: mes => {
|
||||||
if (mes.channelId == "555779161067749448")
|
if (mes.channelId == "555779161067749448")
|
||||||
zpracovatZpravu(mes);
|
zpracovatZpravu(mes);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ let spim = false;
|
|||||||
const exp: Modul = {
|
const exp: Modul = {
|
||||||
super_on_messageCreate: {
|
super_on_messageCreate: {
|
||||||
pos: 0,
|
pos: 0,
|
||||||
fun: (mes: Message) => {
|
fun: mes => {
|
||||||
const cont = mes.content.toLowerCase();
|
const cont = mes.content.toLowerCase();
|
||||||
if (cont == `${prefix} zapni se`) {
|
if (cont == `${prefix} zapni se`) {
|
||||||
if (spim) {
|
if (spim) {
|
||||||
|
|||||||
@ -91,7 +91,7 @@ const exp: Modul = {
|
|||||||
|
|
||||||
super_on_messageCreate: {
|
super_on_messageCreate: {
|
||||||
pos: 1,
|
pos: 1,
|
||||||
fun: (mes: Message) => {
|
fun: mes => {
|
||||||
const ted = Date.now();
|
const ted = Date.now();
|
||||||
const autor = mes.author.id;
|
const autor = mes.author.id;
|
||||||
|
|
||||||
@ -172,13 +172,13 @@ const exp: Modul = {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
},
|
},
|
||||||
|
|
||||||
on_userUpdate: (bef: User, aft: User) => {
|
on_userUpdate: (bef, aft) => {
|
||||||
if (bef.avatar == aft.avatar) return;
|
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");
|
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;
|
if (aft.user?.id != "355053867265818635" || bef?.status == "online" || aft.status != "online") return;
|
||||||
|
|
||||||
(client.channels.cache.get("555779161067749448") as TextChannel)
|
(client.channels.cache.get("555779161067749448") as TextChannel)
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||||
|
|
||||||
import { createServer, IncomingMessage, ServerResponse } from "http";
|
import { createServer, IncomingMessage, ServerResponse } from "http";
|
||||||
import { SRecord } from "./types";
|
import { SRecord } from "./types";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
@ -25,12 +27,12 @@ function parseCookies(cookies?: string) {
|
|||||||
if (!cookies) return list;
|
if (!cookies) return list;
|
||||||
|
|
||||||
cookies.split(`;`).forEach(function (cookie) {
|
cookies.split(`;`).forEach(function (cookie) {
|
||||||
let [name, ...rest] = cookie.split(`=`);
|
const [name, ...rest] = cookie.split(`=`);
|
||||||
name = name?.trim();
|
const nazev = name?.trim();
|
||||||
if (!name) return;
|
if (!nazev) return;
|
||||||
const value = rest.join(`=`).trim();
|
const value = rest.join(`=`).trim();
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
list[name] = decodeURIComponent(value);
|
list[nazev] = decodeURIComponent(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { VoiceConnection } from "@discordjs/voice";
|
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";
|
import { EventEmitter } from "events";
|
||||||
|
|
||||||
export type RunFunkce = (message: Message, argumenty: string) => Awaitable<string | MessagePayload | MessageCreateOptions | void>;
|
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;
|
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 SRecord<T> = Record<string, T>;
|
||||||
|
|
||||||
export type Modul = {
|
export type Modul = {
|
||||||
more_komandy?: SRecord<RunFunkce | KomandRaw | string>;
|
more_komandy?: SRecord<RunFunkce | KomandRaw | string>;
|
||||||
client?: Client<boolean>;
|
client?: Client<boolean>;
|
||||||
} & { [key in `on_${Eventy}`]?: ListenerFunkce }
|
on_userPresenceUpdate?: (bef: Presence | null, aft: Presence) => void;
|
||||||
& { [key in `super_on_${Eventy}`]?: SuperObject | SuperListenerFunkce; };
|
} & { [key in keyof ClientEvents as `on_${key}`]?: ListenerFunkce<key> }
|
||||||
|
& { [key in keyof ClientEvents as `super_on_${key}`]?: SuperObject<key> | SuperListenerFunkce<key>; };
|
||||||
|
|
||||||
export type Komand = {
|
export type Komand = {
|
||||||
run: string | RunFunkce;
|
run: string | RunFunkce;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user