mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 22:15:37 +00:00
Add class for interactions
This commit is contained in:
1 parent
d0f1e940a5
commit
b96a73df6f
37 files changed
+1038
-1012
No files matched your search
@@ -1,32 +1,24 @@
|
||||
import config from 'config';
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import loggerModule from '../../../services/logger';
|
||||
import { ApplicationCommandOption, ApplicationCommandOptionData, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { ExtendedClient } from '../../../types/clientTypes';
|
||||
import { EmbedOptions } from '../../../types/configTypes';
|
||||
import { CustomSlashCommandInteraction } 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 all slash commands across shards.');
|
||||
const isSystemCommand: boolean = true;
|
||||
super(data, isSystemCommand);
|
||||
}
|
||||
|
||||
const command: CustomSlashCommandInteraction = {
|
||||
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.name, executionId, interaction);
|
||||
|
||||
if (await notValidGuildId({ interaction, executionId })) {
|
||||
return;
|
||||
@@ -37,7 +29,7 @@ const command: CustomSlashCommandInteraction = {
|
||||
await client!
|
||||
.shard!.broadcastEval(
|
||||
async (shardClient: ExtendedClient, { executionId }) => {
|
||||
shardClient.registerClientCommands!({ client: shardClient, executionId });
|
||||
shardClient.registerClientInteractions!({ client: shardClient, executionId });
|
||||
},
|
||||
{ context: { executionId: executionId } }
|
||||
)
|
||||
@@ -53,26 +45,36 @@ const command: CustomSlashCommandInteraction = {
|
||||
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}` })
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
const commands: string[] | undefined = client!.commands?.map((command) => {
|
||||
const params: string = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : '';
|
||||
const commands: string[] | undefined = client!.slashCommandInteractions?.map((command: BaseSlashCommandInteraction) => {
|
||||
let params: string = '';
|
||||
|
||||
if (command.data.options && command.data.options.length > 1) {
|
||||
const options = command.data.options as unknown as ApplicationCommandOptionData[];
|
||||
|
||||
options.map((option: ApplicationCommandOption) => {
|
||||
params += `**\`${option.name}\`**` + ' ';
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
Reference in new issue
Block a user