refactor dp.throttled

This commit is contained in:
birdi 2019-08-05 11:32:28 +03:00
parent 288c7099b0
commit 4d00b7c502

View file

@ -1054,16 +1054,12 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
:param chat_id: chat id :param chat_id: chat id
:return: decorator :return: decorator
""" """
def decorator(func): def decorator(func):
nonlocal on_throttled, key, rate, user_id, chat_id
if key is None:
key = func.__name__
@functools.wraps(func) @functools.wraps(func)
async def wrapped(*args, **kwargs): async def wrapped(*args, **kwargs):
is_not_throttled = await self.throttle(key, rate=rate, is_not_throttled = await self.throttle(key if key is not None else func.__name__,
user_id=user_id, chat_id=chat_id, rate=rate,
user=user_id, chat=chat_id,
no_error=True) no_error=True)
if is_not_throttled: if is_not_throttled:
return await func(*args, **kwargs) return await func(*args, **kwargs)
@ -1090,7 +1086,6 @@ class Dispatcher(DataMixin, ContextInstanceMixin):
asyncio.get_running_loop().run_in_executor(None, asyncio.get_running_loop().run_in_executor(None,
partial_func partial_func
) )
return wrapped return wrapped
return decorator return decorator