mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Core] Add checks to [p]command (#2770)
* Add checks to [p]command * Change to privilege level
This commit is contained in:
parent
804d6eecea
commit
9d008d587a
@ -35,6 +35,8 @@ from redbot.core import (
|
|||||||
from .utils.predicates import MessagePredicate
|
from .utils.predicates import MessagePredicate
|
||||||
from .utils.chat_formatting import humanize_timedelta, pagify, box, inline
|
from .utils.chat_formatting import humanize_timedelta, pagify, box, inline
|
||||||
|
|
||||||
|
from .commands.requires import PrivilegeLevel
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from redbot.core.bot import Red
|
from redbot.core.bot import Red
|
||||||
|
|
||||||
@ -1912,6 +1914,12 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
)
|
)
|
||||||
return
|
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:
|
async with ctx.bot.db.disabled_commands() as disabled_commands:
|
||||||
if command not in disabled_commands:
|
if command not in disabled_commands:
|
||||||
disabled_commands.append(command_obj.qualified_name)
|
disabled_commands.append(command_obj.qualified_name)
|
||||||
@ -1934,6 +1942,16 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
)
|
)
|
||||||
return
|
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:
|
async with ctx.bot.db.guild(ctx.guild).disabled_commands() as disabled_commands:
|
||||||
if command not in disabled_commands:
|
if command not in disabled_commands:
|
||||||
disabled_commands.append(command_obj.qualified_name)
|
disabled_commands.append(command_obj.qualified_name)
|
||||||
@ -1990,6 +2008,10 @@ class Core(commands.Cog, CoreLogic):
|
|||||||
)
|
)
|
||||||
return
|
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:
|
async with ctx.bot.db.guild(ctx.guild).disabled_commands() as disabled_commands:
|
||||||
with contextlib.suppress(ValueError):
|
with contextlib.suppress(ValueError):
|
||||||
disabled_commands.remove(command_obj.qualified_name)
|
disabled_commands.remove(command_obj.qualified_name)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user