mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Create a new Message.file property (#1168)
This commit is contained in:
@@ -3,9 +3,11 @@ from .chatgetter import ChatGetter
|
||||
from .sendergetter import SenderGetter
|
||||
from .messagebutton import MessageButton
|
||||
from .forward import Forward
|
||||
from .file import File
|
||||
from .. import TLObject, types, functions
|
||||
from ... import utils, errors
|
||||
|
||||
|
||||
# TODO Figure out a way to have the code generator error on missing fields
|
||||
# Maybe parsing the init function alone if that's possible.
|
||||
class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||
@@ -174,8 +176,10 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||
self.action = action
|
||||
|
||||
# Convenient storage for custom functions
|
||||
# TODO This is becoming a bit of bloat
|
||||
self._client = None
|
||||
self._text = None
|
||||
self._file = None
|
||||
self._reply_message = None
|
||||
self._buttons = None
|
||||
self._buttons_flat = None
|
||||
@@ -370,6 +374,25 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||
|
||||
return self._buttons_count
|
||||
|
||||
@property
|
||||
def file(self):
|
||||
"""
|
||||
Returns a `File <telethon.tl.custom.file.File>` wrapping the
|
||||
`photo` or `document` in this message. If the media type is different
|
||||
(polls, games, none, etc.), this property will be ``None``.
|
||||
|
||||
This instance lets you easily access other properties, such as
|
||||
`file.id <telethon.tl.custom.file.File.id>`,
|
||||
`file.name <telethon.tl.custom.file.File.name>`,
|
||||
etc., without having to manually inspect the ``document.attributes``.
|
||||
"""
|
||||
if not self._file:
|
||||
media = self.photo or self.document
|
||||
if media:
|
||||
self._file = File(media)
|
||||
|
||||
return self._file
|
||||
|
||||
@property
|
||||
def photo(self):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user