From 284e1d1d693486f6c50cdb8b38f01cdf74eb63d2 Mon Sep 17 00:00:00 2001 From: TymanWasTaken Date: Sun, 16 May 2021 21:40:52 -0400 Subject: fix logging for slash command syncing, rename a few files --- src/listeners/client/CreateSlashCommands.ts | 58 --------------------------- src/listeners/client/syncslashcommands.ts | 61 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 58 deletions(-) delete mode 100644 src/listeners/client/CreateSlashCommands.ts create mode 100644 src/listeners/client/syncslashcommands.ts (limited to 'src/listeners/client') diff --git a/src/listeners/client/CreateSlashCommands.ts b/src/listeners/client/CreateSlashCommands.ts deleted file mode 100644 index c395b3a..0000000 --- a/src/listeners/client/CreateSlashCommands.ts +++ /dev/null @@ -1,58 +0,0 @@ -import chalk from 'chalk'; -import { BotListener } from '../../lib/extensions/BotListener'; - -export default class CreateSlashCommands extends BotListener { - constructor() { - super('createslashcommands', { - emitter: 'client', - event: 'ready' - }); - } - async exec(): Promise { - try { - const enabled = await this.client.application.commands.fetch(); - for (const command of enabled) { - if ( - !this.client.commandHandler.modules.find( - (cmd) => cmd.id == command[1].name - ) - ) { - await this.client.application.commands.delete(command[1].id); - this.client.logger.verbose( - `{red Deleted slash command ${command[1].name}}` - ); - } - } - - for (const cmd of this.client.commandHandler.modules) { - if (cmd[1].execSlash) { - const found = enabled.find((i) => i.name == cmd[1].id); - - const slashdata = { - name: cmd[1].id, - description: cmd[1].description.content, - options: cmd[1].options.slashCommandOptions - }; - - if (found?.id) { - if (slashdata.description !== found.description) { - await this.client.application.commands.edit(found.id, slashdata); - } - } else { - this.client.logger.verbose( - `{red Deleted slash command ${cmd[1].id}}` - ); - await this.client.application.commands.create(slashdata); - } - } - } - - return this.client.logger.log(chalk.green('Slash commands registered')); - } catch (e) { - console.log(chalk.red(e)); - return this.client.logger.error( - '{red Slash commands not registered, see above error.}' - ); - } - } -} diff --git a/src/listeners/client/syncslashcommands.ts b/src/listeners/client/syncslashcommands.ts new file mode 100644 index 0000000..2388104 --- /dev/null +++ b/src/listeners/client/syncslashcommands.ts @@ -0,0 +1,61 @@ +import chalk from 'chalk'; +import { BotListener } from '../../lib/extensions/BotListener'; + +export default class CreateSlashCommands extends BotListener { + constructor() { + super('createslashcommands', { + emitter: 'client', + event: 'ready' + }); + } + async exec(): Promise { + try { + const registered = await this.client.application.commands.fetch(); + for (const [, registeredCommand] of registered) { + if ( + !this.client.commandHandler.modules.find( + (cmd) => cmd.id == registeredCommand.name + ) + ) { + await this.client.application.commands.delete(registeredCommand.id); + this.client.logger.verbose( + `{red Deleted slash command ${registeredCommand.name}}` + ); + } + } + + for (const [, botCommand] of this.client.commandHandler.modules) { + if (botCommand.execSlash) { + const found = registered.find((i) => i.name == botCommand.id); + + const slashdata = { + name: botCommand.id, + description: botCommand.description.content, + options: botCommand.options.slashCommandOptions + }; + + if (found?.id) { + if (slashdata.description !== found.description) { + await this.client.application.commands.edit(found.id, slashdata); + this.client.logger.verbose( + `{orange Edited slash command ${botCommand.id}}` + ); + } + } else { + await this.client.application.commands.create(slashdata); + this.client.logger.verbose( + `{green Created slash command ${botCommand.id}}` + ); + } + } + } + + return this.client.logger.log(chalk.green('Slash commands registered')); + } catch (e) { + console.log(chalk.red(e)); + return this.client.logger.error( + '{red Slash commands not registered, see above error.}' + ); + } + } +} -- cgit