diff --git a/telebot/asyncio_filters.py b/telebot/asyncio_filters.py index 5b193fd..417b110 100644 --- a/telebot/asyncio_filters.py +++ b/telebot/asyncio_filters.py @@ -160,6 +160,13 @@ class StateFilter(AdvancedCustomFilter): async def check(self, message, text): if text == '*': return True + + if isinstance(text, list): + new_text = [i.name for i in text] + text = new_text + elif isinstance(text, object): + text = text.name + if message.chat.type == 'group': group_state = await self.bot.current_states.get_state(message.chat.id, message.from_user.id) if group_state == text: diff --git a/telebot/asyncio_storage/memory_storage.py b/telebot/asyncio_storage/memory_storage.py index ab9c486..58a6e35 100644 --- a/telebot/asyncio_storage/memory_storage.py +++ b/telebot/asyncio_storage/memory_storage.py @@ -8,6 +8,8 @@ class StateMemoryStorage(StateStorageBase): async def set_state(self, chat_id, user_id, state): + if isinstance(state, object): + state = state.name if chat_id in self.data: if user_id in self.data[chat_id]: self.data[chat_id][user_id]['state'] = state diff --git a/telebot/asyncio_storage/pickle_storage.py b/telebot/asyncio_storage/pickle_storage.py index 81ef46c..dd6419e 100644 --- a/telebot/asyncio_storage/pickle_storage.py +++ b/telebot/asyncio_storage/pickle_storage.py @@ -47,6 +47,8 @@ class StatePickleStorage(StateStorageBase): file.close() async def set_state(self, chat_id, user_id, state): + if isinstance(state, object): + state = state.name if chat_id in self.data: if user_id in self.data[chat_id]: self.data[chat_id][user_id]['state'] = state diff --git a/telebot/asyncio_storage/redis_storage.py b/telebot/asyncio_storage/redis_storage.py index 655fb9a..f2a2606 100644 --- a/telebot/asyncio_storage/redis_storage.py +++ b/telebot/asyncio_storage/redis_storage.py @@ -65,6 +65,8 @@ class StateRedisStorage(StateStorageBase): """ response = await self.get_record(chat_id) user_id = str(user_id) + if isinstance(state, object): + state = state.name if response: if user_id in response: response[user_id]['state'] = state diff --git a/telebot/custom_filters.py b/telebot/custom_filters.py index 147596c..d95ecd3 100644 --- a/telebot/custom_filters.py +++ b/telebot/custom_filters.py @@ -1,5 +1,4 @@ from abc import ABC - class SimpleCustomFilter(ABC): """ Simple Custom Filter base class. @@ -159,6 +158,12 @@ class StateFilter(AdvancedCustomFilter): def check(self, message, text): if text == '*': return True + + if isinstance(text, list): + new_text = [i.name for i in text] + text = new_text + elif isinstance(text, object): + text = text.name if message.chat.type == 'group': group_state = self.bot.current_states.get_state(message.chat.id, message.from_user.id) if group_state == text: diff --git a/telebot/handler_backends.py b/telebot/handler_backends.py index 0b2bed7..d88457b 100644 --- a/telebot/handler_backends.py +++ b/telebot/handler_backends.py @@ -154,6 +154,7 @@ class State: self.name = None def __str__(self) -> str: return self.name + class StatesGroup: diff --git a/telebot/storage/memory_storage.py b/telebot/storage/memory_storage.py index 3540ac5..45d4da3 100644 --- a/telebot/storage/memory_storage.py +++ b/telebot/storage/memory_storage.py @@ -8,6 +8,8 @@ class StateMemoryStorage(StateStorageBase): def set_state(self, chat_id, user_id, state): + if isinstance(state, object): + state = state.name if chat_id in self.data: if user_id in self.data[chat_id]: self.data[chat_id][user_id]['state'] = state @@ -31,6 +33,7 @@ class StateMemoryStorage(StateStorageBase): def get_state(self, chat_id, user_id): + if self.data.get(chat_id): if self.data[chat_id].get(user_id): return self.data[chat_id][user_id]['state'] diff --git a/telebot/storage/pickle_storage.py b/telebot/storage/pickle_storage.py index 90f2adb..a273690 100644 --- a/telebot/storage/pickle_storage.py +++ b/telebot/storage/pickle_storage.py @@ -53,6 +53,8 @@ class StatePickleStorage(StateStorageBase): file.close() def set_state(self, chat_id, user_id, state): + if isinstance(state, object): + state = state.name if chat_id in self.data: if user_id in self.data[chat_id]: self.data[chat_id][user_id]['state'] = state diff --git a/telebot/storage/redis_storage.py b/telebot/storage/redis_storage.py index a8ba2c5..ff21b6e 100644 --- a/telebot/storage/redis_storage.py +++ b/telebot/storage/redis_storage.py @@ -1,3 +1,4 @@ +from pyclbr import Class from telebot.storage.base_storage import StateStorageBase, StateContext import json @@ -64,6 +65,9 @@ class StateRedisStorage(StateStorageBase): """ response = self.get_record(chat_id) user_id = str(user_id) + if isinstance(state, object): + state = state.name + if response: if user_id in response: response[user_id]['state'] = state