Skip to content

Commit

Permalink
fix: properly parse aliases for base commands (#1728)
Browse files Browse the repository at this point in the history
* fix: properly parse aliases for base commands

* fix: don't add random aliases to base commands
  • Loading branch information
AstreaTSS authored Aug 26, 2024
1 parent d5dfe8e commit e566d1e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,9 @@ def add_command(self, func: Callable) -> None:
elif not isinstance(func, BaseCommand):
raise TypeError("Invalid command type")

for hook in self._add_command_hook:
hook(func)

if not func.callback:
# for group = SlashCommand(...) usage
return
Expand All @@ -1499,9 +1502,6 @@ def add_command(self, func: Callable) -> None:
else:
self.logger.debug(f"Added callback: {func.callback.__name__}")

for hook in self._add_command_hook:
hook(func)

self.dispatch(CallbackAdded(callback=func, extension=func.extension if hasattr(func, "extension") else None))

def _gather_callbacks(self) -> None:
Expand Down
25 changes: 23 additions & 2 deletions interactions/ext/hybrid_commands/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ def _add_hybrid_command(self, callback: Callable):
return

cmd = callback

if not cmd.callback or cmd._dummy_base:
if cmd.group_name:
if not (group := self.client.prefixed.get_command(f"{cmd.name} {cmd.group_name}")):
group = base_subcommand_generator(
str(cmd.group_name),
list(_values_wrapper(cmd.group_name.to_locale_dict())) + cmd.aliases,
str(cmd.group_name),
group=True,
)
self.client.prefixed.commands[str(cmd.name)].add_command(group)
elif not (base := self.client.prefixed.commands.get(str(cmd.name))):
base = base_subcommand_generator(
str(cmd.name),
list(_values_wrapper(cmd.name.to_locale_dict())) + cmd.aliases,
str(cmd.name),
group=False,
)
self.client.prefixed.add_command(base)
return

prefixed_transform = slash_to_prefixed(cmd)

if self.use_slash_command_msg:
Expand All @@ -91,7 +112,7 @@ def _add_hybrid_command(self, callback: Callable):
if not (base := self.client.prefixed.commands.get(str(cmd.name))):
base = base_subcommand_generator(
str(cmd.name),
list(_values_wrapper(cmd.name.to_locale_dict())) + cmd.aliases,
list(_values_wrapper(cmd.name.to_locale_dict())),
str(cmd.name),
group=False,
)
Expand All @@ -102,7 +123,7 @@ def _add_hybrid_command(self, callback: Callable):
if not (group := base.subcommands.get(str(cmd.group_name))):
group = base_subcommand_generator(
str(cmd.group_name),
list(_values_wrapper(cmd.group_name.to_locale_dict())) + cmd.aliases,
list(_values_wrapper(cmd.group_name.to_locale_dict())),
str(cmd.group_name),
group=True,
)
Expand Down

0 comments on commit e566d1e

Please sign in to comment.