diff --git a/telethon/client/updates.py b/telethon/client/updates.py index 72992044..4a9cb2b3 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -291,22 +291,22 @@ class UpdateMethods: entities = {utils.get_peer_id(x): x for x in itertools.chain(update.users, update.chats)} for u in update.updates: - self._process_update(u, entities) + self._process_update(u, update.updates, entities=entities) elif isinstance(update, types.UpdateShort): - self._process_update(update.update) + self._process_update(update.update, None) else: - self._process_update(update) + self._process_update(update, None) self._state_cache.update(update) - def _process_update(self: 'TelegramClient', update, entities=None): + def _process_update(self: 'TelegramClient', update, others, entities=None): update._entities = entities or {} # This part is somewhat hot so we don't bother patching # update with channel ID/its state. Instead we just pass # arguments which is faster. channel_id = self._state_cache.get_channel_id(update) - args = (update, channel_id, self._state_cache[channel_id]) + args = (update, others, channel_id, self._state_cache[channel_id]) if self._dispatching_updates_queue is None: task = self._loop.create_task(self._dispatch_update(*args)) self._updates_queue.add(task) @@ -370,7 +370,7 @@ class UpdateMethods: self._dispatching_updates_queue.clear() - async def _dispatch_update(self: 'TelegramClient', update, channel_id, pts_date): + async def _dispatch_update(self: 'TelegramClient', update, others, channel_id, pts_date): if not self._entity_cache.ensure_cached(update): # We could add a lock to not fetch the same pts twice if we are # already fetching it. However this does not happen in practice, @@ -380,7 +380,7 @@ class UpdateMethods: # For example, UpdateUserStatus or UpdateChatUserTyping. await self._get_difference(update, channel_id, pts_date) - built = EventBuilderDict(self, update) + built = EventBuilderDict(self, update, others) for conv_set in self._conversations.values(): for conv in conv_set: ev = built[events.NewMessage] @@ -527,15 +527,16 @@ class EventBuilderDict: """ Helper "dictionary" to return events from types and cache them. """ - def __init__(self, client: 'TelegramClient', update): + def __init__(self, client: 'TelegramClient', update, others): self.client = client self.update = update + self.others = others def __getitem__(self, builder): try: return self.__dict__[builder] except KeyError: - event = self.__dict__[builder] = builder.build(self.update) + event = self.__dict__[builder] = builder.build(self.update, self.others) if isinstance(event, EventCommon): event.original_update = self.update event._entities = self.update._entities diff --git a/telethon/events/callbackquery.py b/telethon/events/callbackquery.py index 46a50eb6..891815e7 100644 --- a/telethon/events/callbackquery.py +++ b/telethon/events/callbackquery.py @@ -45,7 +45,7 @@ class CallbackQuery(EventBuilder): raise TypeError('Invalid data type given') @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateBotCallbackQuery): return cls.Event(update, update.peer, update.msg_id) elif isinstance(update, types.UpdateInlineBotCallbackQuery): diff --git a/telethon/events/chataction.py b/telethon/events/chataction.py index 79ac1f42..5d9b28af 100644 --- a/telethon/events/chataction.py +++ b/telethon/events/chataction.py @@ -9,7 +9,7 @@ class ChatAction(EventBuilder): Occurs whenever a user joins or leaves a chat, or a message is pinned. """ @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateChannelPinnedMessage) and update.id == 0: # Telegram does not always send # UpdateChannelPinnedMessage for new pins diff --git a/telethon/events/common.py b/telethon/events/common.py index 32ea0cf6..6181f0b0 100644 --- a/telethon/events/common.py +++ b/telethon/events/common.py @@ -77,7 +77,7 @@ class EventBuilder(abc.ABC): @classmethod @abc.abstractmethod - def build(cls, update): + def build(cls, update, others=None): """ Builds an event for the given update if possible, or returns None. diff --git a/telethon/events/inlinequery.py b/telethon/events/inlinequery.py index a97d2026..13fc5de8 100644 --- a/telethon/events/inlinequery.py +++ b/telethon/events/inlinequery.py @@ -46,7 +46,7 @@ class InlineQuery(EventBuilder): raise TypeError('Invalid pattern type given') @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateBotInlineQuery): return cls.Event(update) diff --git a/telethon/events/messagedeleted.py b/telethon/events/messagedeleted.py index 92ee9332..aa6ba177 100644 --- a/telethon/events/messagedeleted.py +++ b/telethon/events/messagedeleted.py @@ -25,7 +25,7 @@ class MessageDeleted(EventBuilder): unless you intend on working with channels and super-groups only. """ @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateDeleteMessages): return cls.Event( deleted_ids=update.messages, diff --git a/telethon/events/messageedited.py b/telethon/events/messageedited.py index bcdc084c..382b9ade 100644 --- a/telethon/events/messageedited.py +++ b/telethon/events/messageedited.py @@ -33,7 +33,7 @@ class MessageEdited(NewMessage): not you). """ @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, (types.UpdateEditMessage, types.UpdateEditChannelMessage)): return cls.Event(update.message) diff --git a/telethon/events/messageread.py b/telethon/events/messageread.py index d3bae43d..3f71917c 100644 --- a/telethon/events/messageread.py +++ b/telethon/events/messageread.py @@ -20,7 +20,7 @@ class MessageRead(EventBuilder): self.inbox = inbox @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateReadHistoryInbox): return cls.Event(update.peer, update.max_id, False) elif isinstance(update, types.UpdateReadHistoryOutbox): diff --git a/telethon/events/newmessage.py b/telethon/events/newmessage.py index cfda9624..ad71c34a 100644 --- a/telethon/events/newmessage.py +++ b/telethon/events/newmessage.py @@ -76,7 +76,7 @@ class NewMessage(EventBuilder): self.from_users = await _into_id_set(client, self.from_users) @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): if not isinstance(update.message, types.Message): diff --git a/telethon/events/raw.py b/telethon/events/raw.py index cd4c80a9..82b64b96 100644 --- a/telethon/events/raw.py +++ b/telethon/events/raw.py @@ -32,7 +32,7 @@ class Raw(EventBuilder): self.resolved = True @classmethod - def build(cls, update): + def build(cls, update, others=None): return update def filter(self, event): diff --git a/telethon/events/userupdate.py b/telethon/events/userupdate.py index 647a3bc2..278115bc 100644 --- a/telethon/events/userupdate.py +++ b/telethon/events/userupdate.py @@ -12,7 +12,7 @@ class UserUpdate(EventBuilder): Occurs whenever a user goes online, starts typing, etc. """ @classmethod - def build(cls, update): + def build(cls, update, others=None): if isinstance(update, types.UpdateUserStatus): return cls.Event(update.user_id, status=update.status) diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index ac61fe97..6b5f6585 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -551,7 +551,6 @@ class MTProtoSender: self._log.debug('Handling update %s', message.obj.__class__.__name__) if self._update_callback: - print(message.obj.stringify()) self._update_callback(message.obj) async def _handle_pong(self, message):