initial commit
This commit is contained in:
parent
da91699e58
commit
5e22ef0677
28
src/app.ts
28
src/app.ts
@ -1,7 +1,7 @@
|
||||
import { ChannelType, Client, CommandInteraction, GatewayIntentBits, InteractionReplyOptions, Message, Partials } from "discord.js";
|
||||
import { readdirSync } from "fs";
|
||||
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, send } from "./utils/utils.js";
|
||||
import levenshtein from "js-levenshtein";
|
||||
import { emouty } from "./utils/emotes";
|
||||
import { lidiCoMajDenimPremium, setClient } from "./utils/denim-Spravce";
|
||||
@ -224,7 +224,7 @@ function handle(e: unknown, mesOrInt: Message | CommandInteraction) {
|
||||
const admin = process.env.adminID;
|
||||
|
||||
const txt = `pri spousteni thohoto komandu nastala chyba ${admin ? `<@${admin}> uz?` : ""}`;
|
||||
if (mesOrInt instanceof Message) return void mesOrInt.channel.send(txt);
|
||||
if (mesOrInt instanceof Message) return void send(mesOrInt, txt);
|
||||
mesOrInt.reply(txt);
|
||||
}
|
||||
|
||||
@ -236,23 +236,23 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm
|
||||
if (jeMes && cmd.slashRun) {
|
||||
const nazev = `${prefix}${cmdName}`;
|
||||
const id = client.slashCommandy[nazev];
|
||||
return void mesOrInt.channel.send(`tuto ejenom sleh komand </${nazev}:${id}>`);
|
||||
return void send(mesOrInt, `tuto ejenom sleh komand </${nazev}:${id}>`);
|
||||
}
|
||||
|
||||
if (cmd.cd && jeMes) {
|
||||
const zbyva = Math.round(maKuldan(mesOrInt.author.id, cmdName, cmd.cd));
|
||||
if (zbyva) return mesOrInt.channel.send(`si kkt vole maz kuldan jeste ${formatCas(zbyva)}`);
|
||||
if (zbyva) return send(mesOrInt, `si kkt vole maz kuldan jeste ${formatCas(zbyva)}`);
|
||||
}
|
||||
|
||||
if (cmd.premium && !lidiCoMajDenimPremium.includes((mesOrInt instanceof Message) ? mesOrInt.author.id : mesOrInt.member?.user.id || "")) {
|
||||
return mesOrInt.channel?.send("sorka bracho tuto je koamnd jenom pro curaki co platy");
|
||||
if (cmd.premium && !lidiCoMajDenimPremium.includes(jeMes ? mesOrInt.author.id : mesOrInt.member?.user.id || "")) {
|
||||
return send(mesOrInt as Message, "sorka bracho tuto je koamnd jenom pro curaki co platy");
|
||||
}
|
||||
|
||||
const akce = cmd.run ?? cmd.slashRun!;
|
||||
|
||||
if (typeof akce == "string") {
|
||||
const res = renderMessage(akce, arg?.split(" ") || []);
|
||||
if (mesOrInt instanceof Message) return mesOrInt.channel.send(res);
|
||||
if (jeMes) return send(mesOrInt, res);
|
||||
return mesOrInt.reply(res);
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm
|
||||
const result = await akce(mesOrInt as never, arg || "");
|
||||
if (!result) return;
|
||||
|
||||
if (jeMes) return mesOrInt.channel.send(result)
|
||||
if (jeMes) return send(mesOrInt, result)
|
||||
.catch(e => handle(e, mesOrInt));
|
||||
// další feklo
|
||||
mesOrInt.reply(result as InteractionReplyOptions);
|
||||
@ -277,12 +277,12 @@ client.on("messageCreate", async mes => {
|
||||
|
||||
const prefixDiff = levenshtein(oddiakritikovat(mesPrefix.toLowerCase()), prefix);
|
||||
if (prefixDiff > 0) {
|
||||
if (!await runEvent("messageCreate", [mes]) && prefixDiff <= 1 && mes.author.id != client.user!.id) mes.channel.send(`${prefix}*`);
|
||||
if (!await runEvent("messageCreate", [mes]) && prefixDiff <= 1 && mes.author.id != client.user!.id) send(mes, `${prefix}*`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!komandSDiakritikou) {
|
||||
if (!await runEvent("messageCreate", [mes])) mes.channel.send("coe voe");
|
||||
if (!await runEvent("messageCreate", [mes])) send(mes, "coe voe");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ client.on("messageCreate", async mes => {
|
||||
if (await runEvent("messageCreate", [mes, cmdName])) return;
|
||||
|
||||
const komand = client.komandy[cmdName];
|
||||
if (mes.channel.type == ChannelType.DM && komand?.DMUnsafe) return void mes.channel.send("tuten komand bohuzel v sz nefunkuje");
|
||||
if (mes.channel.type == ChannelType.DM && komand?.DMUnsafe) return void send(mes, "tuten komand bohuzel v sz nefunkuje");
|
||||
|
||||
if (komand) return void runKomand(mes, komand, cmdName, celArgs);
|
||||
|
||||
@ -303,7 +303,7 @@ client.on("messageCreate", async mes => {
|
||||
const distance = levenshtein(cmd, cmdName);
|
||||
if (distance <= Math.ceil(cmdName.length * 0.3)) slova.push(cmd);
|
||||
});
|
||||
if (!slova.length) return void mes.channel.send("co to znamena ti gadzovko");
|
||||
if (!slova.length) return void send(mes, "co to znamena ti gadzovko");
|
||||
|
||||
const nabidka = slova.sort().slice(0, 5);
|
||||
|
||||
@ -319,9 +319,9 @@ client.on("messageCreate", async mes => {
|
||||
radek.components.forEach(btn => btn.setDisabled());
|
||||
i.update({ content: `ok vole ${emouty.d3k}`, components: [radek] });
|
||||
|
||||
if (!cmd) return void mes.channel.send("bohuzel negdo sy ze mi dela prel");
|
||||
if (!cmd) return void send(mes, "bohuzel negdo sy ze mi dela prel");
|
||||
|
||||
if (mes.channel.type == ChannelType.DM && cmd?.DMUnsafe) return void mes.channel.send("tuten komand bohuzel v sz nefunkuje");
|
||||
if (mes.channel.type == ChannelType.DM && cmd?.DMUnsafe) return void send(mes, "tuten komand bohuzel v sz nefunkuje");
|
||||
|
||||
runKomand(mes, cmd, cmdName, celArgs);
|
||||
},
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { CClient, HelpServer, Komand, KomandNaExport, Modul, SRecord } from "../utils/types";
|
||||
import { join } from "path";
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs";
|
||||
import { oddiakritikovat, strankovani } from "../utils/utils";
|
||||
import { oddiakritikovat, send, strankovani } from "../utils/utils";
|
||||
import { APIEmbed, Message } from "discord.js";
|
||||
|
||||
let client: CClient;
|
||||
@ -63,13 +63,13 @@ function zmrdovoAliasy(zacatek: string, owner: string, mes: Message) {
|
||||
let text = "";
|
||||
arr.forEach(element => {
|
||||
if (text.length + element.length > 2000) {
|
||||
mes.channel.send({ content: text, allowedMentions: { users: [] } });
|
||||
send(mes, { content: text, allowedMentions: { users: [] } });
|
||||
text = "";
|
||||
}
|
||||
text += `${element}\n`;
|
||||
});
|
||||
|
||||
mes.channel.send({ content: text, allowedMentions: { users: [] } });
|
||||
send(mes, { content: text, allowedMentions: { users: [] } });
|
||||
}
|
||||
|
||||
const exp: Modul = {
|
||||
|
||||
@ -5,7 +5,7 @@ import { join } from "path";
|
||||
import { Priority, novejPlay } from "../utils/voice";
|
||||
import { lidiCoMajDenimPremium } from "../utils/denim-Spravce";
|
||||
import { exec } from "child_process";
|
||||
import { log } from "../utils/utils";
|
||||
import { log, send } from "../utils/utils";
|
||||
|
||||
const kmenovaCesta = join(__dirname, `../../zvuky/priVstupu`);
|
||||
const formaty = ["mp3", "wav", "ogg"];
|
||||
@ -42,14 +42,14 @@ const exp: Modul = {
|
||||
if (error) {
|
||||
log("chyba pri ffprobe", error);
|
||||
|
||||
mes.channel.send("bohuzel chiba");
|
||||
send(mes, "bohuzel chiba");
|
||||
vymaz(docasnaCesta);
|
||||
return;
|
||||
}
|
||||
|
||||
// Maximum
|
||||
if (Number(stdout) > 13) {
|
||||
mes.channel.send("13 se kund maks");
|
||||
send(mes, "13 se kund maks");
|
||||
vymaz(docasnaCesta);
|
||||
return;
|
||||
}
|
||||
@ -62,7 +62,7 @@ const exp: Modul = {
|
||||
|
||||
renameSync(docasnaCesta, `${zaklad}.${typ}`);
|
||||
|
||||
mes.channel.send("ej tot am");
|
||||
send(mes, "ej tot am");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
import { ChannelType, Message, MessageReaction } from "discord.js";
|
||||
import { emouty } from "../utils/emotes";
|
||||
import { Modul, SRecord } from "../utils/types";
|
||||
import { formatter, ping, sendDM } from "../utils/utils";
|
||||
import { formatter, ping, send, sendDM } from "../utils/utils";
|
||||
|
||||
const exp: Modul = {
|
||||
more_komandy: {
|
||||
@ -67,7 +67,7 @@ const exp: Modul = {
|
||||
argument.splice(0, 1);
|
||||
if (argument.length) setTimeout(() => randomshit(mes, argument), 1000);
|
||||
};
|
||||
mes.channel.send(":stop_button:").then(mes => randomshit(mes, [":five:", ":four:", ":three:", ":two:", ":one:", ":ok:"]));
|
||||
send(mes, ":stop_button:").then(mes => randomshit(mes, [":five:", ":four:", ":three:", ":two:", ":one:", ":ok:"]));
|
||||
},
|
||||
|
||||
pocasi: () => {
|
||||
|
||||
@ -5,7 +5,7 @@ import { Client } from "discord.js";
|
||||
import { search, spotify, stream, validate, video_basic_info } from "play-dl";
|
||||
import { emouty } from "../utils/emotes";
|
||||
import { Modul } from "../utils/types";
|
||||
import { adminLog, log } from "../utils/utils";
|
||||
import { adminLog, log, send } from "../utils/utils";
|
||||
import { getConn, Hratelny, novejJoin, novejPlay, Priority, stopPlayer } from "../utils/voice";
|
||||
import { array, record, safeParse, string } from "valibot";
|
||||
|
||||
@ -72,16 +72,16 @@ const exp: Modul = {
|
||||
ajtem.name = soubor.name;
|
||||
ajtem.url = soubor.url;
|
||||
ajtem.special = true;
|
||||
mes.channel.send(`zahraju \`${soubor.name}\``);
|
||||
send(mes, `zahraju \`${soubor.name}\``);
|
||||
} else if (txt == "") return "co mam zahrat??";
|
||||
else if (!druh) {
|
||||
ajtem.name = `nejaka picovina ot ${mes.author}`;
|
||||
ajtem.url = txt;
|
||||
ajtem.special = true;
|
||||
mes.channel.send(`zkusim to zahrat`);
|
||||
send(mes, `zkusim to zahrat`);
|
||||
}
|
||||
else if (druh == "search" || druh == "sp_track") {
|
||||
const msg = mes.channel.send("hledam");
|
||||
const msg = send(mes, "hledam");
|
||||
const hledacek = druh == "search" ? txt : (await spotify(txt)).name;
|
||||
const hledani = await search(hledacek, { limit: 1 });
|
||||
if (!hledani[0]) return "nic sem nenašel";
|
||||
@ -100,7 +100,7 @@ const exp: Modul = {
|
||||
const client: Client = module.exports.client;
|
||||
adminLog(client, "video nemá název");
|
||||
}
|
||||
mes.channel.send(`zahraju \`${ajtem.name}\``);
|
||||
send(mes, `zahraju \`${ajtem.name}\``);
|
||||
} else return "tuto neumim zahrat";
|
||||
|
||||
if (!guildy.has(guildId)) {
|
||||
|
||||
@ -4,6 +4,7 @@ import { APIEmbed, Message } from "discord.js";
|
||||
import { Modul, SRecord } from "../utils/types";
|
||||
import { fokinLookupTable, klikance, pocetKeStrane } from "../utils/sachyEtc";
|
||||
import { emiter } from "../utils/sachyServer";
|
||||
import { send } from "../utils/utils";
|
||||
|
||||
const hry: SRecord<Hra> = {};
|
||||
const hraci: SRecord<string> = {};
|
||||
@ -476,7 +477,7 @@ const exp: Modul = {
|
||||
if (hraci[player]) return "zakaz symultanki";
|
||||
}
|
||||
|
||||
const message = await mes.channel.send("hraj zopiciva");
|
||||
const message = await send(mes, "hraj zopiciva");
|
||||
|
||||
const hra = createGame(mes.channelId, mes.author.id, druhej, message);
|
||||
hraci[mes.author.id] = mes.channelId;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
import { ChannelType, Role, TextBasedChannel, User } from "discord.js";
|
||||
import { emouty } from "../utils/emotes";
|
||||
import { Modul, SRecord } from "../utils/types";
|
||||
import { formatCas, formatter, log, oddiakritikovat, ping, safeQuery, sendDM } from "../utils/utils";
|
||||
import { formatCas, formatter, log, oddiakritikovat, ping, safeQuery, send, sendDM } from "../utils/utils";
|
||||
|
||||
const enum Spinky {
|
||||
vstavacek,
|
||||
@ -264,7 +264,7 @@ const exp: Modul = {
|
||||
const entry = await getLastEntry(mes.author.id);
|
||||
if ((entry && !entry.vstavacek) && cmd != "vstavacek") {
|
||||
if (mes.channel.type == ChannelType.DM) {
|
||||
mes.channel.send("drz hubu");
|
||||
send(mes, "drz hubu");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
50
src/modules/ultimatniLoger.ts
Normal file
50
src/modules/ultimatniLoger.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { Modul } from "../utils/types";
|
||||
import { send, stackTrace, wait } from "../utils/utils";
|
||||
|
||||
const maxRecurseLength = 10;
|
||||
|
||||
function najit(id: string, lvl = 0) {
|
||||
if (!stackTrace.has(id) || lvl >= maxRecurseLength) return lvl;
|
||||
|
||||
return najit(stackTrace.get(id)!, lvl + 1);
|
||||
}
|
||||
|
||||
function clear(id: string) {
|
||||
if (!stackTrace.has(id)) return;
|
||||
|
||||
const kam = stackTrace.get(id)!;
|
||||
stackTrace.delete(id);
|
||||
|
||||
return clear(kam);
|
||||
}
|
||||
|
||||
// Garbage collector
|
||||
const garbageCollectDelay = 60_000;
|
||||
setInterval(() => {
|
||||
for (const klic of stackTrace.keys()) {
|
||||
if (Number(BigInt.asUintN(64, BigInt(klic)) >> 22n) + 1420070400000 < Date.now() - garbageCollectDelay)
|
||||
stackTrace.delete(klic);
|
||||
}
|
||||
}, garbageCollectDelay);
|
||||
|
||||
const exp: Modul = {
|
||||
super_on_messageCreate: {
|
||||
pos: 2,
|
||||
fun: async mes => {
|
||||
if (mes.author.id != mes.client.user.id) return false;
|
||||
|
||||
await wait(mes.content);
|
||||
console.log(mes.content, najit(mes.id), mes.id, stackTrace);
|
||||
|
||||
if (najit(mes.id) == maxRecurseLength) {
|
||||
clear(mes.id);
|
||||
send(mes, "nemam rat sarandu");
|
||||
return true;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = exp;
|
||||
@ -53,12 +53,13 @@ const exp: Modul = {
|
||||
if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`;
|
||||
|
||||
const nahlas = !arg.startsWith("potichu");
|
||||
if (nahlas) mes.channel.send("<@&591306633196339261> vojs");
|
||||
|
||||
novejJoin(mes.guild!, channel.id)
|
||||
.then(prev => {
|
||||
if (prev != true && nahlas) novejPlay(mes.guildId!, "zvuky/nazdar.ogg", Priority.Etc);
|
||||
});
|
||||
|
||||
if (nahlas) return "<@&591306633196339261> vojs";
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { getVoiceConnections } from "@discordjs/voice";
|
||||
import { emouty } from "../utils/emotes";
|
||||
import { Modul } from "../utils/types";
|
||||
import { prefix } from "../utils/utils";
|
||||
import { prefix, send } from "../utils/utils";
|
||||
import { novejLeave } from "../utils/voice";
|
||||
|
||||
let spim = false;
|
||||
@ -15,9 +15,9 @@ const exp: Modul = {
|
||||
if (spim) {
|
||||
spim = false;
|
||||
mes.client.user?.setStatus("online");
|
||||
mes.channel.send("dobré ráno magoří");
|
||||
send(mes, "dobré ráno magoří");
|
||||
}
|
||||
else mes.channel.send("tak jsi kokot?");
|
||||
else send(mes, "tak jsi kokot?");
|
||||
} else if (!spim) {
|
||||
if (cont == `${prefix} vypni se`) {
|
||||
mes.react(emouty.purfieRIP);
|
||||
|
||||
@ -4,7 +4,7 @@ import { getVoiceConnections } from "@discordjs/voice";
|
||||
import { Client, TextChannel, } from "discord.js";
|
||||
import { createServer } from "http";
|
||||
import { Modul } from "../utils/types";
|
||||
import { adminLog, formatCas, log, nabidni, sendDM } from "../utils/utils";
|
||||
import { adminLog, formatCas, log, nabidni, send, sendDM } from "../utils/utils";
|
||||
import { emouty } from "../utils/emotes";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
@ -110,7 +110,7 @@ const exp: Modul = {
|
||||
|
||||
(async () => {
|
||||
if (mes.author.id == client.user?.id)
|
||||
return mes.content != "uz nechci" ? mes.channel.send("uz nechci") : "";
|
||||
return mes.content != "uz nechci" ? send(mes, "uz nechci") : "";
|
||||
const adminRole = mes.member?.roles.cache.find(r => r.name == "admin");
|
||||
if (adminRole) {
|
||||
await mes.member?.roles.remove(adminRole).catch(e => log(mes.author.displayName, "nejde odebrat admin", e));
|
||||
@ -120,7 +120,7 @@ const exp: Modul = {
|
||||
if (adminRole) setTimeout(() => {
|
||||
mes.member?.roles.add(adminRole);
|
||||
}, 60_000);
|
||||
mes.channel.send(emouty.fu);
|
||||
send(mes, emouty.fu);
|
||||
})();
|
||||
|
||||
return true;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { VoiceConnection } from "@discordjs/voice";
|
||||
import { Awaitable, BaseMessageOptions, Client, ClientEvents, ClientPresenceStatusData, CommandInteraction, Message, MessageCreateOptions, MessagePayload, Presence, User } from "discord.js";
|
||||
import { Awaitable, BaseMessageOptions, Client, ClientEvents, ClientPresenceStatusData, CommandInteraction, Message, MessageCreateOptions, Presence, User } from "discord.js";
|
||||
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 | MessageCreateOptions | void>;
|
||||
export type InteractionRunFunkce = (interaction: CommandInteraction) => Awaitable<string | BaseMessageOptions | void>;
|
||||
|
||||
export type BaseKomandProps = {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { APIEmbed, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, ChannelType, Client, Collection, ComponentType, MessageCreateOptions, TextBasedChannel, User } from "discord.js";
|
||||
import { APIEmbed, ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, ChannelType, Client, Collection, ComponentType, Message, MessageCreateOptions, TextBasedChannel, User } from "discord.js";
|
||||
import { existsSync } from "fs";
|
||||
import { MysqlError, createPool } from "mysql";
|
||||
|
||||
@ -197,3 +197,25 @@ export const safeQuery = <T>(query: string, parametry?: string[]) => new Promise
|
||||
res({ data: odpoved, err });
|
||||
});
|
||||
});
|
||||
|
||||
export const stackTrace = new Map<string, string>();
|
||||
const nezarazeny = new Map<string, Promise<void>>();
|
||||
|
||||
export async function wait(kontent: string) {
|
||||
if (nezarazeny.has(kontent))
|
||||
await nezarazeny.get(kontent);
|
||||
}
|
||||
|
||||
export async function send(mes: Message, co: string | MessageCreateOptions) {
|
||||
let res = () => { };
|
||||
const klic = (typeof co == "string" ? co : co.content ?? "").trim();
|
||||
nezarazeny.set(klic, new Promise<void>(r => res = r));
|
||||
|
||||
const nova = await mes.channel.send(co);
|
||||
|
||||
stackTrace.set(nova.id, mes.id);
|
||||
nezarazeny.delete(klic);
|
||||
res();
|
||||
|
||||
return nova;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user