From 0a6cc2bd116e55ddc693c031cc3e2bb8539d9b47 Mon Sep 17 00:00:00 2001 From: EvieePy <29671945+EvieePy@users.noreply.github.com> Date: Wed, 5 Feb 2025 01:48:46 +1000 Subject: [PATCH] Add unique_commands to Mixin and fix walk_commands --- twitchio/ext/commands/core.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/twitchio/ext/commands/core.py b/twitchio/ext/commands/core.py index 428f405a..8d1f2828 100644 --- a/twitchio/ext/commands/core.py +++ b/twitchio/ext/commands/core.py @@ -539,9 +539,20 @@ def commands(self) -> dict[str, Command[Component_T, ...] | Group[Any, ...]]: Mixin. This mapping includes aliases as keys. + + .. note:: + + See: :attr:`.unique_commands` for a :class:`set` of commands without duplicates due to aliases. """ return self._commands + @property + def unique_commands(self) -> set[Command[Component_T, ...] | Group[Any, ...]]: + """Property returning a :class:`set` of currently added :class:`~.Command` and :class:`~.Group` associated with this + Mixin. + """ + return set(self._commands.values()) + def get_command(self, name: str, /) -> Command[Component_T, ...] | Group[Any, ...] | None: """Method which returns a previously added :class:`~.Command` or :class:`~.Group`. @@ -792,7 +803,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: def walk_commands(self) -> Generator[Command[Component_T, P] | Group[Component_T, P]]: """A generator which recursively walks through the sub-commands and sub-groups of this group.""" - for command in self._commands.values(): + for command in self.unique_commands: yield command if isinstance(command, Group):