mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[commands] Implement __call__ to commands.Command (#3241)
* This is technically awesome, but let's not document it for public use rn * changelog
This commit is contained in:
parent
c7fd64e0c8
commit
77235f7750
1
changelog.d/3241.misc.rst
Normal file
1
changelog.d/3241.misc.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
implements ``__call__`` for commands
|
||||||
@ -201,6 +201,13 @@ class Command(CogCommandMixin, commands.Command):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def __call__(self, *args, **kwargs):
|
||||||
|
if self.cog:
|
||||||
|
# We need to inject cog as self here
|
||||||
|
return self.callback(self.cog, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
return self.callback(*args, **kwargs)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._help_override = kwargs.pop("help_override", None)
|
self._help_override = kwargs.pop("help_override", None)
|
||||||
@ -637,7 +644,7 @@ class CogMixin(CogGroupMixin, CogCommandMixin):
|
|||||||
@property
|
@property
|
||||||
def all_commands(self) -> Dict[str, Command]:
|
def all_commands(self) -> Dict[str, Command]:
|
||||||
"""
|
"""
|
||||||
This does not have identical behavior to
|
This does not have identical behavior to
|
||||||
Group.all_commands but should return what you expect
|
Group.all_commands but should return what you expect
|
||||||
"""
|
"""
|
||||||
return {cmd.name: cmd for cmd in self.__cog_commands__}
|
return {cmd.name: cmd for cmd in self.__cog_commands__}
|
||||||
@ -653,7 +660,7 @@ class CogMixin(CogGroupMixin, CogCommandMixin):
|
|||||||
"""
|
"""
|
||||||
This really just exists to allow easy use with other methods using can_run
|
This really just exists to allow easy use with other methods using can_run
|
||||||
on commands and groups such as help formatters.
|
on commands and groups such as help formatters.
|
||||||
|
|
||||||
kwargs used in that won't apply here as they don't make sense to,
|
kwargs used in that won't apply here as they don't make sense to,
|
||||||
but will be swallowed silently for a compatible signature for ease of use.
|
but will be swallowed silently for a compatible signature for ease of use.
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user