Support bot API file_id on send_file

This commit is contained in:
Lonami Exo 2018-07-31 23:35:22 +02:00
parent 972950fc2e
commit 6d1bc227aa

View File

@ -41,7 +41,8 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
Furthermore the file may be any media (a message, document, Furthermore the file may be any media (a message, document,
photo or similar) so that it can be resent without the need photo or similar) so that it can be resent without the need
to download and re-upload it again. to download and re-upload it again. Bot API ``file_id``
format is also supported.
If a list or similar is provided, the files in it will be If a list or similar is provided, the files in it will be
sent as an album in the order in which they appear, sliced sent as an album in the order in which they appear, sliced
@ -389,10 +390,15 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
return None, None # Can't turn whatever was given into media return None, None # Can't turn whatever was given into media
media = None media = None
file_handle = None
as_image = utils.is_image(file) and not force_document as_image = utils.is_image(file) and not force_document
use_cache = types.InputPhoto if as_image else types.InputDocument use_cache = types.InputPhoto if as_image else types.InputDocument
if isinstance(file, str) and re.match('https?://', file): if not isinstance(file, str):
file_handle = None file_handle = await self.upload_file(
file, progress_callback=progress_callback,
use_cache=use_cache if allow_cache else None
)
elif re.match('https?://', file):
if as_image: if as_image:
media = types.InputMediaPhotoExternal(file) media = types.InputMediaPhotoExternal(file)
elif not force_document and utils.is_gif(file): elif not force_document and utils.is_gif(file):
@ -400,10 +406,9 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
else: else:
media = types.InputMediaDocumentExternal(file) media = types.InputMediaDocumentExternal(file)
else: else:
file_handle = await self.upload_file( bot_file = utils.resolve_bot_file_id(file)
file, progress_callback=progress_callback, if bot_file:
use_cache=use_cache if allow_cache else None media = utils.get_input_media(bot_file)
)
if media: if media:
pass # Already have media, don't check the rest pass # Already have media, don't check the rest