From 4e07712b041f12092606c18baae67ac74b7697a7 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 15 Sep 2018 10:45:15 +0200 Subject: [PATCH] Return new .web_preview's .photo/.document if present in Message --- telethon/tl/custom/message.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 7f8771da..687e8b46 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -356,6 +356,10 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC): return self.media.photo elif isinstance(self.action, types.MessageActionChatEditPhoto): return self.action.photo + else: + web = self.web_preview + if web and isinstance(web.photo, types.Photo): + return web.photo @property def document(self): @@ -366,6 +370,16 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC): if isinstance(self.media, types.MessageMediaDocument): if isinstance(self.media.document, types.Document): return self.media.document + else: + web = self.web_preview + if web and isinstance(web.photo, types.Document): + return web.photo + + @property + def web_preview(self): + if isinstance(self.media, types.MessageMediaWebPage): + if isinstance(self.media.webpage, types.WebPage): + return self.media.webpage @property def audio(self):