From 5dd0c3b5799c08582f2e2e1bccd1899174ecaa53 Mon Sep 17 00:00:00 2001 From: Red-GitHubBot <88117545+Red-GitHubBot@users.noreply.github.com> Date: Sat, 25 Dec 2021 02:06:08 +0100 Subject: [PATCH] [3.4] Add necessary None checks to Core's usage of `Requires.privilege_level` (#5477) (#5483) * Check if it has a privilege level * Let's fix this in warnings too (cherry picked from commit 5e527cb27df24b2b9bb9ce6fe93df9394dbb674b) Co-authored-by: aleclol <50505980+aleclol@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: aleclol <50505980+aleclol@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/cogs/warnings/helpers.py | 6 ++++-- redbot/core/core_commands.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/redbot/cogs/warnings/helpers.py b/redbot/cogs/warnings/helpers.py index 9c2d4fbe3..5f0a92056 100644 --- a/redbot/cogs/warnings/helpers.py +++ b/redbot/cogs/warnings/helpers.py @@ -55,7 +55,8 @@ async def create_and_invoke_context( await realctx.bot.invoke(fctx) except (commands.CheckFailure, commands.CommandOnCooldown): # reinvoke bypasses checks and we don't want to run bot owner only commands here - if fctx.command.requires.privilege_level < PrivilegeLevel.BOT_OWNER: + privilege_level = fctx.command.requires.privilege_level + if privilege_level is None or privilege_level < PrivilegeLevel.BOT_OWNER: await fctx.reinvoke() @@ -71,7 +72,8 @@ def get_command_from_input(bot, userinput: str): if com is None: return None, _("I could not find a command from that input!") - if com.requires.privilege_level >= PrivilegeLevel.BOT_OWNER: + privilege_level = com.requires.privilege_level + if privilege_level is not None and privilege_level >= PrivilegeLevel.BOT_OWNER: return ( None, _("That command requires bot owner. I can't allow you to use that for an action"), diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 94f6d8791..857248db9 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -4418,9 +4418,10 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): ) return - if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): - await ctx.send(_("You are not allowed to disable that command.")) - return + if command.requires.privilege_level is not None: + if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): + await ctx.send(_("You are not allowed to disable that command.")) + return async with ctx.bot._config.guild(ctx.guild).disabled_commands() as disabled_commands: if command.qualified_name not in disabled_commands: @@ -4489,9 +4490,10 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): **Arguments:** - `` - The command to enable for the current server. """ - if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): - await ctx.send(_("You are not allowed to enable that command.")) - return + if command.requires.privilege_level is not None: + if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): + await ctx.send(_("You are not allowed to enable that command.")) + return async with ctx.bot._config.guild(ctx.guild).disabled_commands() as disabled_commands: with contextlib.suppress(ValueError):