refactor(handler): rename observers

Rename observers but with backward compatibility, relevant documentation
This commit is contained in:
mpa 2020-05-10 03:02:31 +04:00
parent b097680f3c
commit 4124770b0e
21 changed files with 297 additions and 110 deletions

View file

@ -8,7 +8,7 @@ from aiogram.handlers import CallbackQueryHandler
...
@router.callback_query_handler()
@router.callback_query()
class MyHandler(CallbackQueryHandler):
async def handle(self) -> Any: ...
@ -26,4 +26,4 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [CallbackQuery](../../api/types/callback_query.md)
- [Router.callback_query_handler](../router.md#callback-query)
- [Router.callback_query](../router.md#callback-query)

View file

@ -8,7 +8,7 @@ from aiogram.handlers import ChosenInlineResultHandler
...
@router.chosen_inline_result_handler()
@router.chosen_inline_result()
class MyHandler(ChosenInlineResultHandler):
async def handle(self) -> Any: ...
@ -25,4 +25,4 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [ChosenInlineResult](../../api/types/chosen_inline_result.md)
- [Router.chosen_inline_result_handler](../router.md#chosen-inline-query)
- [Router.chosen_inline_result](../router.md#chosen-inline-query)

View file

@ -8,7 +8,7 @@ from aiogram.handlers import ErrorHandler
...
@router.errors_handler()
@router.errors()
class MyHandler(ErrorHandler):
async def handle(self) -> Any:
log.exception(
@ -28,5 +28,5 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
## Related pages
- [BaseHandler](basics.md#basehandler)
- [Router.errors_handler](../router.md#errors)
- [Router.errors](../router.md#errors)
- [Filters](../filters/exception.md)

View file

@ -7,7 +7,7 @@ from aiogram.handlers import InlineQueryHandler
...
@router.inline_query_handler()
@router.inline_query()
class MyHandler(InlineQueryHandler):
async def handle(self) -> Any: ...

View file

@ -8,7 +8,7 @@ from aiogram.handlers import MessageHandler
...
@router.message_handler()
@router.message()
class MyHandler(MessageHandler):
async def handle(self) -> Any:
return SendMessage(chat_id=self.chat.id, text="PASS")
@ -26,7 +26,7 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [Message](../../api/types/message.md)
- [Router.message_handler](../router.md#message)
- [Router.edited_message_handler](../router.md#edited-message)
- [Router.channel_post_handler](../router.md#channel-post)
- [Router.edited_channel_post_handler](../router.md#edited-channel-post)
- [Router.message](../router.md#message)
- [Router.edited_message](../router.md#edited-message)
- [Router.channel_post](../router.md#channel-post)
- [Router.edited_channel_post](../router.md#edited-channel-post)

View file

@ -8,7 +8,7 @@ from aiogram.handlers import PollHandler
...
@router.poll_handler()
@router.poll()
class MyHandler(PollHandler):
async def handle(self) -> Any: ...
@ -25,4 +25,4 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [Poll](../../api/types/poll.md)
- [Router.poll_handler](../router.md#poll)
- [Router.poll](../router.md#poll)

View file

@ -8,7 +8,7 @@ from aiogram.handlers import PreCheckoutQueryHandler
...
@router.pre_checkout_query_handler()
@router.pre_checkout_query()
class MyHandler(PreCheckoutQueryHandler):
async def handle(self) -> Any: ...
@ -24,4 +24,4 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [PreCheckoutQuery](../../api/types/pre_checkout_query.md)
- [Router.pre_checkout_query_handler](../router.md#pre-checkout-query)
- [Router.pre_checkout_query](../router.md#pre-checkout-query)

View file

@ -8,7 +8,7 @@ from aiogram.handlers import ShippingQueryHandler
...
@router.shipping_query_handler()
@router.shipping_query()
class MyHandler(ShippingQueryHandler):
async def handle(self) -> Any: ...
@ -24,4 +24,4 @@ This base handler is subclass of [BaseHandler](basics.md#basehandler) with some
- [BaseHandler](basics.md#basehandler)
- [ShippingQuery](../../api/types/shipping_query.md)
- [Router.shipping_query_handler](../router.md#shipping-query)
- [Router.shipping_query](../router.md#shipping-query)

View file

@ -21,7 +21,7 @@ Example:
```python3
dp = Dispatcher()
@dp.message_handler()
@dp.message()
async def message_handler(message: types.Message) -> None:
await SendMessage(chat_id=message.from_user.id, text=message.text)
```

View file

@ -19,7 +19,7 @@ Works only with [Message](../../api/types/message.md) events which have the `tex
1. Handle command by regexp pattern: `#!python3 Command(commands=[re.compile(r"item_(\d+)")])`
1. Match command by multiple variants: `#!python3 Command(commands=["item", re.compile(r"item_(\d+)")])`
1. Handle commands in public chats intended for other bots: `#!python3 Command(commands=["command"], commands)`
1. As keyword argument in registerer: `#!python3 @router.message_handler(commands=["help"])`
1. As keyword argument in registerer: `#!python3 @router.message(commands=["help"])`
!!! warning
Command cannot include spaces or any whitespace

View file

@ -53,9 +53,9 @@ class MyText(BaseFilter):
return message.text == self.my_text
router.message_handler.bind_filter(MyText)
router.message.bind_filter(MyText)
@router.message_handler(my_text="hello")
@router.message(my_text="hello")
async def my_handler(message: Message): ...
```

View file

@ -34,91 +34,91 @@ Here is list of available observers and examples how to register handlers (In ex
### Update
```python3
@router.update_handler()
@router.update()
async def message_handler(update: types.Update) -> Any: pass
```
Should be used for handling [updates](../api/types/update.md). By default Router is already have an update handler which route all event types to another observers.
### Message
```python3
@router.message_handler()
@router.message()
async def message_handler(message: types.Message) -> Any: pass
```
Is useful for handling [message](../api/types/message.md)
### Edited message
```python3
@router.edited_message_handler()
@router.edited_message()
async def edited_message_handler(edited_message: types.Message) -> Any: pass
```
Is useful for handling [edited messages](../api/types/message.md)
### Channel post
```python3
@router.channel_post_handler()
@router.channel_post()
async def channel_post_handler(channel_post: types.Message) -> Any: pass
```
Is useful for handling [channel posts](../api/types/message.md)
### Edited channel post
```python3
@router.edited_channel_post_handler()
@router.edited_channel_post()
async def edited_channel_post_handler(edited_channel_post: types.Message) -> Any: pass
```
Is useful for handling [edited channel posts](../api/types/message.md)
### Inline query
```python3
@router.inline_query_handler()
@router.inline_query()
async def inline_query_handler(inline_query: types.Message) -> Any: pass
```
Is useful for handling [inline query](../api/types/inline_query.md)
### Chosen inline query
```python3
@router.chosen_inline_result_handler()
@router.chosen_inline_result()
async def chosen_inline_result_handler(chosen_inline_result: types.ChosenInlineResult) -> Any: pass
```
Is useful for handling [chosen inline query](../api/types/chosen_inline_result.md)
### Callback query
```python3
@router.callback_query_handler()
@router.callback_query()
async def callback_query_handler(callback_query: types.CallbackQuery) -> Any: pass
```
Is useful for handling [callback query's](../api/types/callback_query.md)
### Shipping query
```python3
@router.shipping_query_handler()
@router.shipping_query()
async def shipping_query_handler(shipping_query: types.ShippingQuery) -> Any: pass
```
Is useful for handling [shipping query](../api/types/shipping_query.md)
### Pre checkout query
```python3
@router.pre_checkout_query_handler()
@router.pre_checkout_query()
async def pre_checkout_query_handler(pre_checkout_query: types.PreCheckoutQuery) -> Any: pass
```
Is useful for handling [pre-checkout query](../api/types/pre_checkout_query.md)
### Poll
```python3
@router.poll_handler()
@router.poll()
async def poll_handler(poll: types.Poll) -> Any: pass
```
Is useful for handling [polls](../api/types/poll.md)
### Poll answer
```python3
@router.poll_answer_handler()
@router.poll_answer()
async def poll_answer_handler(poll_answer: types.PollAnswer) -> Any: pass
```
Is useful for handling [polls answers](../api/types/poll_answer.md)
### Errors
```python3
@router.errors_handler()
@router.errors()
async def error_handler(exception: Exception) -> Any: pass
```
Is useful for handling errors from other handlers