Files
beavergram/backend/src/userbot/handlers/raw/dispatcher.py
T

42 lines
976 B
Python

from collections.abc import Awaitable, Callable
from pyrogram import raw
from userbot.handlers.raw import (
contacts,
dialog_filters,
profiles,
reactions,
read_contents,
read_receipts,
transcribed,
)
from userbot.modules.client import PyroClient
RawHandler = Callable[..., Awaitable[None]]
_MODULES = (
contacts,
dialog_filters,
profiles,
reactions,
read_contents,
read_receipts,
transcribed,
)
_REGISTRY: dict[type, list[RawHandler]] = {
update_type: [module.handle for module in _MODULES if update_type in module.HANDLES]
for update_type in {kind for module in _MODULES for kind in module.HANDLES}
}
@PyroClient.on_raw_update()
async def dispatch(
client: PyroClient, update: raw.base.Update, users: dict, chats: dict
) -> None:
for handler in _REGISTRY.get(type(update), ()):
await handler(client, update, users, chats)
handlers = dispatch.handlers # ty: ignore[unresolved-attribute]