Skip to content

Commit

Permalink
Add unique_commands to Mixin and fix walk_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Feb 4, 2025
1 parent e9a1712 commit 0a6cc2b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion twitchio/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0a6cc2b

Please sign in to comment.