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:
ZeroN 2023-10-22 02:41:13 +05:00 committed by GitHub
parent 3b21262d34
commit d8e7801963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

1
CHANGES/1343.feature.rst Normal file
View 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.

View file

@ -7,6 +7,7 @@ class FSMStrategy(Enum):
CHAT = auto() CHAT = auto()
GLOBAL_USER = auto() GLOBAL_USER = auto()
USER_IN_TOPIC = auto() USER_IN_TOPIC = auto()
CHAT_TOPIC = auto()
def apply_strategy( def apply_strategy(
@ -21,4 +22,7 @@ def apply_strategy(
return user_id, user_id, None return user_id, user_id, None
if strategy == FSMStrategy.USER_IN_TOPIC: if strategy == FSMStrategy.USER_IN_TOPIC:
return chat_id, user_id, thread_id 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 return chat_id, user_id, None

View file

@ -27,6 +27,9 @@ class TestStrategy:
[FSMStrategy.USER_IN_TOPIC, CHAT, CHAT], [FSMStrategy.USER_IN_TOPIC, CHAT, CHAT],
[FSMStrategy.USER_IN_TOPIC, PRIVATE, PRIVATE], [FSMStrategy.USER_IN_TOPIC, PRIVATE, PRIVATE],
[FSMStrategy.USER_IN_TOPIC, THREAD, THREAD], [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): def test_strategy(self, strategy, case, expected):