Skip to content

Commit 3267caf

Browse files
committed
Document get_command and commands mapping.
1 parent 89ac77c commit 3267caf

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

twitchio/ext/commands/core.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ class Mixin(Generic[Component_T]):
524524
def __init__(self, *args: Any, **kwargs: Any) -> None:
525525
case_: bool = kwargs.pop("case_insensitive", False)
526526
self._case_insensitive: bool = case_
527-
self._commands: dict[str, Command[Component_T, ...]] = {} if not case_ else _CaseInsensitiveDict()
527+
self._commands: dict[str, Command[Component_T, ...] | Group[Any, ...]] = {} if not case_ else _CaseInsensitiveDict()
528528

529529
super().__init__(*args, **kwargs)
530530

@@ -533,6 +533,35 @@ def case_insensitive(self) -> bool:
533533
"""Property returning a bool indicating whether this Mixin is using case insensitive commands."""
534534
return self._case_insensitive
535535

536+
@property
537+
def commands(self) -> dict[str, Command[Component_T, ...] | Group[Any, ...]]:
538+
"""Property returning the mapping of currently added :class:`~.Command` and :class:`~.Group` associated with this
539+
Mixin.
540+
541+
This mapping includes aliases as keys.
542+
"""
543+
return self._commands
544+
545+
def get_command(self, name: str, /) -> Command[Component_T, ...] | Group[Any, ...] | None:
546+
"""Method which returns a previously added :class:`~.Command` or :class:`~.Group`.
547+
548+
If a :class:`~.Command` or :class:`~.Group` can not be found, has been removed or has not been added,
549+
this method will return ``None``.
550+
551+
Parameters
552+
----------
553+
name: str
554+
The name or alias of the :class:`~.Command` or :class:`~.Group` to retrieve.
555+
556+
Returns
557+
-------
558+
:class:`~.Command` | :class:`~.Group`
559+
The command or group command with the provided name or alias associated with this Mixin.
560+
None
561+
A command or group with the provided name or alias could not be found.
562+
"""
563+
return self._commands.get(name, None)
564+
536565
def add_command(self, command: Command[Component_T, ...], /) -> None:
537566
"""Add a :class:`~.commands.Command` object to the mixin.
538567

0 commit comments

Comments
 (0)