Skip to content

Commit 7a7d2e7

Browse files
committed
Fix command groups requesting subcommand locales as options
1 parent ed500f4 commit 7a7d2e7

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

arc/command/slash.py

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from arc.internal.options import resolve_options
1414
from arc.internal.sigparse import parse_command_signature
1515
from arc.internal.types import ClientT, CommandCallbackT, HookT, PostHookT, ResponseBuilderT, SlashCommandLike
16-
from arc.locale import CommandLocaleRequest, LocaleResponse
16+
from arc.locale import CommandLocaleRequest
1717

1818
if t.TYPE_CHECKING:
1919
from asyncio.futures import Future
@@ -196,8 +196,6 @@ def _request_command_locale(self) -> None:
196196
request = CommandLocaleRequest(self, locale, self.name)
197197
resp = self._client._command_locale_provider(request)
198198

199-
assert isinstance(resp, LocaleResponse)
200-
201199
if resp.name is not None and resp.description is not None:
202200
name_locales[locale] = resp.name
203201
desc_locales[locale] = resp.description
@@ -387,6 +385,9 @@ def _request_command_locale(self) -> None:
387385
if self.name_localizations or self.description_localizations or self._client is None:
388386
return
389387

388+
for sub in self.children.values():
389+
sub._request_command_locale(self._client)
390+
390391
if not self._client._provided_locales or not self._client._command_locale_provider:
391392
return
392393

@@ -404,9 +405,6 @@ def _request_command_locale(self) -> None:
404405
self.name_localizations: t.Mapping[hikari.Locale, str] = name_locales
405406
self.description_localizations: t.Mapping[hikari.Locale, str] = desc_locales
406407

407-
for sub in self.children.values():
408-
sub._request_option_locale(self._client, self)
409-
410408
@t.overload
411409
def include(self) -> t.Callable[[SlashSubCommand[ClientT]], SlashSubCommand[ClientT]]: ...
412410

@@ -551,6 +549,30 @@ async def _handle_exception(self, ctx: Context[ClientT], exc: Exception) -> None
551549
assert self._parent is not None
552550
await self._parent._handle_exception(ctx, exc)
553551

552+
def _request_command_locale(self, client: Client[t.Any]) -> None:
553+
if not client._provided_locales or not client._command_locale_provider:
554+
return
555+
556+
for sub in self.children.values():
557+
sub._request_command_locale(client)
558+
559+
if self.name_localizations or self.description_localizations:
560+
return
561+
562+
name_locales = {}
563+
desc_locales = {}
564+
565+
for locale in client._provided_locales:
566+
request = CommandLocaleRequest(self, locale, self.name)
567+
resp = client._command_locale_provider(request)
568+
569+
if resp.name is not None and resp.description is not None:
570+
name_locales[locale] = resp.name
571+
desc_locales[locale] = resp.description
572+
573+
self.name_localizations: t.Mapping[hikari.Locale, str] = name_locales
574+
self.description_localizations: t.Mapping[hikari.Locale, str] = desc_locales
575+
554576
def _request_option_locale(self, client: Client[t.Any], command: CommandProto) -> None:
555577
super()._request_option_locale(client, command)
556578

@@ -705,6 +727,30 @@ async def _handle_exception(self, ctx: Context[ClientT], exc: Exception) -> None
705727
assert self._parent is not None
706728
await self._parent._handle_exception(ctx, e)
707729

730+
def _request_command_locale(self, client: Client[t.Any]) -> None:
731+
if not client._provided_locales or not client._command_locale_provider:
732+
return
733+
734+
for option in self.options.values():
735+
option._request_option_locale(client, self)
736+
737+
if self.name_localizations or self.description_localizations:
738+
return
739+
740+
name_locales = {}
741+
desc_locales = {}
742+
743+
for locale in client._provided_locales:
744+
request = CommandLocaleRequest(self, locale, self.name)
745+
resp = client._command_locale_provider(request)
746+
747+
if resp.name is not None and resp.description is not None:
748+
name_locales[locale] = resp.name
749+
desc_locales[locale] = resp.description
750+
751+
self.name_localizations: t.Mapping[hikari.Locale, str] = name_locales
752+
self.description_localizations: t.Mapping[hikari.Locale, str] = desc_locales
753+
708754
def _request_option_locale(self, client: Client[t.Any], command: CommandProto) -> None:
709755
super()._request_option_locale(client, command)
710756

0 commit comments

Comments
 (0)