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

Allow only state objects

This commit is contained in:
coder2020official 2022-05-02 02:08:48 +05:00
parent 825827cb1e
commit 836130a718
6 changed files with 15 additions and 8 deletions

View File

@ -1,5 +1,7 @@
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
from telebot.asyncio_handler_backends import State
class StateMemoryStorage(StateStorageBase): class StateMemoryStorage(StateStorageBase):
def __init__(self) -> None: def __init__(self) -> None:
self.data = {} self.data = {}
@ -8,7 +10,7 @@ class StateMemoryStorage(StateStorageBase):
async def set_state(self, chat_id, user_id, state): async def set_state(self, chat_id, user_id, state):
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if chat_id in self.data: if chat_id in self.data:
if user_id in self.data[chat_id]: if user_id in self.data[chat_id]:

View File

@ -1,7 +1,7 @@
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
import os import os
from telebot.asyncio_handler_backends import State
import pickle import pickle
@ -47,7 +47,7 @@ class StatePickleStorage(StateStorageBase):
file.close() file.close()
async def set_state(self, chat_id, user_id, state): async def set_state(self, chat_id, user_id, state):
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if chat_id in self.data: if chat_id in self.data:
if user_id in self.data[chat_id]: if user_id in self.data[chat_id]:

View File

@ -1,6 +1,8 @@
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
import json import json
from telebot.asyncio_handler_backends import State
redis_installed = True redis_installed = True
try: try:
import aioredis import aioredis
@ -65,7 +67,7 @@ class StateRedisStorage(StateStorageBase):
""" """
response = await self.get_record(chat_id) response = await self.get_record(chat_id)
user_id = str(user_id) user_id = str(user_id)
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if response: if response:
if user_id in response: if user_id in response:

View File

@ -1,5 +1,7 @@
from telebot.storage.base_storage import StateStorageBase, StateContext from telebot.storage.base_storage import StateStorageBase, StateContext
from telebot.handler_backends import State
class StateMemoryStorage(StateStorageBase): class StateMemoryStorage(StateStorageBase):
def __init__(self) -> None: def __init__(self) -> None:
self.data = {} self.data = {}
@ -8,7 +10,7 @@ class StateMemoryStorage(StateStorageBase):
def set_state(self, chat_id, user_id, state): def set_state(self, chat_id, user_id, state):
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if chat_id in self.data: if chat_id in self.data:
if user_id in self.data[chat_id]: if user_id in self.data[chat_id]:

View File

@ -1,6 +1,6 @@
from telebot.storage.base_storage import StateStorageBase, StateContext from telebot.storage.base_storage import StateStorageBase, StateContext
import os import os
from telebot.handler_backends import State
import pickle import pickle
@ -53,7 +53,7 @@ class StatePickleStorage(StateStorageBase):
file.close() file.close()
def set_state(self, chat_id, user_id, state): def set_state(self, chat_id, user_id, state):
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if chat_id in self.data: if chat_id in self.data:
if user_id in self.data[chat_id]: if user_id in self.data[chat_id]:

View File

@ -1,6 +1,7 @@
from pyclbr import Class from pyclbr import Class
from telebot.storage.base_storage import StateStorageBase, StateContext from telebot.storage.base_storage import StateStorageBase, StateContext
import json import json
from telebot.handler_backends import State
redis_installed = True redis_installed = True
try: try:
@ -65,7 +66,7 @@ class StateRedisStorage(StateStorageBase):
""" """
response = self.get_record(chat_id) response = self.get_record(chat_id)
user_id = str(user_id) user_id = str(user_id)
if isinstance(state, object): if isinstance(state, State):
state = state.name state = state.name
if response: if response: