requested changes: get current() can return None

add check this case
This commit is contained in:
darksidecat 2021-03-11 11:03:28 +02:00
parent 491e344edf
commit 5d38a9228b

View file

@ -1084,8 +1084,11 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
if rate is None:
rate = self.throttling_rate_limit
if user_id is None and chat_id is None:
user_id = types.User.get_current().id
chat_id = types.Chat.get_current().id
chat_obj = types.Chat.get_current()
chat_id = chat_obj.id if chat_obj else None
user_obj = types.User.get_current()
user_id = user_obj.id if user_obj else None
# Detect current time
now = time.time()
@ -1136,8 +1139,11 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
raise RuntimeError('This storage does not provide Leaky Bucket')
if user_id is None and chat_id is None:
user_id = types.User.get_current().id
chat_id = types.Chat.get_current().id
chat_obj = types.Chat.get_current()
chat_id = chat_obj.id if chat_obj else None
user_obj = types.User.get_current()
user_id = user_obj.id if user_obj else None
bucket = await self.storage.get_bucket(chat=chat_id, user=user_id)
data = bucket.get(key, {})
@ -1158,8 +1164,11 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
raise RuntimeError('This storage does not provide Leaky Bucket')
if user_id is None and chat_id is None:
user_id = types.User.get_current().id
chat_id = types.Chat.get_current().id
chat_obj = types.Chat.get_current()
chat_id = chat_obj.id if chat_obj else None
user_obj = types.User.get_current()
user_id = user_obj.id if user_obj else None
bucket = await self.storage.get_bucket(chat=chat_id, user=user_id)
if bucket and key in bucket: