mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1467 from coder2020official/master
CallbackQuery usage with states.
This commit is contained in:
commit
ac12d0fc02
@ -769,7 +769,6 @@ See more examples in our [examples](https://github.com/eternnoir/pyTelegramBotAP
|
||||
Telegram Bot API support new type Chat for message.chat.
|
||||
|
||||
- Check the ```type``` attribute in ```Chat``` object:
|
||||
-
|
||||
```python
|
||||
if message.chat.type == "private":
|
||||
# private chat message
|
||||
|
@ -28,8 +28,10 @@ By cloning repository
|
||||
Directly using pip
|
||||
------------------
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install git+https://github.com/eternnoir/pyTelegramBotAPI.git
|
||||
|
||||
|
||||
It is generally recommended to use the first option.
|
||||
|
||||
While the API is production-ready, it is still under development and it has regular updates, do not forget to update it regularly by calling:
|
||||
|
@ -278,6 +278,18 @@ class StateFilter(AdvancedCustomFilter):
|
||||
async def check(self, message, text):
|
||||
if text == '*': return True
|
||||
|
||||
# needs to work with callbackquery
|
||||
if isinstance(message, types.Message):
|
||||
chat_id = message.chat.id
|
||||
user_id = message.from_user.id
|
||||
|
||||
if isinstance(message, types.CallbackQuery):
|
||||
|
||||
chat_id = message.message.chat.id
|
||||
user_id = message.from_user.id
|
||||
message = message.message
|
||||
|
||||
|
||||
if isinstance(text, list):
|
||||
new_text = []
|
||||
for i in text:
|
||||
@ -288,7 +300,7 @@ class StateFilter(AdvancedCustomFilter):
|
||||
text = text.name
|
||||
|
||||
if message.chat.type == 'group':
|
||||
group_state = await self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
||||
group_state = await self.bot.current_states.get_state(user_id, chat_id)
|
||||
if group_state == text:
|
||||
return True
|
||||
elif group_state in text and type(text) is list:
|
||||
@ -296,7 +308,7 @@ class StateFilter(AdvancedCustomFilter):
|
||||
|
||||
|
||||
else:
|
||||
user_state = await self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
||||
user_state = await self.bot.current_states.get_state(user_id, chat_id)
|
||||
if user_state == text:
|
||||
return True
|
||||
elif type(text) is list and user_state in text:
|
||||
|
@ -5,6 +5,8 @@ from telebot.handler_backends import State
|
||||
from telebot import types
|
||||
|
||||
|
||||
|
||||
|
||||
class SimpleCustomFilter(ABC):
|
||||
"""
|
||||
Simple Custom Filter base class.
|
||||
@ -281,6 +283,20 @@ class StateFilter(AdvancedCustomFilter):
|
||||
|
||||
def check(self, message, text):
|
||||
if text == '*': return True
|
||||
|
||||
# needs to work with callbackquery
|
||||
if isinstance(message, types.Message):
|
||||
chat_id = message.chat.id
|
||||
user_id = message.from_user.id
|
||||
|
||||
if isinstance(message, types.CallbackQuery):
|
||||
|
||||
chat_id = message.message.chat.id
|
||||
user_id = message.from_user.id
|
||||
message = message.message
|
||||
|
||||
|
||||
|
||||
|
||||
if isinstance(text, list):
|
||||
new_text = []
|
||||
@ -290,8 +306,9 @@ class StateFilter(AdvancedCustomFilter):
|
||||
text = new_text
|
||||
elif isinstance(text, State):
|
||||
text = text.name
|
||||
|
||||
if message.chat.type == 'group':
|
||||
group_state = self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
||||
group_state = self.bot.current_states.get_state(user_id, chat_id)
|
||||
if group_state == text:
|
||||
return True
|
||||
elif group_state in text and type(text) is list:
|
||||
@ -299,7 +316,7 @@ class StateFilter(AdvancedCustomFilter):
|
||||
|
||||
|
||||
else:
|
||||
user_state = self.bot.current_states.get_state(message.chat.id, message.from_user.id)
|
||||
user_state = self.bot.current_states.get_state(user_id, chat_id)
|
||||
if user_state == text:
|
||||
return True
|
||||
elif type(text) is list and user_state in text:
|
||||
|
Loading…
Reference in New Issue
Block a user