Handle timeouts when getting answers from inline bots

This commit is contained in:
Dan 2018-05-05 19:42:38 +02:00
parent 553e7f714c
commit 9f3f4099d5

View File

@ -45,7 +45,7 @@ from pyrogram.api.errors import (
PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded, PhoneCodeExpired, PhoneCodeEmpty, SessionPasswordNeeded,
PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing, PasswordHashInvalid, FloodWait, PeerIdInvalid, FilePartMissing,
ChatAdminRequired, FirstnameInvalid, PhoneNumberBanned, ChatAdminRequired, FirstnameInvalid, PhoneNumberBanned,
VolumeLocNotFound, UserMigrate, FileIdInvalid) VolumeLocNotFound, UserMigrate, FileIdInvalid, UnknownError)
from pyrogram.crypto import AES from pyrogram.crypto import AES
from pyrogram.session import Auth, Session from pyrogram.session import Auth, Session
from pyrogram.session.internals import MsgId from pyrogram.session.internals import MsgId
@ -3586,18 +3586,27 @@ class Client:
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
return self.send( # TODO: Split location parameter into lat and long
functions.messages.GetInlineBotResults(
bot=self.resolve_peer(bot), try:
peer=types.InputPeerSelf(), return self.send(
query=query, functions.messages.GetInlineBotResults(
offset=offset, bot=self.resolve_peer(bot),
geo_point=types.InputGeoPoint( peer=types.InputPeerSelf(),
lat=location[0], query=query,
long=location[1] offset=offset,
) if location else None geo_point=types.InputGeoPoint(
lat=location[0],
long=location[1]
) if location else None
)
) )
) except UnknownError as e:
# TODO: Add this -503 Timeout error into the Error DB
if e.x.error_code == -503 and e.x.error_message == "Timeout":
raise TimeoutError("The inline bot didn't answer in time") from None
else:
raise e
def send_inline_bot_result(self, def send_inline_bot_result(self,
chat_id: int or str, chat_id: int or str,
@ -3807,5 +3816,3 @@ class Client:
r = self.send(functions.messages.GetFullChat(peer.chat_id)) r = self.send(functions.messages.GetFullChat(peer.chat_id))
return utils.parse_chat_full(self, r) return utils.parse_chat_full(self, r)