mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-23 19:34:24 +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
|
# 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
|
||||||
))
|
))
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user