mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 09:55:21 +00:00
Implement root group getter.
This commit is contained in:
parent
10538b3199
commit
21c45193da
1 changed files with 14 additions and 0 deletions
|
|
@ -14,6 +14,15 @@ class State:
|
|||
self._group_name = group_name
|
||||
self._group = None
|
||||
|
||||
@property
|
||||
def group(self):
|
||||
if not self._group:
|
||||
raise RuntimeError('This state is not in any group.')
|
||||
return self._group
|
||||
|
||||
def get_root(self):
|
||||
return self.group.get_root()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
if self._state is None:
|
||||
|
|
@ -113,6 +122,11 @@ class MetaStatesGroup(type):
|
|||
def states_names(cls) -> tuple:
|
||||
return tuple(state.state for state in cls.states)
|
||||
|
||||
def get_root(cls):
|
||||
if cls._parent is None:
|
||||
return cls
|
||||
return cls._parent.get_root()
|
||||
|
||||
def __contains__(cls, item):
|
||||
if isinstance(item, str):
|
||||
return item in cls.all_states_names
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue