From cd653092e6f3561d1ee628f837dd800eb154405a Mon Sep 17 00:00:00 2001 From: Neuro Assassin Date: Thu, 13 Jun 2019 13:07:12 -0400 Subject: [PATCH 1/2] Add checks to [p]command --- redbot/core/core_commands.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 1657f219eb5..ecf36a9b5b2 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1912,6 +1912,12 @@ async def command_disable_global(self, ctx: commands.Context, *, command: str): ) 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 +1940,22 @@ async def command_disable_guild(self, ctx: commands.Context, *, command: str): ) 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 + + try: + can = await command_obj.can_run( + ctx, check_all_parents=True, change_permission_state=False + ) + except commands.CommandError: + can = False + if not can: + 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 +2012,16 @@ async def command_enable_guild(self, ctx: commands.Context, *, command: str): ) return + try: + can = await command_obj.can_run( + ctx, check_all_parents=True, change_permission_state=False + ) + except commands.CommandError: + can = False + if not can: + 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) From 622fd431058e4242cab09d6d71c90a31d0a31eca Mon Sep 17 00:00:00 2001 From: Neuro Assassin Date: Thu, 13 Jun 2019 13:43:31 -0400 Subject: [PATCH 2/2] Change to privilege level --- redbot/core/core_commands.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index ecf36a9b5b2..bdbaf2f08de 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -35,6 +35,8 @@ 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 @@ -1946,13 +1948,7 @@ async def command_disable_guild(self, ctx: commands.Context, *, command: str): ) return - try: - can = await command_obj.can_run( - ctx, check_all_parents=True, change_permission_state=False - ) - except commands.CommandError: - can = False - if not can: + if command_obj.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): await ctx.send(_("You are not allowed to disable that command.")) return @@ -2012,13 +2008,7 @@ async def command_enable_guild(self, ctx: commands.Context, *, command: str): ) return - try: - can = await command_obj.can_run( - ctx, check_all_parents=True, change_permission_state=False - ) - except commands.CommandError: - can = False - if not can: + if command_obj.requires.privilege_level > await PrivilegeLevel.from_ctx(ctx): await ctx.send(_("You are not allowed to enable that command.")) return