mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1964 from Cub11k/add_state_list
Add state_list to StatesGroup
This commit is contained in:
commit
370f0370c7
@ -74,12 +74,18 @@ class StatesGroup:
|
|||||||
my_state = State() # returns my_state:State string.
|
my_state = State() # returns my_state:State string.
|
||||||
"""
|
"""
|
||||||
def __init_subclass__(cls) -> None:
|
def __init_subclass__(cls) -> None:
|
||||||
|
state_list = []
|
||||||
for name, value in cls.__dict__.items():
|
for name, value in cls.__dict__.items():
|
||||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||||
# change value of that variable
|
# change value of that variable
|
||||||
value.name = ':'.join((cls.__name__, name))
|
value.name = ':'.join((cls.__name__, name))
|
||||||
value.group = cls
|
value.group = cls
|
||||||
|
state_list.append(value)
|
||||||
|
cls._state_list = state_list
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_list(self):
|
||||||
|
return self._state_list
|
||||||
|
|
||||||
|
|
||||||
class SkipHandler:
|
class SkipHandler:
|
||||||
|
@ -185,13 +185,20 @@ class StatesGroup:
|
|||||||
my_state = State() # returns my_state:State string.
|
my_state = State() # returns my_state:State string.
|
||||||
"""
|
"""
|
||||||
def __init_subclass__(cls) -> None:
|
def __init_subclass__(cls) -> None:
|
||||||
|
state_list = []
|
||||||
for name, value in cls.__dict__.items():
|
for name, value in cls.__dict__.items():
|
||||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||||
# change value of that variable
|
# change value of that variable
|
||||||
value.name = ':'.join((cls.__name__, name))
|
value.name = ':'.join((cls.__name__, name))
|
||||||
value.group = cls
|
value.group = cls
|
||||||
|
state_list.append(value)
|
||||||
|
cls._state_list = state_list
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_list(self):
|
||||||
|
return self._state_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseMiddleware:
|
class BaseMiddleware:
|
||||||
"""
|
"""
|
||||||
Base class for middleware.
|
Base class for middleware.
|
||||||
|
Loading…
Reference in New Issue
Block a user