Fixed branching logic in _file_to_media

This commit is contained in:
YeeChanKo 2018-08-06 20:07:28 +09:00 committed by GitHub
parent e6e33bb434
commit 8c82b3afa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -394,26 +394,29 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
as_image = utils.is_image(file) and not force_document
use_cache = types.InputPhoto if as_image else types.InputDocument
if re.match('https?://', file):
if as_image:
media = types.InputMediaPhotoExternal(file)
elif not force_document and utils.is_gif(file):
media = types.InputMediaGifExternal(file, '')
if isinstance(file, str):
if re.match('https?://', file):
if as_image:
media = types.InputMediaPhotoExternal(file)
elif not force_document and utils.is_gif(file):
media = types.InputMediaGifExternal(file, '')
else:
media = types.InputMediaDocumentExternal(file)
else:
media = types.InputMediaDocumentExternal(file)
elif isinstance(file, str):
file_handle = await self.upload_file(
file, progress_callback=progress_callback,
use_cache=use_cache if allow_cache else None
)
else:
bot_file = utils.resolve_bot_file_id(file)
if bot_file:
media = utils.get_input_media(bot_file)
bot_file = utils.resolve_bot_file_id(file)
if bot_file:
media = utils.get_input_media(bot_file)
# Return if media is resolved
if media:
return None, media
if media:
pass # Already have media, don't check the rest
elif isinstance(file_handle, use_cache):
# Proceed with local file handle
file_handle = await self.upload_file(
file, progress_callback=progress_callback,
use_cache=use_cache if allow_cache else None
)
if isinstance(file_handle, use_cache):
# File was cached, so an instance of use_cache was returned
if as_image:
media = types.InputMediaPhoto(file_handle)