Третий коммит, добавление share, share_kb, а также ADMIN_ID

This commit is contained in:
2025-07-22 13:50:14 +03:00
parent 849feb7beb
commit b98123f4dc
1479 changed files with 323549 additions and 11 deletions

View File

@@ -0,0 +1,46 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Dict, Generic, TypeVar, cast
from aiogram.types import Update
if TYPE_CHECKING:
from aiogram import Bot
T = TypeVar("T")
class BaseHandlerMixin(Generic[T]):
if TYPE_CHECKING:
event: T
data: Dict[str, Any]
class BaseHandler(BaseHandlerMixin[T], ABC):
"""
Base class for all class-based handlers
"""
def __init__(self, event: T, **kwargs: Any) -> None:
self.event: T = event
self.data: Dict[str, Any] = kwargs
@property
def bot(self) -> Bot:
from aiogram import Bot
if "bot" in self.data:
return cast(Bot, self.data["bot"])
raise RuntimeError("Bot instance not found in the context")
@property
def update(self) -> Update:
return cast(Update, self.data.get("update", self.data.get("event_update")))
@abstractmethod
async def handle(self) -> Any: # pragma: no cover
pass
def __await__(self) -> Any:
return self.handle().__await__()