Visitar URL original
Add examples to all available methods · hexa0code/pyrogram@2dec244 · GitHub
Skip to content

Commit 2dec244

Browse files
committed
Add examples to all available methods
1 parent fe2ccc6 commit 2dec244

92 files changed

Lines changed: 876 additions & 287 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pyrogram/client/methods/bots/answer_callback_query.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ def answer_callback_query(
5656
Returns:
5757
``bool``: True, on success.
5858
59-
Raises:
60-
RPCError: In case of a Telegram RPC error.
59+
Example:
60+
.. code-block:: python
61+
62+
# Answer without alert
63+
app.answer_callback_query(query_id, text=text)
64+
65+
# Answer with alert
66+
app.answer_callback_query(query_id, text=text, show_alert=True)
6167
"""
6268
return self.send(
6369
functions.messages.SetBotCallbackAnswer(

‎pyrogram/client/methods/bots/answer_inline_query.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,17 @@ def answer_inline_query(
8181
Returns:
8282
``bool``: True, on success.
8383
84-
Raises:
85-
RPCError: In case of a Telegram RPC error.
84+
Example:
85+
.. code-block:: python
86+
87+
from pyrogram import InlineQueryResultArticle, InputTextMessageContent
88+
89+
app.answer_inline_query(
90+
inline_query_id,
91+
results=[
92+
InlineQueryResultArticle(
93+
"Title",
94+
InputTextMessageContent("Message content"))])
8695
"""
8796
return self.send(
8897
functions.messages.SetInlineBotResults(

‎pyrogram/client/methods/bots/get_game_high_scores.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def get_game_high_scores(
5151
Returns:
5252
List of :obj:`GameHighScore`: On success.
5353
54-
Raises:
55-
RPCError: In case of a Telegram RPC error.
54+
Example:
55+
.. code-block:: python
56+
57+
scores = app.get_game_high_scores(user_id, chat_id, message_id)
58+
print(scores)
5659
"""
5760
# TODO: inline_message_id
5861

‎pyrogram/client/methods/bots/get_inline_bot_results.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GetInlineBotResults(BaseClient):
2727
def get_inline_bot_results(
2828
self,
2929
bot: Union[int, str],
30-
query: str,
30+
query: str = "",
3131
offset: str = "",
3232
latitude: float = None,
3333
longitude: float = None
@@ -40,8 +40,9 @@ def get_inline_bot_results(
4040
Unique identifier of the inline bot you want to get results from. You can specify
4141
a @username (str) or a bot ID (int).
4242
43-
query (``str``):
43+
query (``str``, *optional*):
4444
Text of the query (up to 512 characters).
45+
Defaults to "" (empty string).
4546
4647
offset (``str``, *optional*):
4748
Offset of the results to be returned.
@@ -58,8 +59,13 @@ def get_inline_bot_results(
5859
:obj:`BotResults <pyrogram.api.types.messages.BotResults>`: On Success.
5960
6061
Raises:
61-
RPCError: In case of a Telegram RPC error.
6262
TimeoutError: In case the bot fails to answer within 10 seconds.
63+
64+
Example:
65+
.. code-block:: python
66+
67+
results = app.get_inline_bot_results("pyrogrambot")
68+
print(results)
6369
"""
6470
# TODO: Don't return the raw type
6571

‎pyrogram/client/methods/bots/request_callback_answer.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ def request_callback_answer(
5353
or as an alert.
5454
5555
Raises:
56-
RPCError: In case of a Telegram RPC error.
5756
TimeoutError: In case the bot fails to answer within 10 seconds.
57+
58+
Example:
59+
.. code-block:: python
60+
61+
app.request_callback_answer(chat_id, message_id, "callback_data")
5862
"""
5963

6064
# Telegram only wants bytes, but we are allowed to pass strings too.

‎pyrogram/client/methods/bots/send_game.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ def send_game(
6262
Returns:
6363
:obj:`Message`: On success, the sent game message is returned.
6464
65-
Raises:
66-
RPCError: In case of a Telegram RPC error.
65+
Example:
66+
.. code-block:: python
67+
68+
app.send_game(chat_id, "gamename")
6769
"""
6870
r = self.send(
6971
functions.messages.SendMedia(

‎pyrogram/client/methods/bots/send_inline_bot_result.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def send_inline_bot_result(
6060
Returns:
6161
:obj:`Message`: On success, the sent inline result message is returned.
6262
63-
Raises:
64-
RPCError: In case of a Telegram RPC error.
63+
Example:
64+
.. code-block:: python
65+
66+
app.send_inline_bot_result(chat_id, query_id, result_id)
6567
"""
6668
return self.send(
6769
functions.messages.SendInlineBotResult(

‎pyrogram/client/methods/bots/set_game_score.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,14 @@ def set_game_score(
6666
:obj:`Message` | ``bool``: On success, if the message was sent by the bot, the edited message is returned,
6767
True otherwise.
6868
69-
Raises:
70-
RPCError: In case of a Telegram RPC error.
69+
Example:
70+
.. code-block:: python
71+
72+
# Set new score
73+
app.set_game_score(user_id, 1000)
74+
75+
# Force set new score
76+
app.set_game_score(user_id, 25, force=True)
7177
"""
7278
r = self.send(
7379
functions.messages.SetGameScore(

‎pyrogram/client/methods/chats/add_chat_members.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ def add_chat_members(
4747
4848
Returns:
4949
``bool``: On success, True is returned.
50+
51+
Example:
52+
.. code-block:: python
53+
54+
# Add one member to a group or channel
55+
app.add_chat_members(chat_id, user_id)
56+
57+
# Add multiple members to a group or channel
58+
app.add_chat_members(chat_id, [user_id1, user_id2, user_id3])
59+
60+
# Change forward_limit (for basic groups only)
61+
app.add_chat_members(chat_id, user_id, forward_limit=25)
5062
"""
5163
peer = self.resolve_peer(chat_id)
5264

‎pyrogram/client/methods/chats/archive_chats.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ def archive_chats(
3737
Returns:
3838
``bool``: On success, True is returned.
3939
40-
Raises:
41-
RPCError: In case of a Telegram RPC error.
40+
Example:
41+
.. code-block:: python
42+
43+
# Archive chat
44+
app.archive_chats(chat_id)
45+
46+
# Archive multiple chats at once
47+
app.archive_chats([chat_id1, chat_id2, chat_id3])
4248
"""
4349

4450
if not isinstance(chat_ids, list):

0 commit comments

Comments
 (0)