From 9a0d6b9931be92e7690c5d5c7c54c0fcd6a3d09a Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 10 Aug 2020 16:09:39 +0200 Subject: [PATCH] Don't set force_file on force_document with images Otherwise, Telegram won't analyze the image and won't add it the DocumentAttributeImageSize, causing some bots like t.me/Stickers to break. Closes #1507. --- telethon/client/uploads.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/telethon/client/uploads.py b/telethon/client/uploads.py index 2cf636dc..c46c2899 100644 --- a/telethon/client/uploads.py +++ b/telethon/client/uploads.py @@ -687,8 +687,9 @@ class UploadMethods: if isinstance(file, pathlib.Path): file = str(file.absolute()) + is_image = utils.is_image(file) if as_image is None: - as_image = utils.is_image(file) and not force_document + as_image = is_image and not force_document # `aiofiles` do not base `io.IOBase` but do have `read`, so we # just check for the read attribute to see if it's file-like. @@ -749,7 +750,7 @@ class UploadMethods: file, mime_type=mime_type, attributes=attributes, - force_document=force_document, + force_document=force_document and not is_image, voice_note=voice_note, video_note=video_note, supports_streaming=supports_streaming @@ -767,7 +768,7 @@ class UploadMethods: mime_type=mime_type, attributes=attributes, thumb=thumb, - force_file=force_document + force_file=force_document and not is_image ) return file_handle, media, as_image