Add necessary None checks to Core's usage of Requires.privilege_level (#5477)

* Check if it has a privilege level

* Let's fix this in warnings too

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
aleclol
2021-12-24 20:04:33 -05:00
committed by GitHub
parent bae85c35c1
commit 5e527cb27d
2 changed files with 12 additions and 8 deletions

View File

@@ -55,7 +55,8 @@ async def create_and_invoke_context(
await realctx.bot.invoke(fctx) await realctx.bot.invoke(fctx)
except (commands.CheckFailure, commands.CommandOnCooldown): except (commands.CheckFailure, commands.CommandOnCooldown):
# reinvoke bypasses checks and we don't want to run bot owner only commands here # 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() await fctx.reinvoke()
@@ -71,7 +72,8 @@ def get_command_from_input(bot, userinput: str):
if com is None: if com is None:
return None, _("I could not find a command from that input!") 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 ( return (
None, None,
_("That command requires bot owner. I can't allow you to use that for an action"), _("That command requires bot owner. I can't allow you to use that for an action"),

View File

@@ -4998,6 +4998,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
) )
return return
if command.requires.privilege_level is not None:
if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx):
await ctx.send(_("You are not allowed to disable that command.")) await ctx.send(_("You are not allowed to disable that command."))
return return
@@ -5069,6 +5070,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
**Arguments:** **Arguments:**
- `<command>` - The command to enable for the current server. - `<command>` - The command to enable for the current server.
""" """
if command.requires.privilege_level is not None:
if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): if command.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx):
await ctx.send(_("You are not allowed to enable that command.")) await ctx.send(_("You are not allowed to enable that command."))
return return