diff --git a/bots/discord/src/commands/index.ts b/bots/discord/src/commands/index.ts index 2f94f85..e782811 100644 --- a/bots/discord/src/commands/index.ts +++ b/bots/discord/src/commands/index.ts @@ -10,7 +10,11 @@ export type Command = { * The function to execute when this command is triggered * @param interaction The interaction that triggered this command */ - execute: (context: typeof import('../context'), interaction: ChatInputCommandInteraction) => Promise | void + execute: ( + context: typeof import('../context'), + interaction: ChatInputCommandInteraction, + info: Info, + ) => Promise | void memberRequirements?: { /** * The mode to use when checking for requirements. @@ -46,3 +50,7 @@ export type Command = { */ global?: boolean } + +export interface Info { + userIsOwner: boolean +} diff --git a/bots/discord/src/commands/moderation/mute.ts b/bots/discord/src/commands/moderation/mute.ts index 8328c6f..8cd8bbc 100644 --- a/bots/discord/src/commands/moderation/mute.ts +++ b/bots/discord/src/commands/moderation/mute.ts @@ -24,7 +24,7 @@ export default { global: false, - async execute({ logger }, interaction) { + async execute({ logger }, interaction, { userIsOwner }) { const user = interaction.options.getUser('member', true) const reason = interaction.options.getString('reason') ?? 'No reason provided' const duration = interaction.options.getString('duration') @@ -48,7 +48,7 @@ export default { if (member.manageable) throw new CommandError(CommandErrorType.Generic, 'This user cannot be managed by the bot.') - if (moderator.roles.highest.comparePositionTo(member.roles.highest) <= 0) + if (moderator.roles.highest.comparePositionTo(member.roles.highest) <= 0 && !userIsOwner) throw new CommandError( CommandErrorType.InvalidUser, 'You cannot mute a user with a role equal to or higher than yours.', diff --git a/bots/discord/src/commands/moderation/role-preset.ts b/bots/discord/src/commands/moderation/role-preset.ts index db7b7cd..959b664 100644 --- a/bots/discord/src/commands/moderation/role-preset.ts +++ b/bots/discord/src/commands/moderation/role-preset.ts @@ -35,7 +35,7 @@ export default { global: false, - async execute({ logger }, interaction) { + async execute({ logger }, interaction, { userIsOwner }) { const action = interaction.options.getString('action', true) as 'apply' | 'remove' const user = interaction.options.getUser('member', true) const preset = interaction.options.getString('preset', true) @@ -61,7 +61,7 @@ export default { 'The duration must be at least 1 millisecond long.', ) - if (moderator.roles.highest.comparePositionTo(member.roles.highest) <= 0) + if (moderator.roles.highest.comparePositionTo(member.roles.highest) <= 0 && !userIsOwner) throw new CommandError( CommandErrorType.InvalidUser, 'You cannot apply a role preset to a user with a role equal to or higher than yours.', diff --git a/bots/discord/src/events/discord/interactionCreate/chat-commmand.ts b/bots/discord/src/events/discord/interactionCreate/chat-commmand.ts index 79d262a..9300b75 100644 --- a/bots/discord/src/events/discord/interactionCreate/chat-commmand.ts +++ b/bots/discord/src/events/discord/interactionCreate/chat-commmand.ts @@ -69,7 +69,7 @@ export default on('interactionCreate', async (context, interaction) => { try { logger.debug(`Command ${interaction.commandName} being executed`) - await command.execute(context, interaction) + await command.execute(context, interaction, { userIsOwner: isOwner }) } catch (err) { logger.error(`Error while executing command ${interaction.commandName}:`, err) await interaction[interaction.replied ? 'followUp' : 'reply']({