mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Handle more key errors on forward message
This commit is contained in:
parent
a71b095c1d
commit
a4c2e45d6d
|
@ -142,18 +142,23 @@ class MessageParseMethods(UserMethods):
|
|||
|
||||
random_id = request if isinstance(request, int) else request.random_id
|
||||
if not utils.is_list_like(random_id):
|
||||
if random_id in random_to_id:
|
||||
return id_to_message[random_to_id[random_id]]
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
# ``rnd in random_to_id`` is needed because trying to forward only
|
||||
# deleted messages causes `MESSAGE_ID_INVALID`, but forwarding
|
||||
# valid and invalid messages in the same call makes the call
|
||||
# succeed, although the API won't return those messages thus
|
||||
# `random_to_id[rnd]` would `KeyError`.
|
||||
return [id_to_message[random_to_id[rnd]]
|
||||
if rnd in random_to_id else None
|
||||
for rnd in random_id]
|
||||
msg = id_to_message.get(random_to_id.get(random_id))
|
||||
if not msg:
|
||||
self._log[__name__].warning(
|
||||
'Request %s had missing message mapping %s', request, result)
|
||||
|
||||
return msg
|
||||
|
||||
try:
|
||||
return [id_to_message[random_to_id[rnd]] for rnd in random_id]
|
||||
except KeyError:
|
||||
# Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets
|
||||
# deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at
|
||||
# Telegram), in which case we get some "missing" message mappings.
|
||||
# Log them with the hope that we can better work around them.
|
||||
self._log[__name__].warning(
|
||||
'Request %s had missing message mappings %s', request, result)
|
||||
|
||||
return [id_to_message.get(random_to_id.get(rnd)) for rnd in random_to_id]
|
||||
|
||||
# endregion
|
||||
|
|
|
@ -270,4 +270,5 @@ WALLPAPER_INVALID,400,The input wallpaper was not valid
|
|||
WC_CONVERT_URL_INVALID,400,WC convert URL invalid
|
||||
WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL
|
||||
WEBPAGE_MEDIA_EMPTY,400,Webpage media empty
|
||||
WORKER_BUSY_TOO_LONG_RETRY,500,Telegram workers are too busy to respond immediately
|
||||
YOU_BLOCKED_USER,400,You blocked this user
|
||||
|
|
|
Loading…
Reference in New Issue
Block a user