From 9d008d587a95c36921d16f2f9b7eac98bacc0896 Mon Sep 17 00:00:00 2001 From: Neuro Assassin <42872277+NeuroAssassin@users.noreply.github.com> Date: Tue, 18 Jun 2019 21:35:56 -0400 Subject: [PATCH] [V3 Core] Add checks to [p]command (#2770) * Add checks to [p]command * Change to privilege level --- redbot/core/core_commands.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 1657f219e..bdbaf2f08 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -35,6 +35,8 @@ from redbot.core import ( from .utils.predicates import MessagePredicate from .utils.chat_formatting import humanize_timedelta, pagify, box, inline +from .commands.requires import PrivilegeLevel + if TYPE_CHECKING: from redbot.core.bot import Red @@ -1912,6 +1914,12 @@ class Core(commands.Cog, CoreLogic): ) return + if self.command_manager in command_obj.parents or self.command_manager == command_obj: + await ctx.send( + _("The command to disable cannot be `command` or any of its subcommands.") + ) + return + async with ctx.bot.db.disabled_commands() as disabled_commands: if command not in disabled_commands: disabled_commands.append(command_obj.qualified_name) @@ -1934,6 +1942,16 @@ class Core(commands.Cog, CoreLogic): ) return + if self.command_manager in command_obj.parents or self.command_manager == command_obj: + await ctx.send( + _("The command to disable cannot be `command` or any of its subcommands.") + ) + return + + if command_obj.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): + await ctx.send(_("You are not allowed to disable that command.")) + return + async with ctx.bot.db.guild(ctx.guild).disabled_commands() as disabled_commands: if command not in disabled_commands: disabled_commands.append(command_obj.qualified_name) @@ -1990,6 +2008,10 @@ class Core(commands.Cog, CoreLogic): ) return + if command_obj.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): + await ctx.send(_("You are not allowed to enable that command.")) + return + async with ctx.bot.db.guild(ctx.guild).disabled_commands() as disabled_commands: with contextlib.suppress(ValueError): disabled_commands.remove(command_obj.qualified_name)