pomoc3 will now actually show custom commands
This commit is contained in:
parent
5906bfe895
commit
a42e12015d
12
src/app.ts
12
src/app.ts
@ -1,10 +1,11 @@
|
|||||||
import { Client, Collection, Intents, MessageActionRow, MessageButton } from "discord.js";
|
import { Client, Collection, Intents, MessageActionRow, MessageButton } from "discord.js";
|
||||||
import { readdirSync } from "fs";
|
import { readdirSync } from "fs";
|
||||||
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, RunFunkce, SRecord, SuperListenerFunkce, CustomKomandy } from "./utils/types";
|
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 levenshtein from "js-levenshtein";
|
||||||
import { emouty } from "./utils/emotes";
|
import { emouty } from "./utils/emotes";
|
||||||
|
|
||||||
|
const helpServer = require("./utils/helpServer");
|
||||||
const custom: CustomKomandy = require("./utils/customCommands");
|
const custom: CustomKomandy = require("./utils/customCommands");
|
||||||
|
|
||||||
loadEnv();
|
loadEnv();
|
||||||
@ -21,7 +22,10 @@ const kuldan_log: SRecord<SRecord<number>> = {};
|
|||||||
const komandyNaPoslani: KomandNaExport[] = [];
|
const komandyNaPoslani: KomandNaExport[] = [];
|
||||||
let customKomandy: SRecord<Komand> = custom.cKomandy;
|
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[]) => {
|
const runEvent = (name: string, args: any[]) => {
|
||||||
for (const listener of superEventy[name] || []) {
|
for (const listener of superEventy[name] || []) {
|
||||||
@ -101,9 +105,7 @@ readdirSync(modulFolder).forEach(soubor => {
|
|||||||
custom.realKomandy = komandy;
|
custom.realKomandy = komandy;
|
||||||
komandy["naucse"] = { run: custom.naucse };
|
komandy["naucse"] = { run: custom.naucse };
|
||||||
komandy["zapomen"] = { run: custom.zapomen };
|
komandy["zapomen"] = { run: custom.zapomen };
|
||||||
komandyNaPoslani.push(...custom.naSend);
|
helpServer.cmds = sortArr([...komandyNaPoslani, ...custom.naSend]);
|
||||||
|
|
||||||
require("./utils/helpServer").cmds = komandyNaPoslani;
|
|
||||||
|
|
||||||
const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
|
const maKuldan = (id: string, komand: string, kuldan_komandu: number) => {
|
||||||
if (!kuldan_log[komand]) kuldan_log[komand] = {};
|
if (!kuldan_log[komand]) kuldan_log[komand] = {};
|
||||||
|
|||||||
@ -5,19 +5,25 @@ import { join } from "path";
|
|||||||
|
|
||||||
const cesta = join(__dirname, "../../res/komandi.json");
|
const cesta = join(__dirname, "../../res/komandi.json");
|
||||||
const komandi: SRecord<{ text: string; owner: string; }> = JSON.parse(readFileSync(cesta).toString());
|
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();
|
export const emitter = new EventEmitter();
|
||||||
|
|
||||||
function save(): void;
|
function save(): void;
|
||||||
function save(nesend: true): SRecord<Komand>;
|
function save(nesend: true): [SRecord<Komand>, KomandNaExport[]];
|
||||||
function save(nesend?: true) {
|
function save(nesend?: true) {
|
||||||
const cKomandi: SRecord<Komand> = {};
|
const cKomandi: SRecord<Komand> = {};
|
||||||
|
const naSend = baseNaSend;
|
||||||
Object.keys(komandi).forEach(c => {
|
Object.keys(komandi).forEach(c => {
|
||||||
cKomandi[c] = { run: komandi[c].text };
|
cKomandi[c] = { run: komandi[c].text };
|
||||||
|
naSend.push({ name: c });
|
||||||
});
|
});
|
||||||
if (nesend) return cKomandi;
|
if (nesend) return [cKomandi, naSend];
|
||||||
cKomandy = cKomandi;
|
cKomandy = cKomandi;
|
||||||
emitter.emit("komandi", cKomandy);
|
emitter.emit("komandi", cKomandy, naSend);
|
||||||
writeFileSync(cesta, JSON.stringify(komandi));
|
writeFileSync(cesta, JSON.stringify(komandi));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +47,3 @@ export const zapomen: RunFunkce = (mes, arg) => {
|
|||||||
save();
|
save();
|
||||||
return "jo";
|
return "jo";
|
||||||
};
|
};
|
||||||
|
|
||||||
export const naSend: KomandNaExport[] = [
|
|
||||||
{ name: "naucse", arg: "<jméno nového komandu> <obsah nového komandu>" },
|
|
||||||
{ name: "zapomen", arg: "název komandu" }
|
|
||||||
];
|
|
||||||
|
|||||||
@ -190,3 +190,7 @@ export function adminLog(client: Client, text: string) {
|
|||||||
client.users.cache.get(process.env.adminID)?.createDM().then(ch => ch.send(text));
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user