mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-31 16:07:44 +03:00 
			
		
		
		
	Fix InlineBuilder only working with local files
This commit is contained in:
		
							parent
							
								
									22124b5ced
								
							
						
					
					
						commit
						9a400748f7
					
				|  | @ -515,14 +515,15 @@ 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()) | ||||||
| 
 | 
 | ||||||
|         as_image = utils.is_image(file) and not force_document |         if as_image is None: | ||||||
|  |             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)): | ||||||
|             # The user may pass a Message containing media (or the media, |             # The user may pass a Message containing media (or the media, | ||||||
|  | @ -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, | ||||||
|  |  | ||||||
|  | @ -123,13 +123,16 @@ 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): |             ) | ||||||
|             r = await self._client(functions.messages.UploadMediaRequest( |             if isinstance(media, types.InputPhoto): | ||||||
|                 types.InputPeerSelf(), media=types.InputMediaUploadedPhoto(fh) |                 fh = media | ||||||
|             )) |             else: | ||||||
|             fh = utils.get_input_photo(r.photo) |                 r = await self._client(functions.messages.UploadMediaRequest( | ||||||
|  |                     types.InputPeerSelf(), media=media | ||||||
|  |                 )) | ||||||
|  |                 fh = utils.get_input_photo(r.photo) | ||||||
| 
 | 
 | ||||||
|         result = types.InputBotInlineResultPhoto( |         result = types.InputBotInlineResultPhoto( | ||||||
|             id=id or '', |             id=id or '', | ||||||
|  | @ -191,27 +194,22 @@ 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 | ||||||
|             ) |             ) | ||||||
|             r = await self._client(functions.messages.UploadMediaRequest( |             if isinstance(media, types.InputDocument): | ||||||
|                 types.InputPeerSelf(), media=types.InputMediaUploadedDocument( |                 fh = media | ||||||
|                     fh, |             else: | ||||||
|                     mime_type=mime_type, |                 r = await self._client(functions.messages.UploadMediaRequest( | ||||||
|                     attributes=attributes, |                     types.InputPeerSelf(), media=media | ||||||
|                     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( | ||||||
|             id=id or '', |             id=id or '', | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user