mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-13 04:56:35 +03:00
parent
f326769fa8
commit
e5a5ac5943
|
@ -123,7 +123,6 @@ class MessageParseMethods:
|
||||||
|
|
||||||
random_to_id = {}
|
random_to_id = {}
|
||||||
id_to_message = {}
|
id_to_message = {}
|
||||||
sched_to_message = {} # scheduled IDs may collide with normal IDs
|
|
||||||
for update in updates:
|
for update in updates:
|
||||||
if isinstance(update, types.UpdateMessageID):
|
if isinstance(update, types.UpdateMessageID):
|
||||||
random_to_id[update.random_id] = update.id
|
random_to_id[update.random_id] = update.id
|
||||||
|
@ -164,7 +163,10 @@ class MessageParseMethods:
|
||||||
|
|
||||||
elif isinstance(update, types.UpdateNewScheduledMessage):
|
elif isinstance(update, types.UpdateNewScheduledMessage):
|
||||||
update.message._finish_init(self, entities, input_chat)
|
update.message._finish_init(self, entities, input_chat)
|
||||||
sched_to_message[update.message.id] = update.message
|
# Scheduled IDs may collide with normal IDs. However, for a
|
||||||
|
# single request there *shouldn't* be a mix between "some
|
||||||
|
# scheduled and some not".
|
||||||
|
id_to_message[update.message.id] = update.message
|
||||||
|
|
||||||
elif isinstance(update, types.UpdateMessagePoll):
|
elif isinstance(update, types.UpdateMessagePoll):
|
||||||
if request.media.poll.id == update.poll_id:
|
if request.media.poll.id == update.poll_id:
|
||||||
|
@ -182,17 +184,6 @@ class MessageParseMethods:
|
||||||
if request is None:
|
if request is None:
|
||||||
return id_to_message
|
return id_to_message
|
||||||
|
|
||||||
# Use the scheduled mapping if we got a request with a scheduled message
|
|
||||||
#
|
|
||||||
# This breaks if the schedule date is too young, however, since the message
|
|
||||||
# is sent immediately, so have a fallback.
|
|
||||||
if getattr(request, 'schedule_date', None) is None:
|
|
||||||
mapping = id_to_message
|
|
||||||
opposite = {} # if there's no schedule it can never be scheduled
|
|
||||||
else:
|
|
||||||
mapping = sched_to_message
|
|
||||||
opposite = id_to_message # scheduled may be treated as normal, though
|
|
||||||
|
|
||||||
random_id = request if isinstance(request, (int, list)) else getattr(request, 'random_id', None)
|
random_id = request if isinstance(request, (int, list)) else getattr(request, 'random_id', None)
|
||||||
if random_id is None:
|
if random_id is None:
|
||||||
# Can happen when pinning a message does not actually produce a service message.
|
# Can happen when pinning a message does not actually produce a service message.
|
||||||
|
@ -201,9 +192,7 @@ class MessageParseMethods:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not utils.is_list_like(random_id):
|
if not utils.is_list_like(random_id):
|
||||||
msg = mapping.get(random_to_id.get(random_id))
|
msg = id_to_message.get(random_to_id.get(random_id))
|
||||||
if not msg:
|
|
||||||
msg = opposite.get(random_to_id.get(random_id))
|
|
||||||
|
|
||||||
if not msg:
|
if not msg:
|
||||||
self._log[__name__].warning(
|
self._log[__name__].warning(
|
||||||
|
@ -212,24 +201,21 @@ class MessageParseMethods:
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return [mapping[random_to_id[rnd]] for rnd in random_id]
|
return [id_to_message[random_to_id[rnd]] for rnd in random_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
# Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets
|
||||||
return [opposite[random_to_id[rnd]] for rnd in random_id]
|
# deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at
|
||||||
except KeyError:
|
# Telegram), in which case we get some "missing" message mappings.
|
||||||
# Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets
|
# Log them with the hope that we can better work around them.
|
||||||
# deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at
|
#
|
||||||
# Telegram), in which case we get some "missing" message mappings.
|
# This also happens when trying to forward messages that can't
|
||||||
# Log them with the hope that we can better work around them.
|
# be forwarded because they don't exist (0, service, deleted)
|
||||||
#
|
# among others which could be (like deleted or existing).
|
||||||
# This also happens when trying to forward messages that can't
|
self._log[__name__].warning(
|
||||||
# be forwarded because they don't exist (0, service, deleted)
|
'Request %s had missing message mappings %s', request, result)
|
||||||
# among others which could be (like deleted or existing).
|
|
||||||
self._log[__name__].warning(
|
|
||||||
'Request %s had missing message mappings %s', request, result)
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
(mapping.get(random_to_id[rnd]) or opposite.get(random_to_id[rnd]))
|
id_to_message.get(random_to_id[rnd])
|
||||||
if rnd in random_to_id
|
if rnd in random_to_id
|
||||||
else None
|
else None
|
||||||
for rnd in random_id
|
for rnd in random_id
|
||||||
|
|
Loading…
Reference in New Issue
Block a user