From 17114163358cb8aa076f9adb1bf0aac8f161e545 Mon Sep 17 00:00:00 2001 From: Histmy Date: Thu, 18 Nov 2021 18:59:39 +0100 Subject: [PATCH] pomoc3 added http server for anouncing all commands, their aliasses and sometimes argument meaning beginning of 3001.32 --- package-lock.json | 4 ++-- package.json | 2 +- src/app.ts | 18 +++++++++++++++++- src/modules/komArgs.ts | 22 +++++++++++----------- src/modules/komComplex.ts | 20 +++++++++++--------- src/modules/komRNG.ts | 34 ++++++++++++++++++++++------------ src/modules/spink.ts | 1 + src/modules/vojs.ts | 22 +++++++++++++--------- src/modules/zbytek.ts | 9 ++++++--- src/utils/helpServer.ts | 9 +++++++++ src/utils/types.ts | 17 +++++++++++++---- 11 files changed, 106 insertions(+), 52 deletions(-) create mode 100644 src/utils/helpServer.ts diff --git a/package-lock.json b/package-lock.json index f375d29..de1c2fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.31.0", + "version": "3001.32.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.31.0", + "version": "3001.32.0", "license": "ISC", "dependencies": { "@discordjs/opus": "github:discordjs/opus", diff --git a/package.json b/package.json index 2cd0594..3e27748 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.31.0", + "version": "3001.32.0", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/app.ts b/src/app.ts index f171a2f..739ae5c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,6 +1,6 @@ import { Client, Intents } from "discord.js"; import { readdirSync } from "fs"; -import { EventSOn, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce } from "./utils/types"; +import { EventSOn, KoamndNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce } from "./utils/types"; import { formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js"; loadEnv(); @@ -27,6 +27,16 @@ const runEvent = (name: string, args: any[]) => { }); }; +const getTenParam = (fn: RunFunkce): string | undefined => fn.toString() + .match(/(?:function\s.*?)?\(([^)]*)\)/)![1] + .split(",")[1] + ?.trim(); + +const fnToArg = (fn: RunFunkce | string) => { + if (typeof fn != "function") return; + return getTenParam(fn); +}; + readdirSync(modulFolder).forEach(soubor => { if (!soubor.endsWith(".js")) return; const modul: Modul = require(`${modulFolder}${soubor}`); @@ -52,12 +62,18 @@ readdirSync(modulFolder).forEach(soubor => { const n = modul[name]!; Object.keys(n).forEach(cmdName => { const value = n[cmdName]; + const toCoExportuju: KoamndNaExport = { name: cmdName }; + let hide = false; if (typeof value !== "object") { komandy[cmdName] = { run: value }; + toCoExportuju.arg = fnToArg(value); } else { komandy[cmdName] = { run: value.run, cd: value.cd }; + Object.assign(toCoExportuju, { als: value.als, arg: value.arg ?? fnToArg(value.run) }); + hide = !!value.hidden; value.als?.forEach(al => aliasy[al] = cmdName); } + if (!hide) komandyNaPoslani.push(toCoExportuju); }); } }); diff --git a/src/modules/komArgs.ts b/src/modules/komArgs.ts index f6d165e..ab13805 100644 --- a/src/modules/komArgs.ts +++ b/src/modules/komArgs.ts @@ -5,33 +5,33 @@ import { Modul } from "../utils/types"; const exp: Modul = { more_komandy: { - rekni: (mes, arg) => { + rekni: (mes, co) => { if (mes.author.bot) return "ne"; - const corict = arg || `co mam jako rict ${mes.author}`; + const corict = co || `co mam jako rict ${mes.author}`; mes.delete(); return corict; }, - clap: (mes, arg) => { + clap: (mes, text) => { mes.delete(); - return `${arg} ${emouty.clap}`; + return `${text} ${emouty.clap}`; }, - clap2: (mes, arg) => { + clap2: (mes, text) => { mes.delete(); - return `${emouty.clap2} ${arg}`; + return `${emouty.clap2} ${text}`; }, - voliz: (mes, arg) => { + voliz: (mes, co) => { mes.delete(); - return `${emouty.lickL}${arg}${emouty.lickR}`; + return `${emouty.lickL}${co}${emouty.lickR}`; }, - pozdrav: (_, arg) => `zdravim ${arg}`, + pozdrav: (_, koho) => `zdravim ${koho}`, - zhejti: (_, arg) => `${arg} je pycovina zasrana vimrdana`, + zhejti: (_, koho) => `${koho} je pycovina zasrana vimrdana`, - uraz: (_, arg) => `${arg} , u suck` + uraz: (_, koho) => `${koho} , u suck` } }; diff --git a/src/modules/komComplex.ts b/src/modules/komComplex.ts index 8fc0cea..1154ea1 100644 --- a/src/modules/komComplex.ts +++ b/src/modules/komComplex.ts @@ -39,24 +39,24 @@ const exp: Modul = { run: (mes) => changeStatus(mes, "invisible") }, - hraj: (mes, arg) => changeActivity(mes, "PLAYING", arg), - sleduj: (mes, arg) => changeActivity(mes, "WATCHING", arg), - poslouchej: (mes, arg) => changeActivity(mes, "LISTENING", arg), - soutez: (mes, arg) => changeActivity(mes, "COMPETING", arg), + hraj: (mes, co) => changeActivity(mes, "PLAYING", co), + sleduj: (mes, co) => changeActivity(mes, "WATCHING", co), + poslouchej: (mes, co) => changeActivity(mes, "LISTENING", co), + soutez: (mes, vcem) => changeActivity(mes, "COMPETING", vcem), nedelej: (mes) => changeActivity(mes), fight: { als: ["figh", "fajt"], - run: (mes, arg) => { - if (!ping.test(arg)) return "tak si kokot ti kokote"; + run: (mes, skym) => { + if (!ping.test(skym)) return "tak si kokot ti kokote"; - const vyherce = Math.random() < 0.5 ? mes.author : arg; + const vyherce = Math.random() < 0.5 ? mes.author : skym; return `tento figh vyhrál: ${vyherce}!`; } }, - status: (mes, arg) => { - if (!ping.test(arg)) return "tak si kokot ti kokote"; + status: (mes, koho) => { + if (!ping.test(koho)) return "tak si kokot ti kokote"; const uzivatel = mes.mentions.members!.first()!; const embed = { @@ -82,6 +82,7 @@ const exp: Modul = { zareaguj: { als: ["react"], + arg: "emout/emouty", run: async (mes, arg) => { const emouty = arg.match(//g); if (!emouty) return "retard"; @@ -118,6 +119,7 @@ const exp: Modul = { pockej: { als: ["cekej"], + arg: "počet sekund", run: (mes, arg) => { let cas: number; if (arg.length) { diff --git a/src/modules/komRNG.ts b/src/modules/komRNG.ts index f53f513..51d0b55 100644 --- a/src/modules/komRNG.ts +++ b/src/modules/komRNG.ts @@ -22,35 +22,42 @@ const exp: Modul = { je: { cd: 1800, + arg: "kdo/co", run: () => rand(2) ? "jo je" : "ne neni" }, - ma: () => rand(2) ? "jo ma" : "ne nema", + ma: { + arg: "kdo/co", + run: () => rand(2) ? "jo ma" : "ne nema" + }, - nazor: (_, arg) => rand(2) ? `mam rad ${arg}` : `${arg} je picovina`, + nazor: { + arg: "koho/co", + run: (_, arg) => rand(2) ? `mam rad ${arg}` : `${arg} je picovina` + }, si: { als: ["jsi"], - run: (_, arg) => { - const corict = arg.replace(/\?/g, ""); + run: (_, co) => { + const corict = co.replace(/\?/g, ""); return rand(2) ? `jo sem ${corict}` : `ne nejsem ${corict}`; } }, - mas: (_, arg) => { - const corict = arg.replace(/\?/g, ""); + mas: (_, co) => { + const corict = co.replace(/\?/g, ""); return rand(2) ? `jo mam ${corict}` : `ne nemam ${corict}`; }, jakmoc: { cd: 1800, - run: (_, arg) => `${arg} na ${rand(101)}%` + run: (_, co) => `${co} na ${rand(101)}%` }, jakmoc0: { cd: 1800, - run: (_, arg) => `${arg} na ${rand(1001)}‰` + run: (_, co) => `${co} na ${rand(1001)}‰` }, uz: { @@ -58,10 +65,13 @@ const exp: Modul = { run: () => choose(uz) }, - vyber: (_, arg) => { - if (!arg.length) return "co vole"; - const moznosti = arg.split(arg.indexOf("|") > -1 ? "|" : ",").filter(m => m.length); - return choose(moznosti) || "kokot"; + vyber: { + arg: "co (odděleno čárkami nebo \"|\")", + run: (_, arg) => { + if (!arg.length) return "co vole"; + const moznosti = arg.split(arg.indexOf("|") > -1 ? "|" : ",").filter(m => m.length); + return choose(moznosti) || "kokot"; + } } } }; diff --git a/src/modules/spink.ts b/src/modules/spink.ts index 1fb4701..a25a201 100644 --- a/src/modules/spink.ts +++ b/src/modules/spink.ts @@ -129,6 +129,7 @@ const exp: Modul = { ps: { als: ["poslednispink"], + arg: "kdo (nepovinné)", run: (mes, arg) => { const f = arg != ""; if (!ping.test(arg) && f) return "sikkt"; diff --git a/src/modules/vojs.ts b/src/modules/vojs.ts index 0b003b9..6e94ac0 100644 --- a/src/modules/vojs.ts +++ b/src/modules/vojs.ts @@ -64,6 +64,7 @@ const exp: Modul = { vojs: { cd: 1800, + arg: "potichu (nepovinné)", run: (mes, arg) => { const channel = mes.member?.voice.channel; if (!channel) return `di si tam sam ne ty gadzo ${mes.author}`; @@ -100,11 +101,11 @@ const exp: Modul = { vytah: { als: ["vitah"], - run: (mes, arg) => { + run: (mes, parto) => { if (!mes.member?.voice.channel) return `nejsi ve vojsu ty gadzo ${mes.author}`; - if (!arg) return `napis do jakiho patra ${mes.author}`; + if (!parto) return `napis do jakiho patra ${mes.author}`; - vytahnout(mes.member, Number(arg) || 0); + vytahnout(mes.member, Number(parto) || 0); } }, @@ -162,13 +163,16 @@ const exp: Modul = { } }, - outro: async (mes) => { - const channel = mes.member?.voice.channel; - if (!channel) return "co to znamena ti gadzovko"; + outro: { + hidden: true, + run: async (mes) => { + const channel = mes.member?.voice.channel; + if (!channel) return "co to znamena ti gadzovko"; - const { conn, prev } = await joinVoice(channel); - await play(conn, { name: "zvuky/pocasi/outro.mp3", volume: 30 }); - handlePrevVoice(mes.guild!, prev); + const { conn, prev } = await joinVoice(channel); + await play(conn, { name: "zvuky/pocasi/outro.mp3", volume: 30 }); + handlePrevVoice(mes.guild!, prev); + } } } }; diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 4b6d11f..3531986 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -12,9 +12,12 @@ let spim = false; const exp: Modul = { more_komandy: { - debug_log: (_, arg) => { - console.log("log: ", arg); - return "je to v konzoli"; + debug_log: { + hidden: true, + run: (_, arg) => { + console.log("log: ", arg); + return "je to v konzoli"; + } }, update: async (mes) => { diff --git a/src/utils/helpServer.ts b/src/utils/helpServer.ts new file mode 100644 index 0000000..279c60f --- /dev/null +++ b/src/utils/helpServer.ts @@ -0,0 +1,9 @@ +import { createServer } from "http"; +import { KoamndNaExport } from "./types"; + +createServer((_, res) => { + const komandi: KoamndNaExport[] = module.exports.cmds; + const odpoved = JSON.stringify({ komandy: komandi }); + res.setHeader("Content-Type", "application/json"); + res.end(odpoved); +}).listen(5712); diff --git a/src/utils/types.ts b/src/utils/types.ts index 732c79a..2e38a17 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -2,13 +2,18 @@ import { Client, ClientEvents, ClientPresenceStatusData, Message, MessageOptions type OutputRunFunkce = string | MessageOptions | void; -type RunFunkce = (message: Message, argumenty: string) => OutputRunFunkce | Promise; +export type RunFunkce = (message: Message, argumenty: string) => OutputRunFunkce | Promise; -interface KomandRaw { +interface BaseKomandProps { als?: string[]; - cd?: number; + arg?: string; +} + +type KomandRaw = { run: string | RunFunkce; -}; + cd?: number; + hidden?: true; +} & BaseKomandProps; export type ListenerFunkce = (...args: any[]) => void; @@ -62,3 +67,7 @@ export interface MuzikaFace { name: string; volume: number; } + +export type KoamndNaExport = { + name: string; +} & BaseKomandProps;