From b8d656efa50341ee935a76d9d380dfd0b7f7ce11 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 4 Jun 2024 22:00:49 +0200 Subject: [PATCH] Add events.Raw --- .../telethon/_impl/client/events/__init__.py | 3 +- .../src/telethon/_impl/client/events/event.py | 28 +++++++++++++++++++ client/src/telethon/events/__init__.py | 3 ++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/client/src/telethon/_impl/client/events/__init__.py b/client/src/telethon/_impl/client/events/__init__.py index e386f413..2eb200d6 100644 --- a/client/src/telethon/_impl/client/events/__init__.py +++ b/client/src/telethon/_impl/client/events/__init__.py @@ -1,10 +1,11 @@ -from .event import Continue, Event +from .event import Continue, Event, Raw from .messages import MessageDeleted, MessageEdited, MessageRead, NewMessage from .queries import ButtonCallback, InlineQuery __all__ = [ "Continue", "Event", + "Raw", "MessageDeleted", "MessageEdited", "MessageRead", diff --git a/client/src/telethon/_impl/client/events/event.py b/client/src/telethon/_impl/client/events/event.py index c19962ee..9a2ef406 100644 --- a/client/src/telethon/_impl/client/events/event.py +++ b/client/src/telethon/_impl/client/events/event.py @@ -30,6 +30,34 @@ class Event(metaclass=NoPublicConstructor): pass +class Raw(Event): + """ + Raw update type received from Telegram. + + This event occurs when *any* update is received. + + Like every other event, the raw update type is under the private member ``event._raw``. + + Additionally, all peers received along with this update are present under ``self._chat_map``. + """ + + def __init__( + self, + client: Client, + update: abcs.Update, + chat_map: dict[int, Peer], + ): + self._client = client + self._raw = update + self._chat_map = chat_map + + @classmethod + def _try_from_update( + cls, client: Client, update: abcs.Update, chat_map: dict[int, Peer] + ) -> Optional[Self]: + return cls._create(client, update, chat_map) + + class Continue: """ This is **not** an event type you can listen to. diff --git a/client/src/telethon/events/__init__.py b/client/src/telethon/events/__init__.py index c8c04910..7f62dc85 100644 --- a/client/src/telethon/events/__init__.py +++ b/client/src/telethon/events/__init__.py @@ -5,6 +5,7 @@ Classes related to the different event types that wrap incoming Telegram updates The :doc:`/concepts/updates` concept to learn how to listen to these events. """ + from .._impl.client.events import ( ButtonCallback, Continue, @@ -14,6 +15,7 @@ from .._impl.client.events import ( MessageEdited, MessageRead, NewMessage, + Raw, ) __all__ = [ @@ -25,4 +27,5 @@ __all__ = [ "MessageEdited", "MessageRead", "NewMessage", + "Raw", ]