Skip to content

Commit 70d5f22

Browse files
committed
Some fixes to the documentation
1 parent 394a9ad commit 70d5f22

15 files changed

Lines changed: 75 additions & 192 deletions

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ help:
2121

2222
lhtml: # live html
2323
sphinx-autobuild --host $(shell ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2) \
24-
--watch ../pyrogram -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)
24+
--watch ../pyrogram --watch resources -b html "$(SOURCEDIR)" "$(BUILDDIR)/html" $(SPHINXOPTS)

docs/source/intro/quickstart.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Enjoy the API
5050
That was just a quick overview. In the next few pages of the introduction, we'll take a much more in-depth look of what
5151
we have just done above.
5252

53-
If you are feeling eager to continue you can take a shortcut to :doc:`Calling Methods <../start/invoking>` and come back
53+
If you are feeling eager to continue you can take a shortcut to :doc:`Invoking Methods <../start/invoking>` and come back
5454
later to learn some more details.
5555

5656
.. _community: https://t.me/Pyrogram

docs/source/start/auth.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ after the session name, which will be ``my_bot.session`` for the example below.
8282

8383
.. note::
8484

85-
The API key (api_id and api_hash) and the bot_token is not needed anymore after a successful authorization.
86-
This means you can now simply use:
85+
The API key (api_id and api_hash) and the bot_token are not required anymore after a successful authorization.
86+
This means you can now simply use the following:
8787

8888
.. code-block:: python
8989

docs/source/start/errors.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This error is raised every time a method call against Telegram's API was unsucce
2525
2626
from pyrogram.errors import RPCError
2727
28-
.. note::
28+
.. warning::
2929

3030
Avoid catching this error everywhere, especially when no feedback is given (i.e. by logging/printing the full error
3131
traceback), because it makes it impossible to understand what went wrong.
@@ -81,9 +81,6 @@ In case Pyrogram does not know anything about a specific error yet, it raises a
8181
for example, an unknown error with error code ``400``, will be raised as a ``BadRequest``. This way you can catch the
8282
whole category of errors and be sure to also handle these unknown errors.
8383

84-
In case a whole class of errors is unknown (that is, an error code that is unknown), Pyrogram will raise a special
85-
``520 UnknownError`` exception.
86-
8784
Errors with Values
8885
------------------
8986

docs/source/start/updates.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ and how to handle new incoming messages or other events in Pyrogram.
1414
Defining Updates
1515
----------------
1616

17-
As hinted already, updates are events that happen in your Telegram account (incoming messages, new members join,
17+
Updates are events that happen in your Telegram account (incoming messages, new members join,
1818
bot button presses, etc.), which are meant to notify you about a new specific state that has changed. These updates are
1919
handled by registering one or more callback functions in your app using :doc:`Handlers <../api/handlers>`.
2020

docs/source/topics/advanced-usage.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Here's some examples:
5050
from pyrogram import Client
5151
from pyrogram.raw import functions
5252
53-
with Client("my_account") as app:
54-
app.send(
53+
async with Client("my_account") as app:
54+
await app.send(
5555
functions.account.UpdateProfile(
5656
first_name="First Name", last_name="Last Name",
5757
about="New bio text"
@@ -65,12 +65,12 @@ Here's some examples:
6565
from pyrogram import Client
6666
from pyrogram.raw import functions, types
6767
68-
with Client("my_account") as app:
68+
async with Client("my_account") as app:
6969
# Set online status
70-
app.send(functions.account.UpdateStatus(offline=False))
70+
await app.send(functions.account.UpdateStatus(offline=False))
7171
7272
# Set offline status
73-
app.send(functions.account.UpdateStatus(offline=True))
73+
await app.send(functions.account.UpdateStatus(offline=True))
7474
7575
- Get chat info:
7676

@@ -79,8 +79,8 @@ Here's some examples:
7979
from pyrogram import Client
8080
from pyrogram.raw import functions, types
8181
82-
with Client("my_account") as app:
83-
r = app.send(
82+
async with Client("my_account") as app:
83+
r = await app.send(
8484
functions.channels.GetFullChannel(
8585
channel=app.resolve_peer("username")
8686
)

docs/source/topics/client-settings.rst

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,7 @@ settings. By default you will see something like the following:
1818
Set Custom Values
1919
-----------------
2020

21-
To set custom values, you can either make use of the ``config.ini`` file, this way:
22-
23-
.. code-block:: ini
24-
25-
[pyrogram]
26-
app_version = 1.2.3
27-
device_model = PC
28-
system_version = Linux
29-
30-
Or, pass the arguments directly in the Client's constructor.
21+
To set custom values, you can pass the arguments directly in the Client's constructor.
3122

3223
.. code-block:: python
3324
@@ -47,11 +38,6 @@ English).
4738

4839
With the following code we make Telegram know we want it to speak in Italian (it):
4940

50-
.. code-block:: ini
51-
52-
[pyrogram]
53-
lang_code = it
54-
5541
.. code-block:: python
5642
5743
app = Client(

docs/source/topics/create-filters.rst

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ button:
2525
2626
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
2727
28-
app.send_message(
28+
await app.send_message(
2929
"username", # Change this to your username or id
3030
"Pyrogram custom filter test",
3131
reply_markup=InlineKeyboardMarkup(
@@ -48,40 +48,20 @@ queries containing "pyrogram" as data:
4848
4949
from pyrogram import filters
5050
51-
static_data_filter = filters.create(lambda _, __, query: query.data == "pyrogram")
52-
53-
The first two arguments of the callback function are unused here and because of this we named them using underscores.
54-
55-
The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example. The same
56-
can be achieved with a normal function, but we don't really need it as it makes sense only inside the filter's scope:
57-
58-
.. code-block:: python
59-
60-
from pyrogram import filters
61-
62-
def func(_, __, query):
51+
async def func(_, __, query):
6352
return query.data == "pyrogram"
6453
6554
static_data_filter = filters.create(func)
6655
67-
Asynchronous filters are also possible. Sadly, Python itself doesn't have an ``async lambda``, so we are left with
68-
using a named function:
69-
70-
.. code-block:: python
71-
72-
from pyrogram import filters
73-
74-
async def func(_, __, query):
75-
return query.data == "pyrogram"
7656
77-
static_data_filter = filters.create(func)
57+
The first two arguments of the callback function are unused here and because of this we named them using underscores.
7858

7959
Finally, the filter usage remains the same:
8060

8161
.. code-block:: python
8262
8363
@app.on_callback_query(static_data_filter)
84-
def pyrogram_data(_, query):
64+
async def pyrogram_data(_, query):
8565
query.answer("it works!")
8666
8767
Filters with Arguments
@@ -94,18 +74,6 @@ via named arguments.
9474

9575
This is how a dynamic custom filter looks like:
9676

97-
.. code-block:: python
98-
99-
from pyrogram import filters
100-
101-
def dynamic_data_filter(data):
102-
return filters.create(
103-
lambda flt, _, query: flt.data == query.data,
104-
data=data # "data" kwarg is accessed with "flt.data" above
105-
)
106-
107-
And its asynchronous variant:
108-
10977
.. code-block:: python
11078
11179
from pyrogram import filters
@@ -122,7 +90,7 @@ And finally its usage:
12290
.. code-block:: python
12391
12492
@app.on_callback_query(dynamic_data_filter("pyrogram"))
125-
def pyrogram_data(_, query):
93+
async def pyrogram_data(_, query):
12694
query.answer("it works!")
12795
12896
@@ -133,16 +101,6 @@ The missing piece we haven't covered yet is the second argument of a filter call
133101
argument. This is a reference to the :obj:`~pyrogram.Client` instance that is running the filter and it is useful in
134102
case you would like to make some API calls before deciding whether the filter should allow the update or not:
135103

136-
.. code-block:: python
137-
138-
def func(_, client, query):
139-
# r = client.some_api_method()
140-
# check response "r" and decide to return True or False
141-
...
142-
143-
Asynchronous filters making API calls work fine as well. Just remember that you need to put ``async`` in front of
144-
function definitions and ``await`` in front of method calls:
145-
146104
.. code-block:: python
147105
148106
async def func(_, client, query):

docs/source/topics/debugging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Consider the following code:
2727

2828
.. code-block:: python
2929
30-
me = app.get_users("me")
30+
me = await app.get_users("me")
3131
print(me) # User
3232
3333
This will show a JSON representation of the object returned by :meth:`~pyrogram.Client.get_users`, which is a

docs/source/topics/more-on-updates.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ For example, take these two handlers:
2626
.. code-block:: python
2727
2828
@app.on_message(filters.text | filters.sticker)
29-
def text_or_sticker(client, message):
29+
async def text_or_sticker(client, message):
3030
print("Text or Sticker")
3131
3232
3333
@app.on_message(filters.text)
34-
def just_text(client, message):
34+
async def just_text(client, message):
3535
print("Just Text")
3636
3737
Here, ``just_text`` is never executed because ``text_or_sticker``, which has been registered first, already handles
@@ -40,15 +40,15 @@ texts (``filters.text`` is shared and conflicting). To enable it, register the h
4040
.. code-block:: python
4141
4242
@app.on_message(filters.text, group=1)
43-
def just_text(client, message):
43+
async def just_text(client, message):
4444
print("Just Text")
4545
4646
Or, if you want ``just_text`` to be executed *before* ``text_or_sticker`` (note ``-1``, which is less than ``0``):
4747

4848
.. code-block:: python
4949
5050
@app.on_message(filters.text, group=-1)
51-
def just_text(client, message):
51+
async def just_text(client, message):
5252
print("Just Text")
5353
5454
With :meth:`~pyrogram.Client.add_handler` (without decorators) the same can be achieved with:
@@ -68,17 +68,17 @@ continue to propagate the same update to the next groups until all the handlers
6868
.. code-block:: python
6969
7070
@app.on_message(filters.private)
71-
def _(client, message):
71+
async def _(client, message):
7272
print(0)
7373
7474
7575
@app.on_message(filters.private, group=1)
76-
def _(client, message):
76+
async def _(client, message):
7777
raise Exception("Unhandled exception!") # Simulate an unhandled exception
7878
7979
8080
@app.on_message(filters.private, group=2)
81-
def _(client, message):
81+
async def _(client, message):
8282
print(2)
8383
8484
All these handlers will handle the same kind of messages, that are, messages sent or received in private chats.
@@ -110,18 +110,18 @@ Example with ``stop_propagation()``:
110110
.. code-block:: python
111111
112112
@app.on_message(filters.private)
113-
def _(client, message):
113+
async def _(client, message):
114114
print(0)
115115
116116
117117
@app.on_message(filters.private, group=1)
118-
def _(client, message):
118+
async def _(client, message):
119119
print(1)
120120
message.stop_propagation()
121121
122122
123123
@app.on_message(filters.private, group=2)
124-
def _(client, message):
124+
async def _(client, message):
125125
print(2)
126126
127127
Example with ``raise StopPropagation``:
@@ -131,18 +131,18 @@ Example with ``raise StopPropagation``:
131131
from pyrogram import StopPropagation
132132
133133
@app.on_message(filters.private)
134-
def _(client, message):
134+
async def _(client, message):
135135
print(0)
136136
137137
138138
@app.on_message(filters.private, group=1)
139-
def _(client, message):
139+
async ef _(client, message):
140140
print(1)
141141
raise StopPropagation
142142
143143
144144
@app.on_message(filters.private, group=2)
145-
def _(client, message):
145+
async def _(client, message):
146146
print(2)
147147
148148
Each handler is registered in a different group, but the handler in group number 2 will never be executed because the
@@ -178,19 +178,19 @@ Example with ``continue_propagation()``:
178178
.. code-block:: python
179179
180180
@app.on_message(filters.private)
181-
def _(client, message):
181+
async def _(client, message):
182182
print(0)
183183
message.continue_propagation()
184184
185185
186186
@app.on_message(filters.private)
187-
def _(client, message):
187+
async def _(client, message):
188188
print(1)
189189
message.continue_propagation()
190190
191191
192192
@app.on_message(filters.private)
193-
def _(client, message):
193+
async def _(client, message):
194194
print(2)
195195
196196
Example with ``raise ContinuePropagation``:
@@ -200,19 +200,19 @@ Example with ``raise ContinuePropagation``:
200200
from pyrogram import ContinuePropagation
201201
202202
@app.on_message(filters.private)
203-
def _(client, message):
203+
async def _(client, message):
204204
print(0)
205205
raise ContinuePropagation
206206
207207
208208
@app.on_message(filters.private)
209-
def _(client, message):
209+
async def _(client, message):
210210
print(1)
211211
raise ContinuePropagation
212212
213213
214214
@app.on_message(filters.private)
215-
def _(client, message):
215+
async def _(client, message):
216216
print(2)
217217
218218
Three handlers are registered in the same group, and all of them will be executed because the propagation was continued

0 commit comments

Comments
 (0)