mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-18 00:33:59 +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
|
* The function to execute when this command is triggered
|
||||||
* @param interaction The interaction that triggered this command
|
* @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?: {
|
memberRequirements?: {
|
||||||
/**
|
/**
|
||||||
* The mode to use when checking for requirements.
|
* The mode to use when checking for requirements.
|
||||||
@@ -46,3 +50,7 @@ export type Command = {
|
|||||||
*/
|
*/
|
||||||
global?: boolean
|
global?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Info {
|
||||||
|
userIsOwner: boolean
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export default {
|
|||||||
|
|
||||||
global: false,
|
global: false,
|
||||||
|
|
||||||
async execute({ logger }, interaction) {
|
async execute({ logger }, interaction, { userIsOwner }) {
|
||||||
const user = interaction.options.getUser('member', true)
|
const user = interaction.options.getUser('member', true)
|
||||||
const reason = interaction.options.getString('reason') ?? 'No reason provided'
|
const reason = interaction.options.getString('reason') ?? 'No reason provided'
|
||||||
const duration = interaction.options.getString('duration')
|
const duration = interaction.options.getString('duration')
|
||||||
@@ -48,7 +48,7 @@ export default {
|
|||||||
if (member.manageable)
|
if (member.manageable)
|
||||||
throw new CommandError(CommandErrorType.Generic, 'This user cannot be managed by the bot.')
|
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(
|
throw new CommandError(
|
||||||
CommandErrorType.InvalidUser,
|
CommandErrorType.InvalidUser,
|
||||||
'You cannot mute a user with a role equal to or higher than yours.',
|
'You cannot mute a user with a role equal to or higher than yours.',
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export default {
|
|||||||
|
|
||||||
global: false,
|
global: false,
|
||||||
|
|
||||||
async execute({ logger }, interaction) {
|
async execute({ logger }, interaction, { userIsOwner }) {
|
||||||
const action = interaction.options.getString('action', true) as 'apply' | 'remove'
|
const action = interaction.options.getString('action', true) as 'apply' | 'remove'
|
||||||
const user = interaction.options.getUser('member', true)
|
const user = interaction.options.getUser('member', true)
|
||||||
const preset = interaction.options.getString('preset', true)
|
const preset = interaction.options.getString('preset', true)
|
||||||
@@ -61,7 +61,7 @@ export default {
|
|||||||
'The duration must be at least 1 millisecond long.',
|
'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(
|
throw new CommandError(
|
||||||
CommandErrorType.InvalidUser,
|
CommandErrorType.InvalidUser,
|
||||||
'You cannot apply a role preset to a user with a role equal to or higher than yours.',
|
'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 {
|
try {
|
||||||
logger.debug(`Command ${interaction.commandName} being executed`)
|
logger.debug(`Command ${interaction.commandName} being executed`)
|
||||||
await command.execute(context, interaction)
|
await command.execute(context, interaction, { userIsOwner: isOwner })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`Error while executing command ${interaction.commandName}:`, err)
|
logger.error(`Error while executing command ${interaction.commandName}:`, err)
|
||||||
await interaction[interaction.replied ? 'followUp' : 'reply']({
|
await interaction[interaction.replied ? 'followUp' : 'reply']({
|
||||||
|
|||||||
Reference in New Issue
Block a user