2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-31 06:16:06 +00:00

Update docs

This commit is contained in:
Dan
2018-04-12 13:43:16 +02:00
parent 70cd0500de
commit 1ccda820c1
4 changed files with 67 additions and 35 deletions

View File

@@ -7,7 +7,7 @@ Inline Bots
-----------
- If a bot accepts inline queries, you can call it by using
:obj:`get_inline_bot_results <pyrogram.Client.get_inline_bot_results>` to get the list of its inline results
:meth:`get_inline_bot_results() <pyrogram.Client.get_inline_bot_results>` to get the list of its inline results
for a query:
.. code-block:: python
@@ -20,11 +20,11 @@ Inline Bots
:align: center
:figwidth: 60%
``get_inline_bot_results`` is the equivalent action of writing ``@vid Fuzz Universe`` and getting the
``get_inline_bot_results()`` is the equivalent action of writing ``@vid Fuzz Universe`` and getting the
results list.
- After you retrieved the bot results, you can use
:obj:`send_inline_bot_result <pyrogram.Client.send_inline_bot_result>` to send a chosen result to any chat:
:meth:`send_inline_bot_result() <pyrogram.Client.send_inline_bot_result>` to send a chosen result to any chat:
.. code-block:: python
@@ -36,5 +36,5 @@ Inline Bots
:align: center
:figwidth: 60%
``send_inline_bot_result`` is the equivalent action of choosing a result from the list and sending it
``send_inline_bot_result()`` is the equivalent action of choosing a result from the list and sending it
to a chat.

View File

@@ -1,8 +1,9 @@
Update Handling
===============
Updates are handled by registering one or more callback functions with an Handler.
There are multiple Handlers to choose from, one for each kind of update.
Updates are events that happen in your Telegram account (incoming messages, new channel posts, new members join, ...)
and are handled by registering one or more callback functions with an Handler. There are multiple Handlers to choose
from, one for each kind of update.
Registering an Handler
----------------------
@@ -29,16 +30,18 @@ of a message as soon as it arrives.
app.start()
app.idle()
Alternatively, if you prefer not to use decorators, there is an alternative way for registering Handlers.
If you prefer not to use decorators, there is an alternative way for registering Handlers.
This is useful, for example, if you want to keep your callback functions in a separate file.
.. code-block:: python
from pyrogram import Client, MessageHandler
def my_handler(client, message):
print(message)
app = Client("my_account")
app.add_handler(MessageHandler(my_handler))
@@ -46,10 +49,11 @@ This is useful, for example, if you want to keep your callback functions in a se
app.start()
app.idle()
Using Filters
-------------
For a finer grained control over what kind of messages will be allowed or not, you can use
For a finer grained control over what kind of messages will be allowed or not in your callback functions, you can use
:class:`Filters <pyrogram.Filters>`. The next example will show you how to handler only messages
containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` object:
@@ -57,6 +61,7 @@ containing an :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` object:
from pyrogram import Filters
@app.on_message(Filters.audio)
def my_handler(client, message):
print(message)
@@ -67,18 +72,20 @@ or, without decorators:
from pyrogram import Filters, Messagehandler
def my_handler(client, message):
print(message)
app.add_handler(MessageHandler(my_handler, Filters.audio))
Advanced Filters
----------------
Combining Filters
-----------------
Filters can also be used in a more advanced way by combining more filters together using bitwise operators:
- Use ``~`` to invert a filter (behaves like the ``not`` operator).
- Use ``&`` and ``|`` to merge two filters (``and``, ``or`` operators respectively).
- Use ``&`` and ``|`` to merge two filters (behave like ``and``, ``or`` operators respectively).
Here are some examples:
@@ -90,7 +97,7 @@ Here are some examples:
def my_handler(client, message):
print(message)
- Message is a **sticker** **and** was sent in a **channel** or in a **private** chat.
- Message is a **sticker** **and** is coming from a **channel** or a **private** chat.
.. code-block:: python
@@ -98,10 +105,13 @@ Here are some examples:
def my_handler(client, message):
print(message)
Some filters can also accept parameters, like :obj:`command <pyrogram.Filters.command>` or
:obj:`regex <pyrogram.Filters.regex>`:
Advanced Filters
----------------
- Message is either a /start or /help **command**.
Some filters, like :obj:`command() <pyrogram.Filters.command>` or :obj:`regex() <pyrogram.Filters.regex>`
can also accept arguments:
- Message is either a */start* or */help* **command**.
.. code-block:: python
@@ -115,4 +125,22 @@ Some filters can also accept parameters, like :obj:`command <pyrogram.Filters.co
@app.on_message(Filters.regex("pyrogram"))
def my_handler(client, message):
print(message)
print(message)
More handlers using different filters can be created as well:
.. code-block:: python
@app.on_message(Filters.command("start"))
def start_command(client, message):
print("This is the /start command")
@app.on_message(Filters.command("help"))
def help_command(client, message):
print("This is the /help command")
@app.on_message(Filters.chat("PyrogramChat"))
def my_handler(client, message):
print("New message in @PyrogramChat")