Skip to content

Commit

Permalink
Merge pull request #1529 from coder2020official/state-fixes
Browse files Browse the repository at this point in the history
Allow only state objects
  • Loading branch information
Badiboy authored May 3, 2022
2 parents 59cd1a0 + f9cd0d7 commit 2d8c231
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion telebot/asyncio_storage/memory_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self) -> None:


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]:
Expand Down
3 changes: 1 addition & 2 deletions telebot/asyncio_storage/pickle_storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
import os


import pickle


Expand Down Expand Up @@ -47,7 +46,7 @@ def update_data(self):
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]:
Expand Down
3 changes: 2 additions & 1 deletion telebot/asyncio_storage/redis_storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from telebot.asyncio_storage.base_storage import StateStorageBase, StateContext
import json


redis_installed = True
try:
import aioredis
Expand Down Expand Up @@ -65,7 +66,7 @@ async def set_state(self, chat_id, user_id, state):
"""
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:
Expand Down
3 changes: 2 additions & 1 deletion telebot/storage/memory_storage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from telebot.storage.base_storage import StateStorageBase, StateContext


class StateMemoryStorage(StateStorageBase):
def __init__(self) -> None:
self.data = {}
Expand All @@ -8,7 +9,7 @@ def __init__(self) -> None:


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]:
Expand Down
3 changes: 1 addition & 2 deletions telebot/storage/pickle_storage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from telebot.storage.base_storage import StateStorageBase, StateContext
import os


import pickle


Expand Down Expand Up @@ -53,7 +52,7 @@ def update_data(self):
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]:
Expand Down
2 changes: 1 addition & 1 deletion telebot/storage/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def set_state(self, chat_id, user_id, state):
"""
response = self.get_record(chat_id)
user_id = str(user_id)
if isinstance(state, object):
if hasattr(state, 'name'):
state = state.name

if response:
Expand Down

0 comments on commit 2d8c231

Please sign in to comment.