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

42 lines
871 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, RawHandler] = {
update_type: module.handle for module in _MODULES for update_type in module.HANDLES
}
@PyroClient.on_raw_update()
async def dispatch(
client: PyroClient, update: raw.base.Update, users: dict, chats: dict
) -> None:
handler = _REGISTRY.get(type(update))
if handler is not None:
await handler(client, update, users, chats)
handlers = dispatch.handlers