From 51f5f1a83a1f0c0f6e587a11cd28d97c8038a1c2 Mon Sep 17 00:00:00 2001 From: kutocren <156922880+kutocren@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:02:48 +0000 Subject: [PATCH] add properties for sender and chat of replied-to message --- telethon/tl/custom/message.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 7f43f05f..72c05324 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -280,6 +280,8 @@ class Message(ChatGetter, SenderGetter, TLObject): SenderGetter.__init__(self, sender_id) self._forward = None + self._reply_to_chat = None + self._reply_to_sender = None def _finish_init(self, client, entities, input_chat): """ @@ -333,6 +335,13 @@ class Message(ChatGetter, SenderGetter, TLObject): self._linked_chat = entities.get(utils.get_peer_id( types.PeerChannel(self.replies.channel_id))) + if self.reply_to: + if self.reply_to.reply_to_peer_id: + self._reply_to_chat = entities.get(utils.get_peer_id(self.reply_to.reply_to_peer_id)) + if self.reply_to.reply_from: + if self.reply_to.reply_from.from_id: + self._reply_to_sender = entities.get(utils.get_peer_id(self.reply_to.reply_from.from_id)) + # endregion Initialization @@ -408,6 +417,22 @@ class Message(ChatGetter, SenderGetter, TLObject): """ return self._forward + @property + def reply_to_chat(self): + """ + The :tl:`Channel` in which the replied-to message was sent, + if this message is a reply in another chat + """ + return self._reply_to_chat + + @property + def reply_to_sender(self): + """ + The :tl:`User`, :tl:`Channel`, or whatever other entity that + sent the replied-to message, if this message is a reply in another chat. + """ + return self._reply_to_sender + @property def buttons(self): """