Add support for Hybrid commands in Red (#5681)

Co-authored-by: Kowlin <10947836+Kowlin@users.noreply.github.com>
Co-authored-by: aikaterna <20862007+aikaterna@users.noreply.github.com>
Co-authored-by: Jakub Kuczys <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Kreusada <67752638+Kreusada@users.noreply.github.com>
Co-authored-by: Candy <28566705+mina9999@users.noreply.github.com>
Co-authored-by: Matt Chandra <55866950+matcha19@users.noreply.github.com>
Co-authored-by: Lemon Rose <78662983+japandotorg@users.noreply.github.com>
Co-authored-by: Honkertonken <94032937+Honkertonken@users.noreply.github.com>
Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
Co-authored-by: River <18037011+RheingoldRiver@users.noreply.github.com>
Co-authored-by: AAA3A <89632044+AAA3A-AAA3A@users.noreply.github.com>
Co-authored-by: Lemon Rose <japandotorg@users.noreply.github.com>
Co-authored-by: Julien Mauroy <pro.julien.mauroy@gmail.com>
Co-authored-by: TheThomanski <15034759+TheThomanski@users.noreply.github.com>
This commit is contained in:
TrustyJAID
2022-10-11 14:52:43 -06:00
committed by GitHub
parent 7ff89302b2
commit f8b0cc6c6a
4 changed files with 228 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
from __future__ import annotations
import asyncio
import inspect
import logging
@@ -29,6 +30,7 @@ from typing import (
MutableMapping,
Set,
overload,
TYPE_CHECKING,
)
from types import MappingProxyType
@@ -54,6 +56,13 @@ from .rpc import RPCMixin
from .utils import can_user_send_messages_in, common_filters, AsyncIter
from .utils._internal_utils import send_to_owners_with_prefix_replaced
if TYPE_CHECKING:
from discord.ext.commands.hybrid import CommandCallback, ContextT, P
from discord import app_commands
_T = TypeVar("_T")
CUSTOM_GROUPS = "CUSTOM_GROUPS"
COMMAND_SCOPE = "COMMAND"
SHARED_API_TOKENS = "SHARED_API_TOKENS"
@@ -1796,6 +1805,58 @@ class Red(
subcommand.requires.reset()
return command
def hybrid_command(
self,
name: Union[str, app_commands.locale_str] = discord.utils.MISSING,
with_app_command: bool = True,
*args: Any,
**kwargs: Any,
) -> Callable[[CommandCallback[Any, ContextT, P, _T]], commands.HybridCommand[Any, P, _T]]:
"""A shortcut decorator that invokes :func:`~redbot.core.commands.hybrid_command` and adds it to
the internal command list via :meth:`add_command`.
Returns
--------
Callable[..., :class:`HybridCommand`]
A decorator that converts the provided method into a Command, adds it to the bot, then returns it.
"""
def decorator(func: CommandCallback[Any, ContextT, P, _T]):
kwargs.setdefault("parent", self)
result = commands.hybrid_command(
name=name, *args, with_app_command=with_app_command, **kwargs
)(func)
self.add_command(result)
return result
return decorator
def hybrid_group(
self,
name: Union[str, app_commands.locale_str] = discord.utils.MISSING,
with_app_command: bool = True,
*args: Any,
**kwargs: Any,
) -> Callable[[CommandCallback[Any, ContextT, P, _T]], commands.HybridGroup[Any, P, _T]]:
"""A shortcut decorator that invokes :func:`~redbot.core.commands.hybrid_group` and adds it to
the internal command list via :meth:`add_command`.
Returns
--------
Callable[..., :class:`HybridGroup`]
A decorator that converts the provided method into a Group, adds it to the bot, then returns it.
"""
def decorator(func: CommandCallback[Any, ContextT, P, _T]):
kwargs.setdefault("parent", self)
result = commands.hybrid_group(
name=name, *args, with_app_command=with_app_command, **kwargs
)(func)
self.add_command(result)
return result
return decorator
def clear_permission_rules(self, guild_id: Optional[int], **kwargs) -> None:
"""Clear all permission overrides in a scope.