converted commands to classes

This commit is contained in:
Marius Begby committed 2023-08-31 13:22:28 +02:00
1 parent 335f4bb84e
commit d81fc1d2e7
35 files changed
+618 -768

No files matched your search

+20 -30
View File
@@ -1,32 +1,21 @@
import config from 'config';
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import { Logger } from 'pino';
import loggerModule from '../../../services/logger';
import { ExtendedClient } from '../../../types/clientTypes';
import { EmbedOptions } from '../../../types/configTypes';
import { BaseSlashCommandInteraction } from '../../../types/interactionTypes';
import {
BaseSlashCommandInteraction,
BaseSlashCommandParams,
BaseSlashCommandReturnType
} from '../../../types/interactionTypes';
import { notValidGuildId } from '../../../utils/validation/systemCommandValidator';
const embedOptions: EmbedOptions = config.get('embedOptions');
class ReloadCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder().setName('reload').setDescription('Reload the bot commands.');
super(data);
}
const command: BaseSlashCommandInteraction = {
isSystemCommand: true,
isNew: false,
isBeta: false,
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reload the bot commands.')
.setDMPermission(false)
.setNSFW(false),
execute: async ({ interaction, client, executionId }) => {
const logger: Logger = loggerModule.child({
source: 'reload.js',
module: 'slashCommand',
name: '/reload',
executionId: executionId,
shardId: interaction.guild?.shardId,
guildId: interaction.guild?.id
});
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction, client } = params;
const logger = this.getLogger(this.commandName, executionId, interaction);
if (await notValidGuildId({ interaction, executionId })) {
return;
@@ -53,9 +42,9 @@ const command: BaseSlashCommandInteraction = {
new EmbedBuilder()
.setDescription(
`**${embedOptions.icons.error} Oops!**\n_Hmm.._ It seems I am unable to reload commands across shards.`
`**${this.embedOptions.icons.error} Oops!**\n_Hmm.._ It seems I am unable to reload commands across shards.`
)
.setColor(embedOptions.colors.error)
.setColor(this.embedOptions.colors.error)
.setFooter({ text: `Execution ID: ${executionId}` })
]
});
@@ -66,13 +55,14 @@ const command: BaseSlashCommandInteraction = {
return `- **\`/${command.data.name}\`** ${params}- ${command.data.description}`;
});
const embedDescription: string = `**${embedOptions.icons.bot} Reloaded commands**\n` + commands?.join('\n');
const embedDescription: string =
`**${this.embedOptions.icons.bot} Reloaded commands**\n` + commands?.join('\n');
logger.debug('Responding with success embed.');
return await interaction.editReply({
embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(embedOptions.colors.success)]
embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(this.embedOptions.colors.success)]
});
}
};
}
export default command;
export default new ReloadCommand();