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 # Need to upload the media first, but only if they're not cached yet
media = [] media = []
for file in files: for file in files:
# fh will either be InputPhoto or a modified InputFile # Albums want :tl:`InputMedia` which, in theory, includes
fh = await self.upload_file(file, use_cache=types.InputPhoto) # :tl:`InputMediaUploadedPhoto`. However using that will
if not isinstance(fh, types.InputPhoto): # 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( r = await self(functions.messages.UploadMediaRequest(
entity, media=types.InputMediaUploadedPhoto(fh) entity, media=fm
)) ))
input_photo = utils.get_input_photo(r.photo) fm = utils.get_input_photo(r.photo)
self.session.cache_file(fh.md5, fh.size, input_photo) self.session.cache_file(fh.md5, fh.size, fm)
fh = input_photo fm = types.InputMediaPhoto(fm)
if captions: if captions:
caption, msg_entities = captions.pop() caption, msg_entities = captions.pop()
else: else:
caption, msg_entities = '', None caption, msg_entities = '', None
media.append(types.InputSingleMedia( media.append(types.InputSingleMedia(
types.InputMediaPhoto(fh), fm,
message=caption, message=caption,
entities=msg_entities 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. 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): def is_gif(file):