mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 16:15:51 +00:00
Add new FSM strategy CHAT_TOPIC strategy.py (#1344)
* Create 1343.feature.rst * Add new FSM strategy CHAT_TOPIC strategy.py * ADD CHAT_TOPIC tests test_strategy.py * Update 1343.feature.rst * Update strategy.py * add typing user_id: Optional[int] = None, middleware.py * add typing user_id: Optional[int] = None base.py * Update strategy.py * Update strategy.py * Update middleware.py * Update base.py * Update test_strategy.py * Update base.py * Update strategy.py
This commit is contained in:
parent
3b21262d34
commit
d8e7801963
3 changed files with 8 additions and 0 deletions
1
CHANGES/1343.feature.rst
Normal file
1
CHANGES/1343.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
The new FSM strategy CHAT_TOPIC, which sets the state for the entire topic in the chat, also works in private messages and regular groups without topics.
|
||||
|
|
@ -7,6 +7,7 @@ class FSMStrategy(Enum):
|
|||
CHAT = auto()
|
||||
GLOBAL_USER = auto()
|
||||
USER_IN_TOPIC = auto()
|
||||
CHAT_TOPIC = auto()
|
||||
|
||||
|
||||
def apply_strategy(
|
||||
|
|
@ -21,4 +22,7 @@ def apply_strategy(
|
|||
return user_id, user_id, None
|
||||
if strategy == FSMStrategy.USER_IN_TOPIC:
|
||||
return chat_id, user_id, thread_id
|
||||
if strategy == FSMStrategy.CHAT_TOPIC:
|
||||
return chat_id, chat_id, thread_id
|
||||
|
||||
return chat_id, user_id, None
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ class TestStrategy:
|
|||
[FSMStrategy.USER_IN_TOPIC, CHAT, CHAT],
|
||||
[FSMStrategy.USER_IN_TOPIC, PRIVATE, PRIVATE],
|
||||
[FSMStrategy.USER_IN_TOPIC, THREAD, THREAD],
|
||||
[FSMStrategy.CHAT_TOPIC, CHAT, (CHAT_ID, CHAT_ID, None)],
|
||||
[FSMStrategy.CHAT_TOPIC, PRIVATE, PRIVATE],
|
||||
[FSMStrategy.CHAT_TOPIC, THREAD, (CHAT_ID, CHAT_ID, THREAD_ID)],
|
||||
],
|
||||
)
|
||||
def test_strategy(self, strategy, case, expected):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue