From e585c77830268328f571c8feab8ede15b1b411ee Mon Sep 17 00:00:00 2001 From: coder2020official Date: Sat, 26 Feb 2022 22:43:03 +0500 Subject: [PATCH 1/3] Fix --- telebot/asyncio_filters.py | 21 +++++++++++++++++---- telebot/custom_filters.py | 26 ++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/telebot/asyncio_filters.py b/telebot/asyncio_filters.py index 6c1fc4b..1b39761 100644 --- a/telebot/asyncio_filters.py +++ b/telebot/asyncio_filters.py @@ -1,5 +1,6 @@ from abc import ABC from typing import Optional, Union +from telebot.asyncio_handler_backends import State from telebot import types @@ -277,17 +278,29 @@ 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: - if isclass(i): i = i.name + if isinstance(i, State): i = i.name new_text.append(i) text = new_text - elif isinstance(text, object): + elif isinstance(text, State): 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: @@ -295,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: diff --git a/telebot/custom_filters.py b/telebot/custom_filters.py index 0305673..8442be4 100644 --- a/telebot/custom_filters.py +++ b/telebot/custom_filters.py @@ -1,9 +1,12 @@ from abc import ABC from typing import Optional, Union +from telebot.handler_backends import State from telebot import types + + class SimpleCustomFilter(ABC): """ Simple Custom Filter base class. @@ -280,17 +283,32 @@ 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 = [] for i in text: - if isclass(i): i = i.name + if isinstance(i, State): i = i.name new_text.append(i) text = new_text - elif isinstance(text, object): + 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: @@ -298,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: From 1bfc082d46a0cf44af16df3ba1c17d5283ce54b9 Mon Sep 17 00:00:00 2001 From: coder2020official Date: Sat, 26 Feb 2022 22:48:03 +0500 Subject: [PATCH 2/3] Update documentation --- docs/source/install.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/install.rst b/docs/source/install.rst index f195a43..f2589c9 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -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: From 995e28e9d88a180373c89eb67218468adec7cabb Mon Sep 17 00:00:00 2001 From: _run Date: Sat, 26 Feb 2022 22:50:55 +0500 Subject: [PATCH 3/3] Remove unnecessary thing --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 61015af..e2415f0 100644 --- a/README.md +++ b/README.md @@ -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