pomoc3 will now actually show custom commands

This commit is contained in:
Histmy 2022-02-20 14:12:14 +01:00
parent 5906bfe895
commit a42e12015d
3 changed files with 21 additions and 14 deletions

View File

@ -1,10 +1,11 @@
import { Client, Collection, Intents, MessageActionRow, MessageButton } from "discord.js";
import { readdirSync } from "fs";
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce, CustomKomandy } from "./utils/types";
import { adminLog, formatCas, loadEnv, oddiakritikovat } from "./utils/utils.js";
import { adminLog, formatCas, loadEnv, oddiakritikovat, sortArr } from "./utils/utils.js";
import levenshtein from "js-levenshtein";
import { emouty } from "./utils/emotes";
const helpServer = require("./utils/helpServer");
const custom: CustomKomandy = require("./utils/customCommands");
loadEnv();
@ -21,7 +22,10 @@ const kuldan_log: SRecord<SRecord<number>> = {};
const komandyNaPoslani: KomandNaExport[] = [];
let customKomandy: SRecord<Komand> = custom.cKomandy;
custom.emitter.on("komandi", komandi => customKomandy = komandi);
custom.emitter.on("komandi", (komandi, naPoslani) => {
customKomandy = komandi;
helpServer.cmds = sortArr([...komandyNaPoslani, ...naPoslani]);
});
const runEvent = (name: string, args: any[]) => {
for (const listener of superEventy[name] || []) {
@ -101,9 +105,7 @@ readdirSync(modulFolder).forEach(soubor => {
custom.realKomandy = komandy;
komandy["naucse"] = { run: custom.naucse };
komandy["zapomen"] = { run: custom.zapomen };
komandyNaPoslani.push(...custom.naSend);
require("./utils/helpServer").cmds = komandyNaPoslani;
helpServer.cmds = sortArr([...komandyNaPoslani, ...custom.naSend]);
const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
if (!kuldan_log[komand]) kuldan_log[komand] = {};

View File

@ -5,19 +5,25 @@ import { join } from "path";
const cesta = join(__dirname, "../../res/komandi.json");
const komandi: SRecord<{ text: string; owner: string; }> = JSON.parse(readFileSync(cesta).toString());
export let cKomandy = save(true);
const baseNaSend: KomandNaExport[] = [
{ name: "naucse", arg: "<jméno nového komandu> <obsah nového komandu>" },
{ name: "zapomen", arg: "název komandu" }
];
export let [cKomandy, naSend] = save(true);
export const emitter = new EventEmitter();
function save(): void;
function save(nesend: true): SRecord<Komand>;
function save(nesend: true): [SRecord<Komand>, KomandNaExport[]];
function save(nesend?: true) {
const cKomandi: SRecord<Komand> = {};
const naSend = baseNaSend;
Object.keys(komandi).forEach(c => {
cKomandi[c] = { run: komandi[c].text };
naSend.push({ name: c });
});
if (nesend) return cKomandi;
if (nesend) return [cKomandi, naSend];
cKomandy = cKomandi;
emitter.emit("komandi", cKomandy);
emitter.emit("komandi", cKomandy, naSend);
writeFileSync(cesta, JSON.stringify(komandi));
}
@ -41,8 +47,3 @@ export const zapomen: RunFunkce = (mes, arg) => {
save();
return "jo";
};
export const naSend: KomandNaExport[] = [
{ name: "naucse", arg: "<jméno nového komandu> <obsah nového komandu>" },
{ name: "zapomen", arg: "název komandu" }
];

View File

@ -190,3 +190,7 @@ export function adminLog(client: Client, text: string) {
client.users.cache.get(process.env.adminID)?.createDM().then(ch => ch.send(text));
}
}
export function sortArr(arr: any[]) {
return arr.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
}