Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V3 Core] Add checks to [p]command #2770

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions redbot/core/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1912,6 +1914,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)
Expand All @@ -1934,6 +1942,16 @@ 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

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)
Expand Down Expand Up @@ -1990,6 +2008,10 @@ async def command_enable_guild(self, ctx: commands.Context, *, command: str):
)
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)
Expand Down