From bafadde2d46c9ac917deedffc874add3223a3732 Mon Sep 17 00:00:00 2001 From: cop <32881179+cop-discord@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:22:44 -0700 Subject: [PATCH] yes --- discord/client.py | 2 +- discord/ext/commands/hybrid.py | 34 +++++++++++++++++++++++++--------- discord/utils.py | 2 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/discord/client.py b/discord/client.py index c387edc..27c6dbc 100644 --- a/discord/client.py +++ b/discord/client.py @@ -903,7 +903,7 @@ async def runner(): await self.start(token, reconnect=reconnect) if log_handler is not None: - utils.setup_loguru( + utils.setup_logging( handler=log_handler, formatter=log_formatter, level=log_level, diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 41d9ffd..1c00d76 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -297,14 +297,20 @@ def replace_parameters( class HybridAppCommand(discord.app_commands.Command[CogT, P, T]): - def __init__(self, wrapped: Union[HybridCommand[CogT, ..., T], HybridGroup[CogT, ..., T]]) -> None: + __commands_is_hybrid_app_command__: ClassVar[bool] = True + + def __init__( + self, + wrapped: Union[HybridCommand[CogT, ..., T], HybridGroup[CogT, ..., T]], + name: Optional[Union[str, app_commands.locale_str]] = None, + ) -> None: signature = inspect.signature(wrapped.callback) params = replace_parameters(wrapped.params, wrapped.callback, signature) wrapped.callback.__signature__ = signature.replace(parameters=params) nsfw = getattr(wrapped.callback, '__discord_app_commands_is_nsfw__', False) try: super().__init__( - name=wrapped._locale_name or wrapped.name, + name=name or wrapped._locale_name or wrapped.name, callback=wrapped.callback, # type: ignore # Signature doesn't match but we're overriding the invoke description=wrapped._locale_description or wrapped.description or wrapped.short_doc or '…', nsfw=nsfw, @@ -398,7 +404,7 @@ async def _check_can_run(self, interaction: discord.Interaction) -> bool: if self.binding is not None: try: # Type checker does not like runtime attribute retrieval - check: AppCommandCheck = self.binding.interaction_check # type: ignore + check: AppCommandCheck = self.binding.interaction_check except AttributeError: pass else: @@ -594,6 +600,8 @@ class HybridGroup(Group[CogT, P, T]): application command groups cannot be invoked, this creates a subcommand within the group that can be invoked with the given group callback. If ``None`` then no fallback command is given. Defaults to ``None``. + fallback_locale: Optional[:class:`~discord.app_commands.locale_str`] + The fallback command name's locale string, if available. """ __commands_is_hybrid__: ClassVar[bool] = True @@ -603,7 +611,7 @@ def __init__( *args: Any, name: Union[str, app_commands.locale_str] = MISSING, description: Union[str, app_commands.locale_str] = MISSING, - fallback: Optional[str] = None, + fallback: Optional[Union[str, app_commands.locale_str]] = None, **attrs: Any, ) -> None: name, name_locale = (name.message, name) if isinstance(name, app_commands.locale_str) else (name, None) @@ -631,7 +639,12 @@ def __init__( # However, Python does not have conditional typing so it's very hard to # make this type depend on the with_app_command bool without a lot of needless repetition self.app_command: app_commands.Group = MISSING + + fallback, fallback_locale = ( + (fallback.message, fallback) if isinstance(fallback, app_commands.locale_str) else (fallback, None) + ) self.fallback: Optional[str] = fallback + self.fallback_locale: Optional[app_commands.locale_str] = fallback_locale if self.with_app_command: guild_ids = attrs.pop('guild_ids', None) or getattr( @@ -640,6 +653,8 @@ def __init__( guild_only = getattr(self.callback, '__discord_app_commands_guild_only__', False) default_permissions = getattr(self.callback, '__discord_app_commands_default_permissions__', None) nsfw = getattr(self.callback, '__discord_app_commands_is_nsfw__', False) + contexts = getattr(self.callback, '__discord_app_commands_contexts__', MISSING) + installs = getattr(self.callback, '__discord_app_commands_installation_types__', MISSING) self.app_command = app_commands.Group( name=self._locale_name or self.name, description=self._locale_description or self.description or self.short_doc or '…', @@ -647,6 +662,8 @@ def __init__( guild_only=guild_only, default_permissions=default_permissions, nsfw=nsfw, + allowed_installs=installs, + allowed_contexts=contexts, ) # This prevents the group from re-adding the command at __init__ @@ -654,8 +671,7 @@ def __init__( self.app_command.module = self.module if fallback is not None: - command = HybridAppCommand(self) - command.name = fallback + command = HybridAppCommand(self, name=fallback_locale or fallback) self.app_command.add_command(command) @property @@ -890,7 +906,7 @@ def hybrid_command( def decorator(func: CommandCallback[CogT, ContextT, P, T]) -> HybridCommand[CogT, P, T]: if isinstance(func, Command): raise TypeError('Callback is already a command.') - return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) # type: ignore # ??? + return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) return decorator @@ -920,9 +936,9 @@ def hybrid_group( If the function is not a coroutine or is already a command. """ - def decorator(func: CommandCallback[CogT, ContextT, P, T]): + def decorator(func: CommandCallback[CogT, ContextT, P, T]) -> HybridGroup[CogT, P, T]: if isinstance(func, Command): raise TypeError('Callback is already a command.') return HybridGroup(func, name=name, with_app_command=with_app_command, **attrs) - return decorator # type: ignore + return decorator \ No newline at end of file diff --git a/discord/utils.py b/discord/utils.py index 85e2bd0..eb2d1d2 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -101,7 +101,7 @@ 'as_chunks', 'format_dt', 'MISSING', - 'setup_loguru', + 'setup_logging', ) DISCORD_EPOCH = 1420070400000