From 2b5e4a27bbe9377e358098236691225fba9d212c Mon Sep 17 00:00:00 2001 From: Isaac Date: Sun, 30 May 2021 18:05:05 +0100 Subject: [PATCH] Move blacklist check to after command stuff --- src/modules/commands/manager.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/modules/commands/manager.js b/src/modules/commands/manager.js index 78b15fa..8c3a88c 100644 --- a/src/modules/commands/manager.js +++ b/src/modules/commands/manager.js @@ -74,6 +74,18 @@ module.exports = class CommandManager { const settings = await message.guild.getSettings(); const i18n = this.client.i18n.getLocale(settings.locale); + const prefix = settings.command_prefix; + const escaped_prefix = prefix.toLowerCase().replace(/(?=\W)/g, '\\'); // (lazy) escape every character so it can be used in a RexExp + const client_mention = `<@!?${this.client.user.id}>`; + + let cmd_name = message.content.match(new RegExp(`^(${escaped_prefix}|${client_mention}\\s?)(\\S+)`, 'mi')); // capture prefix and command + if (!cmd_name) return; // stop here if the message is not a command + + const raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command + cmd_name = cmd_name[2].toLowerCase(); // set cmd_name to the actual command alias, effectively removing the prefix + + const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name)); + if (!cmd) return; let is_blacklisted = false; if (settings.blacklist?.includes(message.author.id)) { @@ -96,19 +108,6 @@ module.exports = class CommandManager { } } - const prefix = settings.command_prefix; - const escaped_prefix = prefix.toLowerCase().replace(/(?=\W)/g, '\\'); // (lazy) escape every character so it can be used in a RexExp - const client_mention = `<@!?${this.client.user.id}>`; - - let cmd_name = message.content.match(new RegExp(`^(${escaped_prefix}|${client_mention}\\s?)(\\S+)`, 'mi')); // capture prefix and command - if (!cmd_name) return; // stop here if the message is not a command - - const raw_args = message.content.replace(cmd_name[0], '').trim(); // remove the prefix and command - cmd_name = cmd_name[2].toLowerCase(); // set cmd_name to the actual command alias, effectively removing the prefix - - const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name)); - if (!cmd) return; - const bot_permissions = message.guild.me.permissionsIn(message.channel); const required_bot_permissions = [ 'ADD_REACTIONS',