diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:23:12 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 22:23:12 -0400 |
commit | 4d63c4af57a7391dd61106b79874b8e83c14971a (patch) | |
tree | 4d9aa589b3501169d9ddfe8f0fdff50d9080b553 /src/commands/info | |
parent | 759e93bec4e9e2eb86db7434007345c24b0a0252 (diff) | |
download | tanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.tar.gz tanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.tar.bz2 tanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.zip |
change all existing slash commands to have no repeating code, add help slash command
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/botinfo.ts | 14 | ||||
-rw-r--r-- | src/commands/info/help.ts | 38 |
2 files changed, 43 insertions, 9 deletions
diff --git a/src/commands/info/botinfo.ts b/src/commands/info/botinfo.ts index 306c142..8f5f055 100644 --- a/src/commands/info/botinfo.ts +++ b/src/commands/info/botinfo.ts @@ -1,4 +1,4 @@ -import { MessageEmbed, Message } from 'discord.js'; +import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { duration } from 'moment'; @@ -14,7 +14,7 @@ export default class BotInfoCommand extends BotCommand { }); } - public async exec(message: Message): Promise<void> { + private async generateEmbed(): Promise<MessageEmbed> { const owners = (await this.client.util.mapIDs(this.client.ownerID)) .map((u) => u.tag) .join('\n'); @@ -52,6 +52,14 @@ export default class BotInfoCommand extends BotCommand { } ]) .setTimestamp(); - await message.util.send(embed); + return embed; + } + + public async exec(message: Message): Promise<void> { + await message.util.send(await this.generateEmbed()); + } + + public async execSlash(message: CommandInteraction): Promise<void> { + await message.reply(await this.generateEmbed()); } } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 73dcdbb..cdddb51 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,6 +1,8 @@ import { Message, MessageEmbed } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { stripIndent } from 'common-tags'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; export default class HelpCommand extends BotCommand { constructor() { @@ -17,14 +19,19 @@ export default class HelpCommand extends BotCommand { id: 'command', type: 'commandAlias' } + ], + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'command', + description: 'The command to get help for', + required: false + } ] }); } - public async exec( - message: Message, - { command }: { command: BotCommand } - ): Promise<Message> { + private generateEmbed(command?: BotCommand): MessageEmbed { const prefix = this.handler.prefix; if (!command) { const embed = new MessageEmbed() @@ -49,7 +56,7 @@ export default class HelpCommand extends BotCommand { .join(' ')}` ); } - return message.util.send(embed); + return embed; } const embed = new MessageEmbed() @@ -72,7 +79,26 @@ export default class HelpCommand extends BotCommand { `\`${command.description.examples.join('`\n`')}\``, true ); + return embed; + } - return message.util.send(embed); + public async exec( + message: Message, + { command }: { command: BotCommand } + ): Promise<void> { + await message.util.send(this.generateEmbed(command)); + } + + public async execSlash(message: CommandInteraction): Promise<void> { + const command = message.options.find((o) => o.name === 'command')?.value as + | string + | undefined; + if (command) { + await message.reply( + this.generateEmbed(this.handler.findCommand(command) as BotCommand) + ); + } else { + await message.reply(this.generateEmbed()); + } } } |