Reworked handlers in use (#682)

* Reworked handlers in use util

* Added patch-notes
This commit is contained in:
Alex Root Junior 2021-09-07 01:04:33 +03:00 committed by GitHub
parent e356ede5de
commit cfd2a9968e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 39 deletions

View file

@ -1,28 +0,0 @@
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