From 1cf0946bfd2291bf255a54caf3026a982432894a Mon Sep 17 00:00:00 2001 From: Histmy Date: Fri, 12 Jul 2024 18:09:07 +0200 Subject: [PATCH] added fekal bind commands --- src/app.ts | 31 ++++++++++++++++++++++--------- src/modules/custom.ts | 26 ++++++++++++++++++++++++-- src/utils/types.ts | 1 + 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/app.ts b/src/app.ts index c6a91bc..5138624 100644 --- a/src/app.ts +++ b/src/app.ts @@ -253,11 +253,17 @@ async function runKomand(mesOrInt: Message | CommandInteraction, cmd: Komand, cm return mesOrInt.channel?.send("sorka bracho tuto je koamnd jenom pro curaki co platy"); } + // log(cmd); + + if (cmd.bind) { + return (mesOrInt as Message).reply(`${prefix} ${cmd.run}`); + } + 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 mesOrInt.channel.send(res); return mesOrInt.reply(res); } @@ -291,16 +297,21 @@ client.on("messageCreate", async mes => { return; } - const celArgs = args.join(" "); - const komandBez = oddiakritikovat(komandSDiakritikou).toLowerCase(); - const cmdName = client.aliasy[komandBez] ?? komandBez; + const argString = args.join(" "); + const komandBezDiakritiky = oddiakritikovat(komandSDiakritikou).toLowerCase(); + const cmdName = client.aliasy[komandBezDiakritiky] ?? komandBezDiakritiky; 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 (komand) return void runKomand(mes, komand, cmdName, celArgs); + if (mes.author.id == client.user!.id && mes.reference) { + await mes.channel.messages.fetch(mes.reference.messageId!); + mes.author = (await mes.channel.messages.fetch(mes.reference.messageId!)).author; + } + + if (komand) return void runKomand(mes, komand, cmdName, argString); // neměl jsi na mysli? const slova: string[] = []; @@ -317,18 +328,20 @@ client.on("messageCreate", async mes => { channel: mes.channel, zpravec: { content: "nemnel sy na misli:" }, onCollect: (i, lookupId, radek) => { - if (i.member?.user.id != mes.author.id) return; + if (i.member?.user.id != mes.author.id) + return i.reply({ content: emouty.fu, ephemeral: true }); + const komand = nabidka[lookupId]; const cmdName = client.aliasy[komand] ?? komand; const cmd = client.komandy[cmdName]; radek.components.forEach((btn, i) => btn.setDisabled() && (i == lookupId && btn.setStyle(ButtonStyle.Success))); 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 mes.channel.send("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 mes.channel.send("tuten komand bohuzel v sz nefunkuje"); - runKomand(mes, cmd, cmdName, celArgs); + runKomand(mes, cmd, cmdName, argString); }, konecnaZprava: "pozde" }); diff --git a/src/modules/custom.ts b/src/modules/custom.ts index edada3f..5afaafa 100644 --- a/src/modules/custom.ts +++ b/src/modules/custom.ts @@ -9,7 +9,7 @@ const cesta = `${join(__dirname, "../../res/")}custom`; const helpServer: HelpServer = require("../utils/helpServer"); let zakladniKomandy: SRecord; let zakladniAliasy: SRecord; -let customKomandy: SRecord<{ text: string; owner: string; }>; +let customKomandy: SRecord<{ text: string; owner: string; bind?: true; }>; let customAliasy: SRecord<{ cmd: string; owner: string; }>; function spojit() { @@ -17,7 +17,7 @@ function spojit() { const cKomandyForExport: KomandNaExport[] = []; for (const komand in customKomandy) { - cKomandyAsKomand[komand] = { run: customKomandy[komand].text }; + cKomandyAsKomand[komand] = { run: customKomandy[komand].text, bind: customKomandy[komand].bind }; cKomandyForExport.push({ name: komand, custom: true }); } @@ -115,6 +115,28 @@ const exp: Modul = { } }, + naucsebind: { + arg: " ", + als: ["naucseb"], + run: (mes, arg) => { + const args = arg.split(/\s/).filter(v => v != "").map(e => oddiakritikovat(e).toLowerCase()); + + if (args.length == 0) return "a co se mam jako naucit"; + if (args.length == 1) return "na jakej koamnd to ma bit????"; + + if (zakladniKomandy[args[0]] || customKomandy[args[0]]) return "tuto uz je ale komand"; + if (zakladniAliasy[args[0]] || customAliasy[args[0]]) return "tuto uz je ale alijas"; + + if (!(zakladniKomandy[args[1]] || zakladniAliasy[args[1]] || customKomandy[args[1]] || customAliasy[args[1]])) + return `nejze "${args[1]}" neni realnej ani vlastni komand ani alias`; + + customKomandy[args[0]] = { text: args.splice(1).join(" "), owner: mes.author.id, bind: true }; + + save(); + return "jo"; + } + }, + zapomen: { arg: "název komandu nebo aliasu", run: (mes, arg) => { diff --git a/src/utils/types.ts b/src/utils/types.ts index e3be018..083210e 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -52,6 +52,7 @@ export type Komand = { cd?: number; DMUnsafe?: true; premium?: true; + bind?: true; }; export interface Spinkackar {