Fix MessageAction not allowing access to media

This caused some issues with events.MessageEdited because
some MessageAction can trigger these edit updates such as
scoring in a game.
This commit is contained in:
Lonami Exo 2018-07-03 14:13:44 +02:00
parent 43afdb9d77
commit 44630542d0

View File

@ -430,16 +430,27 @@ class Message:
return self._buttons_count or 0 return self._buttons_count or 0
@property
def media(self):
"""
Returns the media of the message.
"""
if isinstance(self.original_message, types.Message):
return self.original_message.media
elif isinstance(self.original_message, types.MessageService):
action = self.original_message.action
if isinstance(action, types.MessageActionChatEditPhoto):
return types.MessageMediaPhoto(action.photo)
@property @property
def photo(self): def photo(self):
""" """
If the message media is a photo, If the message media is a photo,
this returns the :tl:`Photo` object. this returns the :tl:`Photo` object.
""" """
if isinstance(self.original_message.media, types.MessageMediaPhoto): if isinstance(self.media, types.MessageMediaPhoto):
photo = self.original_message.media.photo if isinstance(self.media.photo, types.Photo):
if isinstance(photo, types.Photo): return self.media.photo
return photo
@property @property
def document(self): def document(self):
@ -447,10 +458,9 @@ class Message:
If the message media is a document, If the message media is a document,
this returns the :tl:`Document` object. this returns the :tl:`Document` object.
""" """
if isinstance(self.original_message.media, types.MessageMediaDocument): if isinstance(self.media, types.MessageMediaDocument):
doc = self.original_message.media.document if isinstance(self.media.document, types.Document):
if isinstance(doc, types.Document): return self.media.document
return doc
def _document_by_attribute(self, kind, condition=None): def _document_by_attribute(self, kind, condition=None):
""" """