mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-30 23:47:33 +03:00 
			
		
		
		
	Fix send_message not forwarding some args to send_file
This commit is contained in:
		
							parent
							
								
									82943bd464
								
							
						
					
					
						commit
						acb8518911
					
				|  | @ -602,7 +602,6 @@ class MessageMethods: | ||||||
| 
 | 
 | ||||||
|             clear_draft (`bool`, optional): |             clear_draft (`bool`, optional): | ||||||
|                 Whether the existing draft should be cleared or not. |                 Whether the existing draft should be cleared or not. | ||||||
|                 Has no effect when sending a file. |  | ||||||
| 
 | 
 | ||||||
|             buttons (`list`, `custom.Button <telethon.tl.custom.button.Button>`, :tl:`KeyboardButton`): |             buttons (`list`, `custom.Button <telethon.tl.custom.button.Button>`, :tl:`KeyboardButton`): | ||||||
|                 The matrix (list of lists), row list or button to be shown |                 The matrix (list of lists), row list or button to be shown | ||||||
|  | @ -691,7 +690,8 @@ class MessageMethods: | ||||||
|             return await self.send_file( |             return await self.send_file( | ||||||
|                 entity, file, caption=message, reply_to=reply_to, |                 entity, file, caption=message, reply_to=reply_to, | ||||||
|                 parse_mode=parse_mode, force_document=force_document, |                 parse_mode=parse_mode, force_document=force_document, | ||||||
|                 buttons=buttons |                 buttons=buttons, clear_draft=clear_draft, silent=silent, | ||||||
|  |                 schedule=schedule | ||||||
|             ) |             ) | ||||||
| 
 | 
 | ||||||
|         entity = await self.get_input_entity(entity) |         entity = await self.get_input_entity(entity) | ||||||
|  |  | ||||||
|  | @ -93,6 +93,7 @@ class UploadMethods: | ||||||
|             *, |             *, | ||||||
|             caption: typing.Union[str, typing.Sequence[str]] = None, |             caption: typing.Union[str, typing.Sequence[str]] = None, | ||||||
|             force_document: bool = False, |             force_document: bool = False, | ||||||
|  |             clear_draft: bool = False, | ||||||
|             progress_callback: 'hints.ProgressCallback' = None, |             progress_callback: 'hints.ProgressCallback' = None, | ||||||
|             reply_to: 'hints.MessageIDLike' = None, |             reply_to: 'hints.MessageIDLike' = None, | ||||||
|             attributes: 'typing.Sequence[types.TypeDocumentAttribute]' = None, |             attributes: 'typing.Sequence[types.TypeDocumentAttribute]' = None, | ||||||
|  | @ -168,6 +169,9 @@ class UploadMethods: | ||||||
|                 the extension of an image file or a video file, it will be |                 the extension of an image file or a video file, it will be | ||||||
|                 sent as such. Otherwise always as a document. |                 sent as such. Otherwise always as a document. | ||||||
| 
 | 
 | ||||||
|  |             clear_draft (`bool`, optional): | ||||||
|  |                 Whether the existing draft should be cleared or not. | ||||||
|  | 
 | ||||||
|             progress_callback (`callable`, optional): |             progress_callback (`callable`, optional): | ||||||
|                 A callback function accepting two parameters: |                 A callback function accepting two parameters: | ||||||
|                 ``(sent bytes, total)``. |                 ``(sent bytes, total)``. | ||||||
|  | @ -296,7 +300,7 @@ class UploadMethods: | ||||||
|                     entity, media[:10], caption=media_captions[:10], |                     entity, media[:10], caption=media_captions[:10], | ||||||
|                     progress_callback=progress_callback, reply_to=reply_to, |                     progress_callback=progress_callback, reply_to=reply_to, | ||||||
|                     parse_mode=parse_mode, silent=silent, schedule=schedule, |                     parse_mode=parse_mode, silent=silent, schedule=schedule, | ||||||
|                     supports_streaming=supports_streaming |                     supports_streaming=supports_streaming, clear_draft=clear_draft | ||||||
|                 ) |                 ) | ||||||
|                 media = media[10:] |                 media = media[10:] | ||||||
|                 media_captions = media_captions[10:] |                 media_captions = media_captions[10:] | ||||||
|  | @ -309,6 +313,7 @@ class UploadMethods: | ||||||
|                     attributes=attributes, thumb=thumb, voice_note=voice_note, |                     attributes=attributes, thumb=thumb, voice_note=voice_note, | ||||||
|                     video_note=video_note, buttons=buttons, silent=silent, |                     video_note=video_note, buttons=buttons, silent=silent, | ||||||
|                     supports_streaming=supports_streaming, schedule=schedule, |                     supports_streaming=supports_streaming, schedule=schedule, | ||||||
|  |                     clear_draft=clear_draft, | ||||||
|                     **kwargs |                     **kwargs | ||||||
|                 )) |                 )) | ||||||
| 
 | 
 | ||||||
|  | @ -341,7 +346,7 @@ class UploadMethods: | ||||||
|         request = functions.messages.SendMediaRequest( |         request = functions.messages.SendMediaRequest( | ||||||
|             entity, media, reply_to_msg_id=reply_to, message=caption, |             entity, media, reply_to_msg_id=reply_to, message=caption, | ||||||
|             entities=msg_entities, reply_markup=markup, silent=silent, |             entities=msg_entities, reply_markup=markup, silent=silent, | ||||||
|             schedule_date=schedule |             schedule_date=schedule, clear_draft=clear_draft | ||||||
|         ) |         ) | ||||||
|         msg = self._get_response_message(request, await self(request), entity) |         msg = self._get_response_message(request, await self(request), entity) | ||||||
|         await self._cache_media(msg, file, file_handle, image=image) |         await self._cache_media(msg, file, file_handle, image=image) | ||||||
|  | @ -351,7 +356,7 @@ class UploadMethods: | ||||||
|     async def _send_album(self: 'TelegramClient', entity, files, caption='', |     async def _send_album(self: 'TelegramClient', entity, files, caption='', | ||||||
|                           progress_callback=None, reply_to=None, |                           progress_callback=None, reply_to=None, | ||||||
|                           parse_mode=(), silent=None, schedule=None, |                           parse_mode=(), silent=None, schedule=None, | ||||||
|                           supports_streaming=None): |                           supports_streaming=None, clear_draft=None): | ||||||
|         """Specialized version of .send_file for albums""" |         """Specialized version of .send_file for albums""" | ||||||
|         # We don't care if the user wants to avoid cache, we will use it |         # We don't care if the user wants to avoid cache, we will use it | ||||||
|         # anyway. Why? The cached version will be exactly the same thing |         # anyway. Why? The cached version will be exactly the same thing | ||||||
|  | @ -413,7 +418,7 @@ class UploadMethods: | ||||||
|         # Now we can construct the multi-media request |         # Now we can construct the multi-media request | ||||||
|         request = functions.messages.SendMultiMediaRequest( |         request = functions.messages.SendMultiMediaRequest( | ||||||
|             entity, reply_to_msg_id=reply_to, multi_media=media, |             entity, reply_to_msg_id=reply_to, multi_media=media, | ||||||
|             silent=silent, schedule_date=schedule |             silent=silent, schedule_date=schedule, clear_draft=clear_draft | ||||||
|         ) |         ) | ||||||
|         result = await self(request) |         result = await self(request) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										0
									
								
								tests/telethon/client/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/telethon/client/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										40
									
								
								tests/telethon/client/test_messages.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								tests/telethon/client/test_messages.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,40 @@ | ||||||
|  | import inspect | ||||||
|  | 
 | ||||||
|  | import pytest | ||||||
|  | 
 | ||||||
|  | from telethon import TelegramClient | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @pytest.mark.asyncio | ||||||
|  | async def test_send_message_with_file_forwards_args(): | ||||||
|  |     arguments = {} | ||||||
|  |     sentinel = object() | ||||||
|  | 
 | ||||||
|  |     for value, name in enumerate(inspect.signature(TelegramClient.send_message).parameters): | ||||||
|  |         if name in {'self', 'entity', 'file'}: | ||||||
|  |             continue  # positional | ||||||
|  | 
 | ||||||
|  |         if name in {'message'}: | ||||||
|  |             continue  # renamed | ||||||
|  | 
 | ||||||
|  |         if name in {'link_preview'}: | ||||||
|  |             continue  # make no sense in send_file | ||||||
|  | 
 | ||||||
|  |         arguments[name] = value | ||||||
|  | 
 | ||||||
|  |     class MockedClient(TelegramClient): | ||||||
|  |         # noinspection PyMissingConstructor | ||||||
|  |         def __init__(self): | ||||||
|  |             pass | ||||||
|  | 
 | ||||||
|  |         async def send_file(self, entity, file, **kwargs): | ||||||
|  |             assert entity == 'a' | ||||||
|  |             assert file == 'b' | ||||||
|  |             for k, v in arguments.items(): | ||||||
|  |                 assert k in kwargs | ||||||
|  |                 assert kwargs[k] == v | ||||||
|  | 
 | ||||||
|  |             return sentinel | ||||||
|  | 
 | ||||||
|  |     client = MockedClient() | ||||||
|  |     assert (await client.send_message('a', file='b', **arguments)) == sentinel | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user