mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-22 19:04:20 +03:00
Fix sending albums with bot file IDs
This commit is contained in:
parent
70b08c4952
commit
8e36c0002b
|
@ -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
|
||||
))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user