mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
Improve unreleased Command.is_enabled() and document related methods (#6209)
Co-authored-by: Michael Oliveira <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
parent
df7bbe5b55
commit
6f920daeed
@ -461,11 +461,32 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
if not change_permission_state:
|
if not change_permission_state:
|
||||||
ctx.permission_state = original_state
|
ctx.permission_state = original_state
|
||||||
|
|
||||||
def is_enabled(self, ctx) -> bool:
|
def is_enabled(self, guild: Optional[discord.abc.Snowflake] = None) -> bool:
|
||||||
|
"""
|
||||||
|
Check if the command is enabled globally or in a guild.
|
||||||
|
|
||||||
|
When guild is provided, this method checks whether
|
||||||
|
the command is enabled both globally and in the guild.
|
||||||
|
|
||||||
|
This is generally set by the settings managed with
|
||||||
|
the ``[p]command enable/disable global/server`` commands.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
guild : discord.abc.Snowflake, optional
|
||||||
|
The guild to check that the command is enabled in.
|
||||||
|
If this is ``None``, this will check whether
|
||||||
|
the command is enabled globally.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
bool
|
||||||
|
``True`` if the command is enabled.
|
||||||
|
"""
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
return False
|
return False
|
||||||
if ctx.guild:
|
if guild is not None:
|
||||||
if self._disabled_in.has(ctx.guild.id):
|
if self._disabled_in.has(guild.id):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -473,7 +494,7 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
async def prepare(self, ctx, /):
|
async def prepare(self, ctx, /):
|
||||||
ctx.command = self
|
ctx.command = self
|
||||||
|
|
||||||
cmd_enabled = self.is_enabled(ctx)
|
cmd_enabled = self.is_enabled(ctx.guild)
|
||||||
if not cmd_enabled:
|
if not cmd_enabled:
|
||||||
raise DisabledCommand(f"{self.name} command is disabled")
|
raise DisabledCommand(f"{self.name} command is disabled")
|
||||||
|
|
||||||
@ -530,7 +551,15 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def disable_in(self, guild: discord.Guild) -> bool:
|
def disable_in(self, guild: discord.Guild) -> bool:
|
||||||
"""Disable this command in the given guild.
|
"""
|
||||||
|
Disable this command in the given guild.
|
||||||
|
|
||||||
|
This is generally called by the settings managed with
|
||||||
|
the ``[p]command disable global/server`` commands.
|
||||||
|
Any changes made outside of that will not persist after cog
|
||||||
|
reload and may also be affected when either of those commands
|
||||||
|
is called on this command. It is not recommended to rely on
|
||||||
|
this method, if you want a consistent behavior.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@ -541,7 +570,6 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
-------
|
-------
|
||||||
bool
|
bool
|
||||||
``True`` if the command wasn't already disabled.
|
``True`` if the command wasn't already disabled.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self._disabled_in.has(guild.id):
|
if self._disabled_in.has(guild.id):
|
||||||
return False
|
return False
|
||||||
@ -552,6 +580,13 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
def enable_in(self, guild: discord.Guild) -> bool:
|
def enable_in(self, guild: discord.Guild) -> bool:
|
||||||
"""Enable this command in the given guild.
|
"""Enable this command in the given guild.
|
||||||
|
|
||||||
|
This is generally called by the settings managed with
|
||||||
|
the ``[p]command disable global/server`` commands.
|
||||||
|
Any changes made outside of that will not persist after cog
|
||||||
|
reload and may also be affected when either of those commands
|
||||||
|
is called on this command. It is not recommended to rely on
|
||||||
|
this method, if you want a consistent behavior.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
guild : discord.Guild
|
guild : discord.Guild
|
||||||
@ -561,7 +596,6 @@ class Command(CogCommandMixin, DPYCommand):
|
|||||||
-------
|
-------
|
||||||
bool
|
bool
|
||||||
``True`` if the command wasn't already enabled.
|
``True`` if the command wasn't already enabled.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self._disabled_in.remove(guild.id)
|
self._disabled_in.remove(guild.id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user