Fix sending albums with bot file IDs

This commit is contained in:
Lonami Exo 2019-02-25 18:23:39 +01:00
parent 70b08c4952
commit 8e36c0002b
2 changed files with 16 additions and 9 deletions

View File

@ -293,22 +293,25 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
# Need to upload the media first, but only if they're not cached yet
media = []
for file in files:
# fh will either be InputPhoto or a modified InputFile
fh = await self.upload_file(file, use_cache=types.InputPhoto)
if not isinstance(fh, types.InputPhoto):
# Albums want :tl:`InputMedia` which, in theory, includes
# :tl:`InputMediaUploadedPhoto`. However using that will
# make it `raise MediaInvalidError`, so we need to upload
# it as media and then convert that to :tl:`InputMediaPhoto`.
fh, fm = await self._file_to_media(file)
if isinstance(fm, types.InputMediaUploadedPhoto):
r = await self(functions.messages.UploadMediaRequest(
entity, media=types.InputMediaUploadedPhoto(fh)
entity, media=fm
))
input_photo = utils.get_input_photo(r.photo)
self.session.cache_file(fh.md5, fh.size, input_photo)
fh = input_photo
fm = utils.get_input_photo(r.photo)
self.session.cache_file(fh.md5, fh.size, fm)
fm = types.InputMediaPhoto(fm)
if captions:
caption, msg_entities = captions.pop()
else:
caption, msg_entities = '', None
media.append(types.InputSingleMedia(
types.InputMediaPhoto(fh),
fm,
message=caption,
entities=msg_entities
))

View File

@ -662,7 +662,11 @@ def is_image(file):
"""
Returns ``True`` if the file extension looks like an image file to Telegram.
"""
return re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE)
match = re.match(r'\.(png|jpe?g)', _get_extension(file), re.IGNORECASE)
if match:
return True
else:
return isinstance(resolve_bot_file_id(file), types.Photo)
def is_gif(file):