2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 21:38:04 +00:00

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,6 +3586,9 @@ class Client:
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
# TODO: Split location parameter into lat and long
try:
return self.send( return self.send(
functions.messages.GetInlineBotResults( functions.messages.GetInlineBotResults(
bot=self.resolve_peer(bot), bot=self.resolve_peer(bot),
@ -3598,6 +3601,12 @@ class Client:
) if location else None ) 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)