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