mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
28 lines
705 B
Python
28 lines
705 B
Python
from abc import ABC
|
|
from typing import cast
|
|
|
|
from aiogram.filters import CommandObject
|
|
from aiogram.handlers.base import BaseHandler, BaseHandlerMixin
|
|
from aiogram.types import Chat, Message, User
|
|
|
|
|
|
class MessageHandler(BaseHandler[Message], ABC):
|
|
"""
|
|
Base class for message handlers
|
|
"""
|
|
|
|
@property
|
|
def from_user(self) -> User | None:
|
|
return self.event.from_user
|
|
|
|
@property
|
|
def chat(self) -> Chat:
|
|
return self.event.chat
|
|
|
|
|
|
class MessageHandlerCommandMixin(BaseHandlerMixin[Message]):
|
|
@property
|
|
def command(self) -> CommandObject | None:
|
|
if "command" in self.data:
|
|
return cast(CommandObject, self.data["command"])
|
|
return None
|