diff --git a/src/interactions/commands/info/help.ts b/src/interactions/commands/info/help.ts index 62729b8..8e4c521 100644 --- a/src/interactions/commands/info/help.ts +++ b/src/interactions/commands/info/help.ts @@ -1,6 +1,13 @@ -import { EmbedBuilder, SlashCommandBuilder, SlashCommandNumberOption, SlashCommandStringOption } from 'discord.js'; +import { + Collection, + EmbedBuilder, + SlashCommandBuilder, + SlashCommandNumberOption, + SlashCommandStringOption +} from 'discord.js'; import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { ExtendedClient } from '../../../types/clientTypes'; class HelpCommand extends BaseSlashCommandInteraction { constructor() { @@ -12,37 +19,11 @@ class HelpCommand extends BaseSlashCommandInteraction { const { executionId, client, interaction } = params; const logger = this.getLogger(this.name, executionId, interaction); - const commandList = client! - .slashCommandInteractions!.filter((command: BaseSlashCommandInteraction) => { - // don't include system commands - if (command.isSystemCommand) { - return false; - } - return true; - }) - .map((command: BaseSlashCommandInteraction) => { - let params: string = ''; - const option = command.data.options[0]; - if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) { - params = `**\`${option.name}\`**` + ' '; - } - const beta: string = command.isBeta ? `${this.embedOptions.icons.beta} ` : ''; - const newCommand: string = command.isNew ? `${this.embedOptions.icons.new} ` : ''; - return `- **\`/${command.data.name}\`** ${params}- ${beta}${newCommand}${command.data.description}`; - }); - - const commandListString: string = commandList.join('\n'); - - const supportServerString: string = this.botOptions.serverInviteUrl - ? `${this.embedOptions.icons.support} **Support server**\n` + - 'Join the support server for help or to suggest improvements: \n' + - `**${this.botOptions.serverInviteUrl}**\n\n` - : ''; - const addBotString: string = this.botOptions.botInviteUrl - ? `${this.embedOptions.icons.bot} **Enjoying ${this.botOptions.name}?**\n` + - 'Add me to another server: \n' + - `**[Click me!](${this.botOptions.botInviteUrl})**` - : ''; + const [commandEmbedString, supportServerString, addBotString] = await Promise.all([ + this.getCommandEmbedString(client!), + this.getSupportServerString(), + this.getAddBotString() + ]); logger.debug('Responding with info embed.'); return await interaction.editReply({ @@ -50,7 +31,7 @@ class HelpCommand extends BaseSlashCommandInteraction { new EmbedBuilder() .setDescription( `${this.embedOptions.icons.rule} **List of commands**\n` + - `${commandListString}\n\n` + + commandEmbedString + supportServerString + addBotString ) @@ -58,6 +39,71 @@ class HelpCommand extends BaseSlashCommandInteraction { ] }); } + + private getNonSystemCommands(client: ExtendedClient): Collection { + const clientSlashCommands = client.slashCommandInteractions; + const nonSystemCommands = clientSlashCommands?.filter((command) => !command.isSystemCommand); + + if (!nonSystemCommands) { + throw new Error('No non-system commands found.'); + } + + return nonSystemCommands; + } + + private async getCommandEmbedString(client: ExtendedClient): Promise { + const commandCollection = this.getNonSystemCommands(client!); + + const commandStringList = commandCollection.map((command: BaseSlashCommandInteraction) => { + return this.getCommandString(command); + }); + + const commandString = commandStringList.join('\n') + '\n'; + return commandString; + } + + private getCommandString(command: BaseSlashCommandInteraction): string { + const commandParams: string = this.getCommandParams(command); + const beta: string = command.isBeta ? `${this.embedOptions.icons.beta} ` : ''; + const newCommand: string = command.isNew ? `${this.embedOptions.icons.new} ` : ''; + return `- **\`/${command.data.name}\`** ${commandParams}- ${beta}${newCommand}${command.data.description}`; + } + + private getCommandParams(command: BaseSlashCommandInteraction): string { + const option = command.data.options[0]; + if (option instanceof SlashCommandNumberOption || option instanceof SlashCommandStringOption) { + return `**\`${option.name}\`** `; + } + return ''; + } + + private async getSupportServerString(): Promise { + if (!this.botOptions.serverInviteUrl) { + return ''; + } + + const embedString = ` + ${this.embedOptions.icons.support} **Support server** + Join the support server for help or to suggest improvements: + **${this.botOptions.serverInviteUrl}** + `; + + return embedString; + } + + private async getAddBotString(): Promise { + if (!this.botOptions.botInviteUrl) { + return ''; + } + + const embedString = ` + ${this.embedOptions.icons.bot} **Enjoying ${this.botOptions.name}?** + Add me to another server: + **[Click me!](${this.botOptions.botInviteUrl})** + `; + + return embedString; + } } export default new HelpCommand(); diff --git a/src/interactions/commands/player/leave.ts b/src/interactions/commands/player/leave.ts index 1aa1e4d..6e5c9f4 100644 --- a/src/interactions/commands/player/leave.ts +++ b/src/interactions/commands/player/leave.ts @@ -45,7 +45,7 @@ class LeaveCommand extends BaseSlashCommandInteraction { }); } - protected async deleteQueue(queue: GuildQueue): Promise { + private async deleteQueue(queue: GuildQueue): Promise { if (!queue.deleted) { queue.delete(); }