Skip to content

Commit bc9f902

Browse files
committed
Clean up inline-mode
1 parent fede743 commit bc9f902

33 files changed

+287
-121
lines changed

docs/source/pyrogram/Client.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Bots
143143
send_game
144144
set_game_score
145145
get_game_high_scores
146+
answer_inline_query
146147

147148

148149
.. autoclass:: pyrogram.Client

docs/source/pyrogram/Types.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ Inline Mode
7979
.. autosummary::
8080
:nosignatures:
8181

82+
InlineQuery
8283
InlineQueryResult
8384
InlineQueryResultArticle
85+
86+
InputMessageContent
87+
-------------------
88+
89+
.. autosummary::
90+
:nosignatures:
91+
8492
InputMessageContent
8593
InputTextMessageContent
8694

@@ -229,12 +237,18 @@ Inline Mode
229237
.. Inline Mode
230238
-----------
231239
240+
.. autoclass:: InlineQuery
241+
:members:
242+
232243
.. autoclass:: InlineQueryResult
233244
:members:
234245

235246
.. autoclass:: InlineQueryResultArticle
236247
:members:
237248

249+
.. InputMessageContent
250+
-------------------
251+
238252
.. autoclass:: InputMessageContent
239253
:members:
240254

pyrogram/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
3939
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
4040
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
41-
InlineQuery, InlineQueryResult, InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent,
42-
InlineQueryResultCachedAudio, InputMessageContent, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton,
43-
ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll, PollOption, ChatPreview, StopPropagation, ContinuePropagation,
44-
Game, CallbackGame, GameHighScore, GameHighScores, ChatPermissions
41+
InlineQuery, InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputTextMessageContent,
42+
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll,
43+
PollOption, ChatPreview, StopPropagation, ContinuePropagation, Game, CallbackGame, GameHighScore, GameHighScores,
44+
ChatPermissions
4545
)
4646
from .client import (
4747
Client, ChatAction, ParseMode, Emoji,

pyrogram/client/methods/bots/answer_inline_query.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,65 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import List
20+
1921
from pyrogram.api import functions, types
2022
from pyrogram.client.ext import BaseClient
23+
from ...types.inline_mode import InlineQueryResult
2124

2225

2326
class AnswerInlineQuery(BaseClient):
2427
def answer_inline_query(
2528
self,
2629
inline_query_id: str,
27-
results: list,
30+
results: List[InlineQueryResult],
2831
cache_time: int = 300,
2932
is_personal: bool = None,
3033
next_offset: str = "",
3134
switch_pm_text: str = "",
3235
switch_pm_parameter: str = ""
3336
):
34-
# TODO: Docs
37+
"""Use this method to send answers to an inline query.
38+
No more than 50 results per query are allowed.
39+
40+
Args:
41+
inline_query_id (``str``):
42+
Unique identifier for the answered query.
43+
44+
results (List of :obj:`InlineQueryResult <pyrogram.InlineQueryResult>`):
45+
A list of results for the inline query.
46+
47+
cache_time (``int``, *optional*):
48+
The maximum amount of time in seconds that the result of the inline query may be cached on the server.
49+
Defaults to 300.
50+
51+
is_personal (``bool``, *optional*):
52+
Pass True, if results may be cached on the server side only for the user that sent the query.
53+
By default, results may be returned to any user who sends the same query.
54+
55+
next_offset (``str``, *optional*):
56+
Pass the offset that a client should send in the next query with the same text to receive more results.
57+
Pass an empty string if there are no more results or if you don‘t support pagination.
58+
Offset length can’t exceed 64 bytes.
59+
60+
switch_pm_text (``str``, *optional*):
61+
If passed, clients will display a button with specified text that switches the user to a private chat
62+
with the bot and sends the bot a start message with the parameter switch_pm_parameter
63+
64+
switch_pm_parameter (``str``, *optional*):
65+
`Deep-linking <https://core.telegram.org/bots#deep-linking>`_ parameter for the /start message sent to
66+
the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
67+
68+
Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube
69+
account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account"
70+
button above the results, or even before showing any. The user presses the button, switches to a private
71+
chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth
72+
link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat
73+
where they wanted to use the bot's inline capabilities.
74+
75+
Returns:
76+
On success, True is returned.
77+
"""
3578
return self.send(
3679
functions.messages.SetInlineBotResults(
3780
query_id=int(inline_query_id),

pyrogram/client/types/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from .bots import (
20-
CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
21-
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineQuery, InlineQueryResult,
22-
InlineQueryResultArticle, InlineQueryResultPhoto, InlineQueryResultCachedAudio
23-
)
2419
from .bots import (
2520
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
2621
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame,
27-
GameHighScore, GameHighScores
22+
GameHighScore, GameHighScores, CallbackQuery
23+
)
24+
from .inline_mode import (
25+
InlineQuery, InlineQueryResult, InlineQueryResultArticle
2826
)
2927
from .input_media import (
3028
InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto,
31-
InputMediaDocument, InputMediaAnimation, InputMessageContent, InputTextMessageContent
29+
InputMediaDocument, InputMediaAnimation
30+
)
31+
from .input_message_content import (
32+
InputMessageContent, InputTextMessageContent
3233
)
3334
from .messages_and_media import (
3435
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,

pyrogram/client/types/bots/__init__.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,6 @@
2323
from .game_high_scores import GameHighScores
2424
from .inline_keyboard_button import InlineKeyboardButton
2525
from .inline_keyboard_markup import InlineKeyboardMarkup
26-
from .inline_query import InlineQuery
27-
from .inline_query_result import InlineQueryResult
28-
from .inline_query_result_article import InlineQueryResultArticle
29-
from .inline_query_result_audio import InlineQueryResultAudio
30-
from .inline_query_result_cached_audio import InlineQueryResultCachedAudio
31-
from .inline_query_result_cached_document import InlineQueryResultCachedDocument
32-
from .inline_query_result_cached_gif import InlineQueryResultCachedGif
33-
from .inline_query_result_cached_mpeg4_gif import InlineQueryResultCachedMpeg4Gif
34-
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
35-
from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker
36-
from .inline_query_result_cached_video import InlineQueryResultCachedVideo
37-
from .inline_query_result_cached_voice import InlineQueryResultCachedVoice
38-
from .inline_query_result_contact import InlineQueryResultContact
39-
from .inline_query_result_document import InlineQueryResultDocument
40-
from .inline_query_result_game import InlineQueryResultGame
41-
from .inline_query_result_gif import InlineQueryResultGif
42-
from .inline_query_result_location import InlineQueryResultLocation
43-
from .inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif
44-
from .inline_query_result_photo import InlineQueryResultPhoto
45-
from .inline_query_result_venue import InlineQueryResultVenue
46-
from .inline_query_result_video import InlineQueryResultVideo
47-
from .inline_query_result_voice import InlineQueryResultVoice
4826
from .keyboard_button import KeyboardButton
4927
from .reply_keyboard_markup import ReplyKeyboardMarkup
5028
from .reply_keyboard_remove import ReplyKeyboardRemove
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from .inline_query import InlineQuery
20+
from .inline_query_result import InlineQueryResult
21+
from .inline_query_result_article import InlineQueryResultArticle

pyrogram/client/types/bots/inline_query.py renamed to pyrogram/client/types/inline_mode/inline_query.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020

2121
import pyrogram
2222
from pyrogram.api import types
23-
from ..bots.inline_query_result import InlineQueryResult
23+
from .inline_query_result import InlineQueryResult
2424
from ..messages_and_media import Location
2525
from ..pyrogram_type import PyrogramType
26+
from ..update import Update
2627
from ..user_and_chats import User
2728

2829

29-
class InlineQuery(PyrogramType):
30+
class InlineQuery(PyrogramType, Update):
3031
"""This object represents an incoming inline query.
31-
When the user sends an empty query, your bot could return some default or trending results
32+
When the user sends an empty query, your bot could return some default or trending results.
3233
3334
Args:
3435
id (``str``):
@@ -50,6 +51,7 @@ class InlineQuery(PyrogramType):
5051

5152
def __init__(
5253
self,
54+
*,
5355
client: "pyrogram.client.ext.BaseClient",
5456
id: str,
5557
from_user: User,
@@ -69,7 +71,6 @@ def __init__(
6971
@staticmethod
7072
def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery":
7173
return InlineQuery(
72-
client=client,
7374
id=str(inline_query.query_id),
7475
from_user=User._parse(client, users[inline_query.user_id]),
7576
query=inline_query.query,
@@ -78,7 +79,8 @@ def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "In
7879
longitude=inline_query.geo.long,
7980
latitude=inline_query.geo.lat,
8081
client=client
81-
) if inline_query.geo else None
82+
) if inline_query.geo else None,
83+
client=client
8284
)
8385

8486
def answer(
@@ -90,6 +92,55 @@ def answer(
9092
switch_pm_text: str = "",
9193
switch_pm_parameter: str = ""
9294
):
95+
"""Bound method *answer* of :obj:`InlineQuery <pyrogram.InlineQuery>`.
96+
97+
Use this method as a shortcut for:
98+
99+
.. code-block:: python
100+
101+
client.answer_inline_query(
102+
inline_query.id,
103+
results=[...]
104+
)
105+
106+
Example:
107+
.. code-block:: python
108+
109+
inline_query.answer([...])
110+
111+
Args:
112+
results (List of :obj:`InlineQueryResult <pyrogram.InlineQueryResult>`):
113+
A list of results for the inline query.
114+
115+
cache_time (``int``, *optional*):
116+
The maximum amount of time in seconds that the result of the inline query may be cached on the server.
117+
Defaults to 300.
118+
119+
is_personal (``bool``, *optional*):
120+
Pass True, if results may be cached on the server side only for the user that sent the query.
121+
By default, results may be returned to any user who sends the same query.
122+
123+
next_offset (``str``, *optional*):
124+
Pass the offset that a client should send in the next query with the same text to receive more results.
125+
Pass an empty string if there are no more results or if you don‘t support pagination.
126+
Offset length can’t exceed 64 bytes.
127+
128+
switch_pm_text (``str``, *optional*):
129+
If passed, clients will display a button with specified text that switches the user to a private chat
130+
with the bot and sends the bot a start message with the parameter switch_pm_parameter
131+
132+
switch_pm_parameter (``str``, *optional*):
133+
`Deep-linking <https://core.telegram.org/bots#deep-linking>`_ parameter for the /start message sent to
134+
the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
135+
136+
Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube
137+
account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account"
138+
button above the results, or even before showing any. The user presses the button, switches to a private
139+
chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth
140+
link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat
141+
where they wanted to use the bot's inline capabilities.
142+
"""
143+
93144
return self._client.answer_inline_query(
94145
inline_query_id=self.id,
95146
results=results,

pyrogram/client/types/bots/inline_query_result.py renamed to pyrogram/client/types/inline_mode/inline_query_result.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from ..pyrogram_type import PyrogramType
1920

20-
class InlineQueryResult:
21-
"""This object represents one result of an inline query.
22-
Pyrogram currently supports results of the following 20 types:
23-
24-
- :obj:`InlineQueryResultCachedAudio`
21+
"""- :obj:`InlineQueryResultCachedAudio`
2522
- :obj:`InlineQueryResultCachedDocument`
2623
- :obj:`InlineQueryResultCachedGif`
2724
- :obj:`InlineQueryResultCachedMpeg4Gif`
2825
- :obj:`InlineQueryResultCachedPhoto`
2926
- :obj:`InlineQueryResultCachedSticker`
3027
- :obj:`InlineQueryResultCachedVideo`
3128
- :obj:`InlineQueryResultCachedVoice`
32-
- :obj:`InlineQueryResultArticle`
3329
- :obj:`InlineQueryResultAudio`
3430
- :obj:`InlineQueryResultContact`
3531
- :obj:`InlineQueryResultGame`
@@ -40,9 +36,24 @@ class InlineQueryResult:
4036
- :obj:`InlineQueryResultPhoto`
4137
- :obj:`InlineQueryResultVenue`
4238
- :obj:`InlineQueryResultVideo`
43-
- :obj:`InlineQueryResultVoice`
39+
- :obj:`InlineQueryResultVoice`"""
40+
41+
42+
class InlineQueryResult(PyrogramType):
43+
"""This object represents one result of an inline query.
44+
45+
Pyrogram currently supports results of the following 20 types:
46+
47+
- :obj:`InlineQueryResultArticle`
4448
"""
4549

50+
__slots__ = ["type", "id"]
51+
4652
def __init__(self, type: str, id: str):
53+
super().__init__(None)
54+
4755
self.type = type
4856
self.id = id
57+
58+
def write(self):
59+
pass

0 commit comments

Comments
 (0)