From 6bf657c3d284a9b3ef5df6d07c7303f93c777bda Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Tue, 31 Aug 2021 19:59:52 +0200 Subject: [PATCH] Revert "restricted access to CommandManager's list" This reverts commit 00753477dec31c5c05bf4ba06d1897a0bfa1ea7f. --- src/Bot.ts | 9 +++------ src/CommandManager.ts | 11 +---------- src/Help.ts | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/Bot.ts b/src/Bot.ts index f8eae3b..fcd6565 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -132,6 +132,7 @@ export class Bot extends EventEmitter { const helpMsg: Command = new HelpMessage(this.commands, this.messages.help, this.name); this.commands.add(helpMsg); } + Object.freeze(this.commands.list); process.stdout.write("Connecting to Discord... "); this.client.login(this.token); this.client.on("ready", async () => { @@ -247,15 +248,11 @@ export class Bot extends EventEmitter { process.stdout.write("Registering commands... "); await axios.put( `https://discord.com/api/v8/applications/${this.applicationId}/commands`, - this.commands - .getList() - .filter((c) => !Array.isArray(c.guilds) && c.slash) - .map((c) => c.toCommandObject()), + this.commands.list.filter((c) => !Array.isArray(c.guilds) && c.slash).map((c) => c.toCommandObject()), { headers: { Authorization: `Bot ${this.token}` } } ); const guilds: any = {}; - await this.commands - .getList() + await this.commands.list .filter((c) => Array.isArray(c.guilds) && c.guilds.length > 0) .map((c) => { c.guilds?.map(async (g) => { diff --git a/src/CommandManager.ts b/src/CommandManager.ts index cf4268e..685e6ec 100644 --- a/src/CommandManager.ts +++ b/src/CommandManager.ts @@ -12,7 +12,7 @@ export class CommandManager { * List of commands registered in the manager * @type {Array} {@link Command} */ - private readonly list: Command[]; + public readonly list: Command[]; /** * Prefix used as a way to trigger the bot using messages * @type {string} @@ -56,15 +56,6 @@ export class CommandManager { return command; } - /** - * Get all commands registered in a manager - * @returns {Command[]} List of registered commands in a manager - */ - getList(): Command[] { - const list = this.list; - return list; - } - /** * Adds the given {@link Command} to the instance manager with initial processing * @param {Command} command - {@link Command} instance object diff --git a/src/Help.ts b/src/Help.ts index 47faaf6..b3c666f 100644 --- a/src/Help.ts +++ b/src/Help.ts @@ -61,7 +61,7 @@ export class HelpMessage extends Command { helpMsg.setTitle(params.title); helpMsg.setDescription(params.bottomText); - cmdManager.getList().map((c) => { + cmdManager.list.map((c) => { if ( c.visible && ((Array.isArray(c.guilds) && c.guilds.length > 0 && c.guilds.find((g) => i?.guild?.id === g)) || !Array.isArray(c.guilds) || c.guilds.length === 0)