mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
fix: refactored help slash command
This commit is contained in:
1 parent
d0e929e284
commit
922337769d
2 files changed
+80
-34
No files matched your search
@@ -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 { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||||
|
import { ExtendedClient } from '../../../types/clientTypes';
|
||||||
|
|
||||||
class HelpCommand extends BaseSlashCommandInteraction {
|
class HelpCommand extends BaseSlashCommandInteraction {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -12,37 +19,11 @@ class HelpCommand extends BaseSlashCommandInteraction {
|
|||||||
const { executionId, client, interaction } = params;
|
const { executionId, client, interaction } = params;
|
||||||
const logger = this.getLogger(this.name, executionId, interaction);
|
const logger = this.getLogger(this.name, executionId, interaction);
|
||||||
|
|
||||||
const commandList = client!
|
const [commandEmbedString, supportServerString, addBotString] = await Promise.all([
|
||||||
.slashCommandInteractions!.filter((command: BaseSlashCommandInteraction) => {
|
this.getCommandEmbedString(client!),
|
||||||
// don't include system commands
|
this.getSupportServerString(),
|
||||||
if (command.isSystemCommand) {
|
this.getAddBotString()
|
||||||
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})**`
|
|
||||||
: '';
|
|
||||||
|
|
||||||
logger.debug('Responding with info embed.');
|
logger.debug('Responding with info embed.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
@@ -50,7 +31,7 @@ class HelpCommand extends BaseSlashCommandInteraction {
|
|||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`${this.embedOptions.icons.rule} **List of commands**\n` +
|
`${this.embedOptions.icons.rule} **List of commands**\n` +
|
||||||
`${commandListString}\n\n` +
|
commandEmbedString +
|
||||||
supportServerString +
|
supportServerString +
|
||||||
addBotString
|
addBotString
|
||||||
)
|
)
|
||||||
@@ -58,6 +39,71 @@ class HelpCommand extends BaseSlashCommandInteraction {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getNonSystemCommands(client: ExtendedClient): Collection<string, BaseSlashCommandInteraction> {
|
||||||
|
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<string> {
|
||||||
|
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<string> {
|
||||||
|
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<string> {
|
||||||
|
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();
|
export default new HelpCommand();
|
||||||
@@ -45,7 +45,7 @@ class LeaveCommand extends BaseSlashCommandInteraction {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async deleteQueue(queue: GuildQueue): Promise<void> {
|
private async deleteQueue(queue: GuildQueue): Promise<void> {
|
||||||
if (!queue.deleted) {
|
if (!queue.deleted) {
|
||||||
queue.delete();
|
queue.delete();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user