mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge pull request #1529 from coder2020official/state-fixes
Allow only state objects
This commit is contained in:
commit
2d8c2312e3
@ -8,7 +8,7 @@ class StateMemoryStorage(StateStorageBase):
|
||||
|
||||
|
||||
async def set_state(self, chat_id, user_id, state):
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
if chat_id in self.data:
|
||||
if user_id in self.data[chat_id]:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
|
||||
import os
|
||||
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
@ -47,7 +46,7 @@ class StatePickleStorage(StateStorageBase):
|
||||
file.close()
|
||||
|
||||
async def set_state(self, chat_id, user_id, state):
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
if chat_id in self.data:
|
||||
if user_id in self.data[chat_id]:
|
||||
|
@ -1,6 +1,7 @@
|
||||
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
|
||||
import json
|
||||
|
||||
|
||||
redis_installed = True
|
||||
try:
|
||||
import aioredis
|
||||
@ -65,7 +66,7 @@ class StateRedisStorage(StateStorageBase):
|
||||
"""
|
||||
response = await self.get_record(chat_id)
|
||||
user_id = str(user_id)
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
if response:
|
||||
if user_id in response:
|
||||
|
@ -1,5 +1,6 @@
|
||||
from telebot.storage.base_storage import StateStorageBase, StateContext
|
||||
|
||||
|
||||
class StateMemoryStorage(StateStorageBase):
|
||||
def __init__(self) -> None:
|
||||
self.data = {}
|
||||
@ -8,7 +9,7 @@ class StateMemoryStorage(StateStorageBase):
|
||||
|
||||
|
||||
def set_state(self, chat_id, user_id, state):
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
if chat_id in self.data:
|
||||
if user_id in self.data[chat_id]:
|
||||
|
@ -1,7 +1,6 @@
|
||||
from telebot.storage.base_storage import StateStorageBase, StateContext
|
||||
import os
|
||||
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
@ -53,7 +52,7 @@ class StatePickleStorage(StateStorageBase):
|
||||
file.close()
|
||||
|
||||
def set_state(self, chat_id, user_id, state):
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
if chat_id in self.data:
|
||||
if user_id in self.data[chat_id]:
|
||||
|
@ -65,7 +65,7 @@ class StateRedisStorage(StateStorageBase):
|
||||
"""
|
||||
response = self.get_record(chat_id)
|
||||
user_id = str(user_id)
|
||||
if isinstance(state, object):
|
||||
if hasattr(state, 'name'):
|
||||
state = state.name
|
||||
|
||||
if response:
|
||||
|
Loading…
Reference in New Issue
Block a user