mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Added ability to specify which update bot need to receive and process while using polling mode (#617)
* provide allowed_updates in polling mode
This commit is contained in:
parent
eee6589a2c
commit
125fc22ff9
5 changed files with 184 additions and 4 deletions
28
aiogram/utils/handlers_in_use.py
Normal file
28
aiogram/utils/handlers_in_use.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from itertools import chain
|
||||
from typing import List, cast
|
||||
|
||||
from aiogram.dispatcher.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.router import Router
|
||||
|
||||
INTERNAL_HANDLERS = [
|
||||
"update",
|
||||
"error",
|
||||
]
|
||||
|
||||
|
||||
def get_handlers_in_use(
|
||||
dispatcher: Dispatcher, handlers_to_skip: List[str] = INTERNAL_HANDLERS
|
||||
) -> List[str]:
|
||||
handlers_in_use: List[str] = []
|
||||
|
||||
for router in [dispatcher.sub_routers, dispatcher]:
|
||||
if isinstance(router, list):
|
||||
if router:
|
||||
handlers_in_use.extend(chain(*list(map(get_handlers_in_use, router))))
|
||||
else:
|
||||
router = cast(Router, router)
|
||||
for update_name, observer in router.observers.items():
|
||||
if observer.handlers and update_name not in [*handlers_to_skip, *handlers_in_use]:
|
||||
handlers_in_use.append(update_name)
|
||||
|
||||
return handlers_in_use
|
||||
Loading…
Add table
Add a link
Reference in a new issue