mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-13 18:43:53 +00:00
Allow to change states-group name by __group_name__
This commit is contained in:
parent
ac50db075b
commit
d8909ffe35
1 changed files with 6 additions and 1 deletions
|
|
@ -7,7 +7,10 @@ class State:
|
||||||
|
|
||||||
def __set_name__(self, owner, name):
|
def __set_name__(self, owner, name):
|
||||||
if self.state is None:
|
if self.state is None:
|
||||||
self.state = owner.__name__ + ':' + name
|
group_name = getattr(owner, '__group_name__')
|
||||||
|
if group_name is None:
|
||||||
|
group_name = owner.__name__
|
||||||
|
self.state = f"{group_name}:{name}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"<State '{self.state}>'"
|
return f"<State '{self.state}>'"
|
||||||
|
|
@ -42,6 +45,8 @@ class MetaStatesGroup(type):
|
||||||
|
|
||||||
|
|
||||||
class StatesGroup(metaclass=MetaStatesGroup):
|
class StatesGroup(metaclass=MetaStatesGroup):
|
||||||
|
__group_name__ = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def next(cls) -> str:
|
async def next(cls) -> str:
|
||||||
state = Dispatcher.current().current_state()
|
state = Dispatcher.current().current_state()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue