1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Badiboy
ac12d0fc02
Merge pull request #1467 from coder2020official/master
CallbackQuery usage with states.
2022-03-02 11:56:13 +03:00
_run
995e28e9d8
Remove unnecessary thing 2022-02-26 22:50:55 +05:00
coder2020official
1bfc082d46 Update documentation 2022-02-26 22:48:03 +05:00
coder2020official
1a35bbb127 Merge branch 'master' of https://github.com/coder2020official/pyTelegramBotAPI 2022-02-26 22:43:05 +05:00
coder2020official
e585c77830 Fix 2022-02-26 22:43:03 +05:00
4 changed files with 35 additions and 5 deletions

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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: