mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Typing for handlers and add hello world to index page of docs
This commit is contained in:
parent
9dc1e9ff1a
commit
b30e4e77ad
3 changed files with 54 additions and 4 deletions
|
|
@ -6,11 +6,17 @@ from aiogram.api.types import TelegramObject
|
|||
|
||||
|
||||
class BaseHandlerMixin:
|
||||
"""
|
||||
Typed mixin. Do nothing.
|
||||
"""
|
||||
event: TelegramObject
|
||||
data: Dict[str, Any]
|
||||
|
||||
|
||||
class _HandlerBotMixin(BaseHandlerMixin):
|
||||
"""
|
||||
Mixin adds bot attribute
|
||||
"""
|
||||
@property
|
||||
def bot(self) -> Bot:
|
||||
if "bot" in self.data:
|
||||
|
|
@ -19,7 +25,9 @@ class _HandlerBotMixin(BaseHandlerMixin):
|
|||
|
||||
|
||||
class BaseHandler(_HandlerBotMixin, ABC):
|
||||
event: TelegramObject
|
||||
"""
|
||||
Base class for all class-based handlers
|
||||
"""
|
||||
|
||||
def __init__(self, event: TelegramObject, **kwargs: Any) -> None:
|
||||
self.event = event
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from abc import ABC
|
||||
from typing import Optional
|
||||
|
||||
from aiogram.api.types import Message
|
||||
from aiogram.api.types import Message, User, Chat
|
||||
from aiogram.dispatcher.filters import CommandObject
|
||||
from aiogram.dispatcher.handler.base import BaseHandler, BaseHandlerMixin
|
||||
|
||||
|
|
@ -10,11 +10,11 @@ class MessageHandler(BaseHandler, ABC):
|
|||
event: Message
|
||||
|
||||
@property
|
||||
def from_user(self):
|
||||
def from_user(self) -> User:
|
||||
return self.event.from_user
|
||||
|
||||
@property
|
||||
def chat(self):
|
||||
def chat(self) -> Chat:
|
||||
return self.event.chat
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue