Skip to content

Commit fede743

Browse files
committed
Fix inline-mode branch breaking after many commits from develop
1 parent acbbfab commit fede743

File tree

5 files changed

+81
-23
lines changed

5 files changed

+81
-23
lines changed

pyrogram/client/dispatcher/dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, client, workers: int):
8080
),
8181

8282
(types.UpdateBotInlineQuery,):
83-
lambda upd, usr, cht: (utils.parse_inline_query(self.client, upd, usr), InlineQueryHandler)
83+
lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler)
8484
}
8585

8686
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}

pyrogram/client/ext/base_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,6 @@ def get_chat_members(self, *args, **kwargs):
129129

130130
def get_chat_members_count(self, *args, **kwargs):
131131
pass
132+
133+
def answer_inline_query(self, *args, **kwargs):
134+
pass

pyrogram/client/methods/bots/answer_inline_query.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121

2222

2323
class AnswerInlineQuery(BaseClient):
24-
def answer_inline_query(self,
25-
inline_query_id: str,
26-
results: list,
27-
cache_time: int = 300,
28-
is_personal: bool = None,
29-
next_offset: str = "",
30-
switch_pm_text: str = "",
31-
switch_pm_parameter: str = ""):
24+
def answer_inline_query(
25+
self,
26+
inline_query_id: str,
27+
results: list,
28+
cache_time: int = 300,
29+
is_personal: bool = None,
30+
next_offset: str = "",
31+
switch_pm_text: str = "",
32+
switch_pm_parameter: str = ""
33+
):
3234
# TODO: Docs
3335
return self.send(
3436
functions.messages.SetInlineBotResults(
@@ -39,8 +41,8 @@ def answer_inline_query(self,
3941
private=is_personal or None,
4042
next_offset=next_offset or None,
4143
switch_pm=types.InlineBotSwitchPM(
42-
switch_pm_text,
43-
switch_pm_parameter
44+
text=switch_pm_text,
45+
start_param=switch_pm_parameter
4446
) if switch_pm_text else None
4547
)
4648
)

pyrogram/client/methods/decorators/on_inline_query.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +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 typing import Tuple
20+
1921
import pyrogram
2022
from pyrogram.client.filters.filter import Filter
23+
from pyrogram.client.handlers.handler import Handler
2124
from ...ext import BaseClient
2225

2326

2427
class OnInlineQuery(BaseClient):
25-
def on_inline_query(self, filters=None, group: int = 0):
28+
def on_inline_query(
29+
self=None,
30+
filters=None,
31+
group: int = 0
32+
) -> callable:
2633
"""Use this decorator to automatically register a function for handling
2734
inline queries. This does the same thing as :meth:`add_handler` using the
2835
:class:`InlineQueryHandler`.
@@ -36,7 +43,10 @@ def on_inline_query(self, filters=None, group: int = 0):
3643
The group identifier, defaults to 0.
3744
"""
3845

39-
def decorator(func):
46+
def decorator(func: callable) -> Tuple[Handler, int]:
47+
if isinstance(func, tuple):
48+
func = func[0].callback
49+
4050
handler = pyrogram.InlineQueryHandler(func, filters)
4151

4252
if isinstance(self, Filter):

pyrogram/client/types/bots/inline_query.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
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.api.core import Object
19+
from typing import List
2020

21+
import pyrogram
22+
from pyrogram.api import types
23+
from ..bots.inline_query_result import InlineQueryResult
24+
from ..messages_and_media import Location
25+
from ..pyrogram_type import PyrogramType
26+
from ..user_and_chats import User
2127

22-
class InlineQuery(Object):
28+
29+
class InlineQuery(PyrogramType):
2330
"""This object represents an incoming inline query.
2431
When the user sends an empty query, your bot could return some default or trending results
2532
@@ -39,20 +46,56 @@ class InlineQuery(Object):
3946
location (:obj:`Location <pyrogram.Location>`. *optional*):
4047
Sender location, only for bots that request user location.
4148
"""
42-
ID = 0xb0700032
49+
__slots__ = ["id", "from_user", "query", "offset", "location"]
4350

4451
def __init__(
45-
self,
46-
client,
47-
id: str,
48-
from_user,
49-
query: str,
50-
offset: str,
51-
location=None,
52+
self,
53+
client: "pyrogram.client.ext.BaseClient",
54+
id: str,
55+
from_user: User,
56+
query: str,
57+
offset: str,
58+
location: Location = None
5259
):
60+
super().__init__(client)
61+
5362
self._client = client
5463
self.id = id
5564
self.from_user = from_user
5665
self.query = query
5766
self.offset = offset
5867
self.location = location
68+
69+
@staticmethod
70+
def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery":
71+
return InlineQuery(
72+
client=client,
73+
id=str(inline_query.query_id),
74+
from_user=User._parse(client, users[inline_query.user_id]),
75+
query=inline_query.query,
76+
offset=inline_query.offset,
77+
location=Location(
78+
longitude=inline_query.geo.long,
79+
latitude=inline_query.geo.lat,
80+
client=client
81+
) if inline_query.geo else None
82+
)
83+
84+
def answer(
85+
self,
86+
results: List[InlineQueryResult],
87+
cache_time: int = 300,
88+
is_personal: bool = None,
89+
next_offset: str = "",
90+
switch_pm_text: str = "",
91+
switch_pm_parameter: str = ""
92+
):
93+
return self._client.answer_inline_query(
94+
inline_query_id=self.id,
95+
results=results,
96+
cache_time=cache_time,
97+
is_personal=is_personal,
98+
next_offset=next_offset,
99+
switch_pm_text=switch_pm_text,
100+
switch_pm_parameter=switch_pm_parameter
101+
)

0 commit comments

Comments
 (0)