mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
fix(bots/discord): owners cannot bypass checks on some commands
This commit is contained in:
@@ -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> | void
|
||||
execute: (
|
||||
context: typeof import('../context'),
|
||||
interaction: ChatInputCommandInteraction,
|
||||
info: Info,
|
||||
) => Promise<void> | void
|
||||
memberRequirements?: {
|
||||
/**
|
||||
* The mode to use when checking for requirements.
|
||||
@@ -46,3 +50,7 @@ export type Command = {
|
||||
*/
|
||||
global?: boolean
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
userIsOwner: boolean
|
||||
}
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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']({
|
||||
|
||||
Reference in New Issue
Block a user