mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
refactor dp.throttled
This commit is contained in:
parent
288c7099b0
commit
4d00b7c502
1 changed files with 3 additions and 8 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue