from __future__ import annotations import asyncio import logging from collections.abc import Callable from pyrogram.errors import ( FloodWait, InputUserDeactivated, MessageDeleteForbidden, MessageIdInvalid, MessageNotModified, PeerIdInvalid, UserIsBlocked, ) from pyrogram.types import CallbackQuery, Message async def message_handler( func: Callable, *args, # noqa: ANN002 **kwargs, # noqa: ANN003 ) -> Message | CallbackQuery | None: try: return await func(*args, **kwargs) except ( UserIsBlocked, PeerIdInvalid, InputUserDeactivated, MessageIdInvalid, MessageNotModified, MessageDeleteForbidden, ): pass except FloodWait as e: await asyncio.sleep(e.value * 1.2) return await message_handler(func, *args, **kwargs) except Exception: logging.exception("Found an error")