1
0
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:
Badiboy
2022-03-02 11:56:13 +03:00
committed by GitHub
4 changed files with 35 additions and 5 deletions

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: