Fix InlineBuilder only working with local files

This commit is contained in:
Lonami Exo 2019-05-01 16:02:21 +02:00
parent 22124b5ced
commit 9a400748f7
2 changed files with 25 additions and 25 deletions

View File

@ -515,13 +515,14 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
self, file, force_document=False, self, file, force_document=False,
progress_callback=None, attributes=None, thumb=None, progress_callback=None, attributes=None, thumb=None,
allow_cache=True, voice_note=False, video_note=False, allow_cache=True, voice_note=False, video_note=False,
supports_streaming=False): supports_streaming=False, mime_type=None, as_image=None):
if not file: if not file:
return None, None, None return None, None, None
if isinstance(file, pathlib.Path): if isinstance(file, pathlib.Path):
file = str(file.absolute()) file = str(file.absolute())
if as_image is None:
as_image = utils.is_image(file) and not force_document as_image = utils.is_image(file) and not force_document
if not isinstance(file, (str, bytes, io.IOBase)): if not isinstance(file, (str, bytes, io.IOBase)):
@ -584,6 +585,7 @@ class UploadMethods(ButtonMethods, MessageParseMethods, UserMethods):
else: else:
attributes, mime_type = utils.get_attributes( attributes, mime_type = utils.get_attributes(
file, file,
mime_type=mime_type,
attributes=attributes, attributes=attributes,
force_document=force_document, force_document=force_document,
voice_note=voice_note, voice_note=voice_note,

View File

@ -123,11 +123,14 @@ class InlineBuilder:
try: try:
fh = utils.get_input_photo(file) fh = utils.get_input_photo(file)
except TypeError: except TypeError:
fh = await self._client.upload_file(file, use_cache=types.InputPhoto) _, media, _ = await self._client._file_to_media(
file, allow_cache=True, as_image=True
if not isinstance(fh, types.InputPhoto): )
if isinstance(media, types.InputPhoto):
fh = media
else:
r = await self._client(functions.messages.UploadMediaRequest( r = await self._client(functions.messages.UploadMediaRequest(
types.InputPeerSelf(), media=types.InputMediaUploadedPhoto(fh) types.InputPeerSelf(), media=media
)) ))
fh = utils.get_input_photo(r.photo) fh = utils.get_input_photo(r.photo)
@ -191,26 +194,21 @@ class InlineBuilder:
try: try:
fh = utils.get_input_document(file) fh = utils.get_input_document(file)
except TypeError: except TypeError:
use_cache = types.InputDocument if use_cache else None _, media, _ = await self._client._file_to_media(
fh = await self._client.upload_file(file, use_cache=use_cache)
if not isinstance(fh, types.InputDocument):
attributes, mime_type = utils.get_attributes(
file, file,
mime_type=mime_type, mime_type=mime_type,
attributes=attributes, attributes=attributes,
force_document=force_document, force_document=True,
voice_note=voice_note, voice_note=voice_note,
video_note=video_note video_note=video_note,
allow_cache=use_cache
) )
if isinstance(media, types.InputDocument):
fh = media
else:
r = await self._client(functions.messages.UploadMediaRequest( r = await self._client(functions.messages.UploadMediaRequest(
types.InputPeerSelf(), media=types.InputMediaUploadedDocument( types.InputPeerSelf(), media=media
fh, ))
mime_type=mime_type,
attributes=attributes,
nosound_video=None,
thumb=None
)))
fh = utils.get_input_document(r.document) fh = utils.get_input_document(r.document)
result = types.InputBotInlineResultDocument( result = types.InputBotInlineResultDocument(