538f1e3972
- Pyrogram core is now fully asynchronous - Ditched Python 3.5, welcome 3.6 as minimum version. - Moved all types to pyrogram.types - Turned the Filters class into a module (filters) - Moved all filters to pyrogram.filters - Moved all handlers to pyrogram.handlers - Moved all emoji to pyrogram.emoji - Renamed pyrogram.api to pyrogram.raw - Clock is now synced with server's time - Telegram schema updated to Layer 117 - Greatly improved the TL compiler (proper type-constructor hierarchy) - Added "do not edit" warning in generated files - Crypto parts are executed in a thread pool to avoid blocking the event loop - idle() is now a separate function (it doesn't deal with Client instances) - Async storage, async filters and async progress callback (optional, can be sync too) - Added getpass back, for hidden password inputs
66 lines
1.7 KiB
ReStructuredText
66 lines
1.7 KiB
ReStructuredText
Decorators
|
|
==========
|
|
|
|
While still being methods bound to the :class:`~pyrogram.Client` class, decorators are of a special kind and thus
|
|
deserve a dedicated page.
|
|
|
|
Decorators are able to register callback functions for handling updates in a much easier and cleaner way compared to
|
|
:doc:`Handlers <handlers>`; they do so by instantiating the correct handler and calling
|
|
:meth:`~pyrogram.Client.add_handler` automatically. All you need to do is adding the decorators on top of your
|
|
functions.
|
|
|
|
.. code-block:: python
|
|
:emphasize-lines: 6
|
|
|
|
from pyrogram import Client
|
|
|
|
app = Client("my_account")
|
|
|
|
|
|
@app.on_message()
|
|
def log(client, message):
|
|
print(message)
|
|
|
|
|
|
app.run()
|
|
|
|
.. contents:: Contents
|
|
:backlinks: none
|
|
:depth: 1
|
|
:local:
|
|
|
|
-----
|
|
|
|
.. currentmodule:: pyrogram
|
|
|
|
Index
|
|
-----
|
|
|
|
.. hlist::
|
|
:columns: 3
|
|
|
|
- :meth:`~Client.on_message`
|
|
- :meth:`~Client.on_callback_query`
|
|
- :meth:`~Client.on_inline_query`
|
|
- :meth:`~Client.on_chosen_inline_result`
|
|
- :meth:`~Client.on_deleted_messages`
|
|
- :meth:`~Client.on_user_status`
|
|
- :meth:`~Client.on_poll`
|
|
- :meth:`~Client.on_disconnect`
|
|
- :meth:`~Client.on_raw_update`
|
|
|
|
-----
|
|
|
|
Details
|
|
-------
|
|
|
|
.. Decorators
|
|
.. autodecorator:: pyrogram.Client.on_message()
|
|
.. autodecorator:: pyrogram.Client.on_callback_query()
|
|
.. autodecorator:: pyrogram.Client.on_inline_query()
|
|
.. autodecorator:: pyrogram.Client.on_chosen_inline_result()
|
|
.. autodecorator:: pyrogram.Client.on_deleted_messages()
|
|
.. autodecorator:: pyrogram.Client.on_user_status()
|
|
.. autodecorator:: pyrogram.Client.on_poll()
|
|
.. autodecorator:: pyrogram.Client.on_disconnect()
|
|
.. autodecorator:: pyrogram.Client.on_raw_update() |