From 7c7a063fb6a3c4355e706eb39f340618ce36b7f3 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 14:38:02 +0300 Subject: [PATCH 01/16] Fix some code hints --- README.md | 1 - telebot/__init__.py | 13 +++++++++++-- telebot/apihelper.py | 3 ++- telebot/async_telebot.py | 24 +++++++++++++++--------- telebot/asyncio_helper.py | 9 ++++++--- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a618836..5792f54 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![PyPi Package Version](https://img.shields.io/pypi/v/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI) [![Supported Python versions](https://img.shields.io/pypi/pyversions/pyTelegramBotAPI.svg)](https://pypi.python.org/pypi/pyTelegramBotAPI) [![Documentation Status](https://readthedocs.org/projects/pytba/badge/?version=latest)](https://pytba.readthedocs.io/en/latest/?badge=latest) -[![Build Status](https://travis-ci.org/eternnoir/pyTelegramBotAPI.svg?branch=master)](https://travis-ci.org/eternnoir/pyTelegramBotAPI) [![PyPi downloads](https://img.shields.io/pypi/dm/pyTelegramBotAPI.svg)](https://pypi.org/project/pyTelegramBotAPI/) [![PyPi status](https://img.shields.io/pypi/status/pytelegrambotapi.svg?style=flat-square)](https://pypi.python.org/pypi/pytelegrambotapi) diff --git a/telebot/__init__.py b/telebot/__init__.py index 0d36d7b..43a462c 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -451,7 +451,7 @@ class TeleBot: drop_pending_updates: Optional[bool] = None, timeout: Optional[int]=None, secret_token: Optional[str]=None, - secret_token_length: Optional[int]=20,): + secret_token_length: Optional[int]=20): """ This class sets webhooks and listens to a given url and port. @@ -1906,6 +1906,8 @@ class TeleBot: :param message_thread_id: Identifier of a message thread, in which the message will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2072,6 +2074,8 @@ class TeleBot: :param message_thread_id: The thread to which the message will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2256,6 +2260,8 @@ class TeleBot: :param has_spoiler: Pass True, if the video should be sent as a spoiler :type has_spoiler: :obj:`bool` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2359,6 +2365,8 @@ class TeleBot: :param has_spoiler: Pass True, if the animation should be sent as a spoiler :type has_spoiler: :obj:`bool` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2438,6 +2446,8 @@ class TeleBot: :param message_thread_id: Identifier of a message thread, in which the video note will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -6740,7 +6750,6 @@ class TeleBot: if not process_handler: continue for i in inspect.signature(handler['function']).parameters: params.append(i) - result = None if len(params) == 1: result = handler['function'](message) elif "data" in params: diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 6d59b84..88b36f9 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1479,7 +1479,8 @@ def send_invoice( :param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency :param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. - :param protect_content: + :param protect_content: Protects the contents of the sent message from forwarding and saving + :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only :return: """ method_url = r'sendInvoice' diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index f13d1a0..2e0af51 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -209,8 +209,8 @@ class AsyncTeleBot: :param allowed_updates: Array of string. List the types of updates you want your bot to receive. :type allowed_updates: :obj:`list`, optional - :param long_polling_timeout: Timeout in seconds for long polling. - :type long_polling_timeout: :obj:`int`, optional + :param request_timeout: Timeout in seconds for request. + :type request_timeout: :obj:`int`, optional :return: An Array of Update objects is returned. :rtype: :obj:`list` of :class:`telebot.types.Update` @@ -511,7 +511,6 @@ class AsyncTeleBot: if not process_update: continue for i in signature(handler['function']).parameters: params.append(i) - result = None if len(params) == 1: result = await handler['function'](message) elif "data" in params: @@ -2072,6 +2071,8 @@ class AsyncTeleBot: :param drop_pending_updates: Pass True to drop all pending updates :param timeout: Integer. Request connection timeout :param secret_token: Secret token to be used to verify the webhook request. + :param secret_token_length: Length of a secret token, defaults to 20 + :param debug: Debug mode, defaults to False :return: """ @@ -2079,12 +2080,9 @@ class AsyncTeleBot: if not secret_token: secret_token = ''.join(random.choices(string.ascii_uppercase + string.digits, k=secret_token_length)) - if not url_path: url_path = self.token + '/' if url_path[-1] != '/': url_path += '/' - - protocol = "https" if certificate else "http" if not webhook_url: @@ -2093,8 +2091,6 @@ class AsyncTeleBot: if certificate and certificate_key: ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ssl_ctx.load_cert_chain(certificate, certificate_key) - else: - ssl_ctx = None # open certificate if it exists cert_file = open(certificate, 'rb') if certificate else None @@ -2769,6 +2765,8 @@ class AsyncTeleBot: :param message_thread_id: Identifier of a message thread, in which the message will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2934,6 +2932,8 @@ class AsyncTeleBot: :param message_thread_id: Identifier of a message thread, in which the message will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3116,6 +3116,8 @@ class AsyncTeleBot: :param has_spoiler: Pass True, if the video should be sent as a spoiler :type has_spoiler: :obj:`bool` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3220,6 +3222,8 @@ class AsyncTeleBot: :param has_spoiler: Pass True, if the animation should be sent as a spoiler :type has_spoiler: :obj:`bool` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3299,6 +3303,8 @@ class AsyncTeleBot: :param message_thread_id: Identifier of a message thread, in which the video note will be sent :type message_thread_id: :obj:`int` + :param thumb: Deprecated. Use thumbnail instead + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -5609,7 +5615,7 @@ class AsyncTeleBot: async def create_new_sticker_set( self, user_id: int, name: str, title: str, - emojis: Optional[str]=None, + emojis: Optional[List[str]]=None, png_sticker: Union[Any, str]=None, tgs_sticker: Union[Any, str]=None, webm_sticker: Union[Any, str]=None, diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 0494f27..49dc92d 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -173,6 +173,7 @@ async def get_file_url(token, file_id): if FILE_URL is None: return "https://api.telegram.org/file/bot{0}/{1}".format(token, (await get_file(token, file_id))['file_path']) else: + # noinspection PyUnresolvedReferences return FILE_URL.format(token, (await get_file(token, file_id))['file_path']) @@ -180,6 +181,7 @@ async def download_file(token, file_path): if FILE_URL is None: url = "https://api.telegram.org/file/bot{0}/{1}".format(token, file_path) else: + # noinspection PyUnresolvedReferences url = FILE_URL.format(token, file_path) session = await session_manager.get_session() async with session.get(url, proxy=proxy) as response: @@ -1433,8 +1435,8 @@ async def send_invoice( need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, send_phone_number_to_provider = None, send_email_to_provider = None, is_flexible=None, disable_notification=None, reply_to_message_id=None, reply_markup=None, provider_data=None, - timeout=None, allow_sending_without_reply=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, - message_thread_id=None): + timeout=None, allow_sending_without_reply=None, max_tip_amount=None, suggested_tip_amounts=None, + protect_content=None, message_thread_id=None): """ Use this method to send invoices. On success, the sent Message is returned. :param token: Bot's token (you don't need to fill this) @@ -1466,7 +1468,8 @@ async def send_invoice( :param max_tip_amount: The maximum accepted amount for tips in the smallest units of the currency :param suggested_tip_amounts: A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. - :param protect_content: + :param protect_content: Protects the contents of the sent message from forwarding and saving + :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only :return: """ method_url = r'sendInvoice' From e56c60ac00ebec7bf0d35a496191b1fdda8a9096 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 14:44:50 +0300 Subject: [PATCH 02/16] thumb deprecation typo and thumb->thumbnail param rename --- telebot/__init__.py | 8 ++--- telebot/apihelper.py | 62 ++++++++++++++++----------------- telebot/async_telebot.py | 8 ++--- telebot/asyncio_helper.py | 72 +++++++++++++++++++-------------------- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 43a462c..dd1f8d2 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1918,7 +1918,7 @@ class TeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( apihelper.send_audio( @@ -2090,13 +2090,13 @@ class TeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( apihelper.send_data( self.token, chat_id, document, 'document', reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode, - disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumbnail, + disable_notification = disable_notification, timeout = timeout, caption = caption, thumbnail= thumbnail, caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply, disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name, protect_content = protect_content, message_thread_id = message_thread_id)) @@ -2276,7 +2276,7 @@ class TeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( apihelper.send_video( diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 88b36f9..32e38bc 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -668,8 +668,8 @@ def send_chat_action(token, chat_id, action, timeout=None, message_thread_id=Non def send_video(token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None, - thumb=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None, + parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None, + thumbnail=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None, has_spoiler=None): method_url = r'sendVideo' payload = {'chat_id': chat_id} @@ -694,14 +694,14 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if width: payload['width'] = width if height: @@ -721,7 +721,7 @@ def send_video(token, chat_id, data, duration=None, caption=None, reply_to_messa def send_animation( token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, disable_notification=None, timeout=None, thumb=None, caption_entities=None, + parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None, width=None, height=None, message_thread_id=None, has_spoiler=None): method_url = r'sendAnimation' @@ -745,14 +745,14 @@ def send_animation( payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: @@ -806,7 +806,7 @@ def send_voice(token, chat_id, voice, caption=None, duration=None, reply_to_mess def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_message_id=None, reply_markup=None, - disable_notification=None, timeout=None, thumb=None, allow_sending_without_reply=None, protect_content=None, + disable_notification=None, timeout=None, thumbnail=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None): method_url = r'sendVideoNote' payload = {'chat_id': chat_id} @@ -829,14 +829,14 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_m payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if allow_sending_without_reply is not None: payload['allow_sending_without_reply'] = allow_sending_without_reply if protect_content is not None: @@ -847,7 +847,7 @@ def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_m def send_audio(token, chat_id, audio, caption=None, duration=None, performer=None, title=None, reply_to_message_id=None, - reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumb=None, + reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None): method_url = r'sendAudio' payload = {'chat_id': chat_id} @@ -874,14 +874,14 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: @@ -894,7 +894,7 @@ def send_audio(token, chat_id, audio, caption=None, duration=None, performer=Non def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None, - disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None, + disable_notification=None, timeout=None, caption=None, thumbnail=None, caption_entities=None, allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content = None, message_thread_id=None, emoji=None): method_url = get_method_by_type(data_type) @@ -919,14 +919,14 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m payload['timeout'] = timeout if caption: payload['caption'] = caption - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 2e0af51..cd952ae 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -2948,13 +2948,13 @@ class AsyncTeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( await asyncio_helper.send_data( self.token, chat_id, document, 'document', reply_to_message_id = reply_to_message_id, reply_markup = reply_markup, parse_mode = parse_mode, - disable_notification = disable_notification, timeout = timeout, caption = caption, thumb = thumbnail, + disable_notification = disable_notification, timeout = timeout, caption = caption, thumbnail= thumbnail, caption_entities = caption_entities, allow_sending_without_reply = allow_sending_without_reply, disable_content_type_detection = disable_content_type_detection, visible_file_name = visible_file_name, protect_content = protect_content, message_thread_id = message_thread_id)) @@ -3234,7 +3234,7 @@ class AsyncTeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( await asyncio_helper.send_animation( @@ -3314,7 +3314,7 @@ class AsyncTeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('thumb is deprecated, use thumbnail instead') + logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') return types.Message.de_json( await asyncio_helper.send_video_note( diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index 49dc92d..dc8e9b8 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -662,9 +662,9 @@ async def send_chat_action(token, chat_id, action, timeout=None, message_thread_ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None, - thumb=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, - protect_content=None, message_thread_id=None, has_spoiler=None): + parse_mode=None, supports_streaming=None, disable_notification=None, timeout=None, + thumbnail=None, width=None, height=None, caption_entities=None, allow_sending_without_reply=None, + protect_content=None, message_thread_id=None, has_spoiler=None): method_url = r'sendVideo' payload = {'chat_id': chat_id} files = None @@ -688,14 +688,14 @@ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if width: payload['width'] = width if height: @@ -715,7 +715,7 @@ async def send_video(token, chat_id, data, duration=None, caption=None, reply_to async def send_animation( token, chat_id, data, duration=None, caption=None, reply_to_message_id=None, reply_markup=None, - parse_mode=None, disable_notification=None, timeout=None, thumb=None, caption_entities=None, + parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, caption_entities=None, allow_sending_without_reply=None, width=None, height=None, protect_content=None, message_thread_id=None, has_spoiler=None): method_url = r'sendAnimation' @@ -739,14 +739,14 @@ async def send_animation( payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: @@ -800,8 +800,8 @@ async def send_voice(token, chat_id, voice, caption=None, duration=None, reply_t async def send_video_note(token, chat_id, data, duration=None, length=None, reply_to_message_id=None, reply_markup=None, - disable_notification=None, timeout=None, thumb=None, allow_sending_without_reply=None, protect_content=None, - message_thread_id=None): + disable_notification=None, timeout=None, thumbnail=None, allow_sending_without_reply=None, protect_content=None, + message_thread_id=None): method_url = r'sendVideoNote' payload = {'chat_id': chat_id} files = None @@ -823,14 +823,14 @@ async def send_video_note(token, chat_id, data, duration=None, length=None, repl payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if allow_sending_without_reply is not None: payload['allow_sending_without_reply'] = allow_sending_without_reply if protect_content is not None: @@ -841,8 +841,8 @@ async def send_video_note(token, chat_id, data, duration=None, length=None, repl async def send_audio(token, chat_id, audio, caption=None, duration=None, performer=None, title=None, reply_to_message_id=None, - reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumb=None, - caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None): + reply_markup=None, parse_mode=None, disable_notification=None, timeout=None, thumbnail=None, + caption_entities=None, allow_sending_without_reply=None, protect_content=None, message_thread_id=None): method_url = r'sendAudio' payload = {'chat_id': chat_id} files = None @@ -868,14 +868,14 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform payload['disable_notification'] = disable_notification if timeout: payload['timeout'] = timeout - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: @@ -888,9 +888,9 @@ async def send_audio(token, chat_id, audio, caption=None, duration=None, perform async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None, parse_mode=None, - disable_notification=None, timeout=None, caption=None, thumb=None, caption_entities=None, - allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content=None, - message_thread_id=None, emoji=None): + disable_notification=None, timeout=None, caption=None, thumbnail=None, caption_entities=None, + allow_sending_without_reply=None, disable_content_type_detection=None, visible_file_name=None, protect_content=None, + message_thread_id=None, emoji=None): method_url = await get_method_by_type(data_type) payload = {'chat_id': chat_id} files = None @@ -913,14 +913,14 @@ async def send_data(token, chat_id, data, data_type, reply_to_message_id=None, r payload['timeout'] = timeout if caption: payload['caption'] = caption - if thumb: - if not util.is_string(thumb): + if thumbnail: + if not util.is_string(thumbnail): if files: - files['thumbnail'] = thumb + files['thumbnail'] = thumbnail else: - files = {'thumbnail': thumb} + files = {'thumbnail': thumbnail} else: - payload['thumbnail'] = thumb + payload['thumbnail'] = thumbnail if caption_entities: payload['caption_entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(caption_entities)) if allow_sending_without_reply is not None: From 6a9c25cf809ef069faa88e8bf81b8f1b851feca2 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 14:56:31 +0300 Subject: [PATCH 03/16] Fix set_sticker_set_thumb and set_sticker_set_thumbnail --- telebot/__init__.py | 17 ++++++++--------- telebot/apihelper.py | 10 +++++----- telebot/async_telebot.py | 16 +++++++--------- telebot/asyncio_helper.py | 10 +++++----- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index dd1f8d2..b0161bc 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -4547,8 +4547,7 @@ class TeleBot: """ return apihelper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time) - def set_sticker_set_thumbnail( - self, name: str, user_id: int, thumb: Union[Any, str]=None): + def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Union[Any, str]=None): """ Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns True on success. @@ -4561,16 +4560,17 @@ class TeleBot: :param user_id: User identifier :type user_id: :obj:`int` - :param thumb: - :type thumb: :obj:`filelike object` + :param thumbnail: A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + :type thumbnail: :obj:`filelike object` :return: On success, True is returned. :rtype: :obj:`bool` """ - return apihelper.set_sticker_set_thumb(self.token, name, user_id, thumb) + + return apihelper.set_sticker_set_thumbnail(self.token, name, user_id, thumbnail) - def set_sticker_set_thumb( - self, name: str, user_id: int, thumb: Union[Any, str]=None): + @util.deprecated(deprecation_text="Use set_sticker_set_thumbnail instead") + def set_sticker_set_thumb(self, name: str, user_id: int, thumb: Union[Any, str]=None): """ Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns True on success. @@ -4590,8 +4590,7 @@ class TeleBot: :rtype: :obj:`bool` """ # deprecated - logger.warning('set_sticker_set_thumb is deprecated. Use set_sticker_set_thumbnail instead.') - return apihelper.set_sticker_set_thumb(self.token, name, user_id, thumb) + return self.set_sticker_set_thumbnail(name, user_id, thumb) def get_sticker_set(self, name: str) -> types.StickerSet: """ diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 32e38bc..b5eb065 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -355,15 +355,15 @@ def get_chat_member_count(token, chat_id): return _make_request(token, method_url, params=payload) -def set_sticker_set_thumb(token, name, user_id, thumb): +def set_sticker_set_thumbnail(token, name, user_id, thumbnail): method_url = r'setStickerSetThumbnail' payload = {'name': name, 'user_id': user_id} files = {} - if thumb: - if not isinstance(thumb, str): - files['thumb'] = thumb + if thumbnail: + if not isinstance(thumbnail, str): + files['thumbnail'] = thumbnail else: - payload['thumb'] = thumb + payload['thumbnail'] = thumbnail return _make_request(token, method_url, params=payload, files=files or None) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index cd952ae..247440c 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -5407,8 +5407,7 @@ class AsyncTeleBot: """ return await asyncio_helper.answer_callback_query(self.token, callback_query_id, text, show_alert, url, cache_time) - async def set_sticker_set_thumbnail( - self, name: str, user_id: int, thumb: Union[Any, str]=None): + async def set_sticker_set_thumbnail(self, name: str, user_id: int, thumbnail: Union[Any, str]=None): """ Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns True on success. @@ -5421,16 +5420,16 @@ class AsyncTeleBot: :param user_id: User identifier :type user_id: :obj:`int` - :param thumb: - :type thumb: :obj:`filelike object` + :param thumbnail: A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + :type thumbnail: :obj:`filelike object` :return: On success, True is returned. :rtype: :obj:`bool` """ - return await asyncio_helper.set_sticker_set_thumb(self.token, name, user_id, thumb) + return await asyncio_helper.set_sticker_set_thumbnail(self.token, name, user_id, thumbnail) - async def set_sticker_set_thumb( - self, name: str, user_id: int, thumb: Union[Any, str]=None): + @util.deprecated(deprecation_text="Use set_sticker_set_thumbnail instead") + async def set_sticker_set_thumb(self, name: str, user_id: int, thumb: Union[Any, str]=None): """ Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns True on success. @@ -5450,8 +5449,7 @@ class AsyncTeleBot: :rtype: :obj:`bool` """ # deprecated - logger.warning('set_sticker_set_thumb is deprecated, use set_sticker_set_thumbnail instead') - return await asyncio_helper.set_sticker_set_thumb(self.token, name, user_id, thumb) + return await self.set_sticker_set_thumbnail(name, user_id, thumb) async def get_sticker_set(self, name: str) -> types.StickerSet: """ diff --git a/telebot/asyncio_helper.py b/telebot/asyncio_helper.py index dc8e9b8..6f7ef0f 100644 --- a/telebot/asyncio_helper.py +++ b/telebot/asyncio_helper.py @@ -343,15 +343,15 @@ async def get_chat_member_count(token, chat_id): return await _process_request(token, method_url, params=payload) -async def set_sticker_set_thumb(token, name, user_id, thumb): +async def set_sticker_set_thumbnail(token, name, user_id, thumbnail): method_url = r'setStickerSetThumbnail' payload = {'name': name, 'user_id': user_id} files = {} - if thumb: - if not isinstance(thumb, str): - files['thumb'] = thumb + if thumbnail: + if not isinstance(thumbnail, str): + files['thumbnail'] = thumbnail else: - payload['thumb'] = thumb + payload['thumbnail'] = thumbnail return await _process_request(token, method_url, params=payload, files=files or None) From b0740a920a4aad7ab1ea6ec8141fdeebba08eac4 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 15:08:40 +0300 Subject: [PATCH 04/16] Set "thumb" as property in types --- telebot/types.py | 73 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index 96d526e..68adeba 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -1578,8 +1578,12 @@ class Audio(JsonDeserializable): self.file_name: str = file_name self.mime_type: str = mime_type self.file_size: int = file_size - self.thumbnail: PhotoSize = thumbnail - self.thumb = thumbnail + self.thumbnail: PhotoSize = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail class Voice(JsonDeserializable): @@ -1670,7 +1674,11 @@ class Document(JsonDeserializable): self.file_name: str = file_name self.mime_type: str = mime_type self.file_size: int = file_size - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail class Video(JsonDeserializable): @@ -1730,7 +1738,11 @@ class Video(JsonDeserializable): self.file_name: str = file_name self.mime_type: str = mime_type self.file_size: int = file_size - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail class VideoNote(JsonDeserializable): @@ -1776,7 +1788,11 @@ class VideoNote(JsonDeserializable): self.duration: int = duration self.thumbnail: PhotoSize = thumbnail self.file_size: int = file_size - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail class Contact(JsonDeserializable): @@ -5471,11 +5487,15 @@ class Animation(JsonDeserializable): self.height: int = height self.duration: int = duration self.thumbnail: PhotoSize = thumbnail - self.thumb: PhotoSize = thumbnail self.file_name: str = file_name self.mime_type: str = mime_type self.file_size: int = file_size + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail + class GameHighScore(JsonDeserializable): """ @@ -5895,7 +5915,11 @@ class StickerSet(JsonDeserializable): self.is_video: bool = is_video self.stickers: List[Sticker] = stickers self.thumbnail: PhotoSize = thumbnail - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail @property def contains_masks(self): @@ -5997,8 +6021,11 @@ class Sticker(JsonDeserializable): self.premium_animation: File = premium_animation self.custom_emoji_id: int = custom_emoji_id self.needs_repainting: bool = needs_repainting - self.thumb = self.thumbnail - + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail class MaskPosition(Dictionaryable, JsonDeserializable, JsonSerializable): @@ -6195,7 +6222,11 @@ class InputMediaVideo(InputMedia): self.duration = duration self.supports_streaming = supports_streaming self.has_spoiler: Optional[bool] = has_spoiler - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail def to_dict(self): ret = super(InputMediaVideo, self).to_dict() @@ -6225,12 +6256,12 @@ class InputMediaAnimation(InputMedia): multipart/form-data under name. More information on Sending Files » :type media: :obj:`str` - :param thumb: Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported + :param thumbnail: Optional. Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under . More information on Sending Files » - :type thumb: InputFile or :obj:`str` + :type thumbnail: InputFile or :obj:`str` :param caption: Optional. Caption of the animation to be sent, 0-1024 characters after entities parsing :type caption: :obj:`str` @@ -6267,7 +6298,11 @@ class InputMediaAnimation(InputMedia): self.height = height self.duration = duration self.has_spoiler: Optional[bool] = has_spoiler - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail def to_dict(self): ret = super(InputMediaAnimation, self).to_dict() @@ -6333,7 +6368,11 @@ class InputMediaAudio(InputMedia): self.duration = duration self.performer = performer self.title = title - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail def to_dict(self): ret = super(InputMediaAudio, self).to_dict() @@ -6390,7 +6429,11 @@ class InputMediaDocument(InputMedia): type="document", media=media, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities) self.thumbnail = thumbnail self.disable_content_type_detection = disable_content_type_detection - self.thumb = thumbnail + + @property + def thumb(self): + logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + return self.thumbnail def to_dict(self): ret = super(InputMediaDocument, self).to_dict() From c9ef0d71f05cfb8d5eb3ea5d1d27b86c2317b39d Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 15:17:29 +0300 Subject: [PATCH 05/16] Deprecation warnings equalisation --- telebot/__init__.py | 24 +++++++++++------------- telebot/async_telebot.py | 28 ++++++++++++---------------- telebot/types.py | 22 +++++++++++----------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index b0161bc..8aec551 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1028,7 +1028,7 @@ class TeleBot: :return: """ if none_stop is not None: - logger.warning("polling: none_stop parameter is deprecated. Use non_stop instead.") + logger.warning('The parameter "none_stop" is deprecated. Use "non_stop" instead.') non_stop = none_stop if skip_pending: @@ -1918,7 +1918,7 @@ class TeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( apihelper.send_audio( @@ -2086,11 +2086,12 @@ class TeleBot: if data and not(document): # function typo miss compatibility + logger.warning('The parameter "data" is deprecated. Use "document" instead.') document = data if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( apihelper.send_data( @@ -2166,6 +2167,7 @@ class TeleBot: if data and not(sticker): # function typo miss compatibility + logger.warning('The parameter "data" is deprecated. Use "sticker" instead.') sticker = data return types.Message.de_json( @@ -2272,11 +2274,12 @@ class TeleBot: if data and not(video): # function typo miss compatibility + logger.warning('The parameter "data" is deprecated. Use "video" instead.') video = data if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( apihelper.send_video( @@ -3033,9 +3036,7 @@ class TeleBot: can_invite_users=can_invite_users, can_pin_messages=can_pin_messages ) - logger.warning( - "Individual parameters are deprecated and will be removed, use 'permissions' instead." - ) + logger.warning('The parameters "can_..." are deprecated, use "permissions" instead.') return apihelper.restrict_chat_member( self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions) @@ -3118,7 +3119,7 @@ class TeleBot: :rtype: :obj:`bool` """ if can_manage_voice_chats is not None: - logger.warning("promote_chat_member: can_manage_voice_chats parameter is deprecated. Use can_manage_video_chats instead.") + logger.warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.') if can_manage_video_chats is None: can_manage_video_chats = can_manage_voice_chats @@ -4745,7 +4746,7 @@ class TeleBot: :rtype: :class:`telebot.types.File` """ if png_sticker: - logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning) + logger.warning('The parameter "png_sticker" is deprecated. Use "sticker" instead.') sticker = png_sticker sticker_format = "static" @@ -4903,10 +4904,7 @@ class TeleBot: if sticker is None: old_sticker = png_sticker or tgs_sticker or webm_sticker if old_sticker is not None: - logger.warning( - 'The parameters "png_sticker", "tgs_sticker", "webm_sticker", "emojis" and "mask_position" are deprecated, ' - 'use "sticker" instead' - ) + logger.warning('The parameters "..._sticker", "emojis" and "mask_position" are deprecated, use "sticker" instead') if not old_sticker: raise ValueError('You must pass at least one sticker.') sticker = types.InputSticker(old_sticker, emojis, mask_position) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 247440c..04c4e6e 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -294,7 +294,7 @@ class AsyncTeleBot: :return: """ if none_stop is not None: - logger.warning("polling: none_stop parameter is deprecated. Use non_stop instead.") + logger.warning('The parameter "none_stop" is deprecated. Use "non_stop" instead.') non_stop = none_stop if skip_pending: @@ -2944,11 +2944,12 @@ class AsyncTeleBot: if data and not(document): # function typo miss compatibility + logger.warning('The parameter "data" is deprecated. Use "document" instead.') document = data if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( await asyncio_helper.send_data( @@ -3021,7 +3022,7 @@ class AsyncTeleBot: if data and not(sticker): # function typo miss compatibility - logger.warning("send_sticker: data parameter is deprecated. Use sticker instead.") + logger.warning('The parameter "data" is deprecated. Use "sticker" instead.') sticker = data return types.Message.de_json( @@ -3128,11 +3129,11 @@ class AsyncTeleBot: if data and not(video): # function typo miss compatibility - logger.warning("send_sticker: data parameter is deprecated. Use video instead.") + logger.warning('The parameter "data" is deprecated. Use "video" instead.') video = data if thumb and not(thumbnail): - logger.warning("send_sticker: thumb parameter is deprecated. Use thumbnail instead.") + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') thumbnail = thumb return types.Message.de_json( @@ -3234,7 +3235,7 @@ class AsyncTeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( await asyncio_helper.send_animation( @@ -3314,7 +3315,7 @@ class AsyncTeleBot: if thumb is not None and thumbnail is None: thumbnail = thumb - logger.warning('"thumb" param is deprecated, use "thumbnail" param instead') + logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.') return types.Message.de_json( await asyncio_helper.send_video_note( @@ -3887,9 +3888,7 @@ class AsyncTeleBot: can_invite_users=can_invite_users, can_pin_messages=can_pin_messages ) - logger.warning( - "Individual parameters are deprecated and will be removed, use 'permissions' instead." - ) + logger.warning('The parameters "can_..." are deprecated, use "permissions" instead.') return await asyncio_helper.restrict_chat_member( self.token, chat_id, user_id, permissions, until_date, use_independent_chat_permissions) @@ -3973,7 +3972,7 @@ class AsyncTeleBot: """ if can_manage_voice_chats is not None: - logger.warning("promote_chat_member: can_manage_voice_chats parameter is deprecated. Use can_manage_video_chats instead.") + logger.warning('The parameter "can_manage_voice_chats" is deprecated. Use "can_manage_video_chats" instead.') if can_manage_video_chats is None: can_manage_video_chats = can_manage_voice_chats @@ -5539,7 +5538,7 @@ class AsyncTeleBot: :rtype: :class:`telebot.types.File` """ if png_sticker: - logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning) + logger.warning('The parameter "png_sticker" is deprecated. Use "sticker" instead.') sticker = png_sticker sticker_format = "static" @@ -5761,10 +5760,7 @@ class AsyncTeleBot: if sticker is None: old_sticker = png_sticker or tgs_sticker or webm_sticker if old_sticker is not None: - logger.warning( - 'Parameters "png_sticker", "tgs_sticker", "webm_sticker", "emojis" and "mask_position" are deprecated, ' - 'use "sticker" instead' - ) + logger.warning('The parameters "..._sticker", "emojis" and "mask_position" are deprecated, use "sticker" instead') if not old_sticker: raise ValueError('You must pass at least one sticker.') sticker = types.InputSticker(old_sticker, emojis, mask_position) diff --git a/telebot/types.py b/telebot/types.py index 68adeba..4c68e65 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -1582,7 +1582,7 @@ class Audio(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -1677,7 +1677,7 @@ class Document(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -1741,7 +1741,7 @@ class Video(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -1791,7 +1791,7 @@ class VideoNote(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -5493,7 +5493,7 @@ class Animation(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -5918,7 +5918,7 @@ class StickerSet(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @property @@ -6024,7 +6024,7 @@ class Sticker(JsonDeserializable): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail @@ -6225,7 +6225,7 @@ class InputMediaVideo(InputMedia): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail def to_dict(self): @@ -6301,7 +6301,7 @@ class InputMediaAnimation(InputMedia): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail def to_dict(self): @@ -6371,7 +6371,7 @@ class InputMediaAudio(InputMedia): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail def to_dict(self): @@ -6432,7 +6432,7 @@ class InputMediaDocument(InputMedia): @property def thumb(self): - logger.warning('The property "thumb" is deprecated, use "thumbnail" instead') + logger.warning('The parameter "thumb" is deprecated, use "thumbnail" instead') return self.thumbnail def to_dict(self): From fe2e9a7a3022c8dc18a48a40950af8b16a0aec4c Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 15:22:30 +0300 Subject: [PATCH 06/16] thumb_url etc. converted to properties --- telebot/types.py | 130 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 34 deletions(-) diff --git a/telebot/types.py b/telebot/types.py index 4c68e65..58fc07b 100644 --- a/telebot/types.py +++ b/telebot/types.py @@ -4032,10 +4032,20 @@ class InlineQueryResultArticle(InlineQueryResultBase): self.thumbnail_width = thumbnail_width self.thumbnail_height = thumbnail_height - # deprecateds - self.thumb_url = thumbnail_url - self.thumb_width = thumbnail_width - self.thumb_height = thumbnail_height + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + + @property + def thumb_width(self): + logger.warning('The parameter "thumb_width" is deprecated, use "thumbnail_width" instead') + return self.thumbnail_width + + @property + def thumb_height(self): + logger.warning('The parameter "thumb_height" is deprecated, use "thumbnail_height" instead') + return self.thumbnail_height def to_dict(self): json_dict = super().to_dict() @@ -4047,9 +4057,9 @@ class InlineQueryResultArticle(InlineQueryResultBase): json_dict['description'] = self.description if self.thumbnail_url: json_dict['thumbnail_url'] = self.thumbnail_url - if self.thumb_width: + if self.thumbnail_width: json_dict['thumbnail_width'] = self.thumbnail_width - if self.thumb_height: + if self.thumbnail_height: json_dict['thumbnail_height'] = self.thumbnail_height return json_dict @@ -4115,8 +4125,10 @@ class InlineQueryResultPhoto(InlineQueryResultBase): self.photo_height = photo_height self.description = description - # deprecateds - self.thumb_url = thumbnail_url + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url def to_dict(self): json_dict = super().to_dict() @@ -4198,9 +4210,15 @@ class InlineQueryResultGif(InlineQueryResultBase): self.gif_duration = gif_duration self.thumbnail_mime_type = thumbnail_mime_type - # deprecateds - self.thumb_url = thumbnail_url - self.thumb_mime_type = thumbnail_mime_type + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + + @property + def thumb_mime_type(self): + logger.warning('The parameter "thumb_mime_type" is deprecated, use "thumbnail_mime_type" instead') + return self.thumbnail_mime_type def to_dict(self): json_dict = super().to_dict() @@ -4284,9 +4302,15 @@ class InlineQueryResultMpeg4Gif(InlineQueryResultBase): self.mpeg4_duration = mpeg4_duration self.thumbnail_mime_type = thumbnail_mime_type - # deprecateds - self.thumb_url = thumbnail_url - self.thumb_mime_type = thumbnail_mime_type + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + + @property + def thumb_mime_type(self): + logger.warning('The parameter "thumb_mime_type" is deprecated, use "thumbnail_mime_type" instead') + return self.thumbnail_mime_type def to_dict(self): json_dict = super().to_dict() @@ -4375,8 +4399,10 @@ class InlineQueryResultVideo(InlineQueryResultBase): self.video_duration = video_duration self.description = description - # deprecated - self.thumb_url = thumbnail_url + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url def to_dict(self): json_dict = super().to_dict() @@ -4579,11 +4605,20 @@ class InlineQueryResultDocument(InlineQueryResultBase): self.thumbnail_width = thumbnail_width self.thumbnail_height = thumbnail_height - # deprecated - self.thumb_url = thumbnail_url - self.thumb_width = thumbnail_width - self.thumb_height = thumbnail_height + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + @property + def thumb_width(self): + logger.warning('The parameter "thumb_width" is deprecated, use "thumbnail_width" instead') + return self.thumbnail_width + + @property + def thumb_height(self): + logger.warning('The parameter "thumb_height" is deprecated, use "thumbnail_height" instead') + return self.thumbnail_height def to_dict(self): json_dict = super().to_dict() @@ -4668,10 +4703,20 @@ class InlineQueryResultLocation(InlineQueryResultBase): self.thumbnail_width = thumbnail_width self.thumbnail_height = thumbnail_height - # deprecated - self.thumb_url = thumbnail_url - self.thumb_width = thumbnail_width - self.thumb_height = thumbnail_height + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + + @property + def thumb_width(self): + logger.warning('The parameter "thumb_width" is deprecated, use "thumbnail_width" instead') + return self.thumbnail_width + + @property + def thumb_height(self): + logger.warning('The parameter "thumb_height" is deprecated, use "thumbnail_height" instead') + return self.thumbnail_height def to_dict(self): json_dict = super().to_dict() @@ -4765,11 +4810,20 @@ class InlineQueryResultVenue(InlineQueryResultBase): self.thumbnail_width = thumbnail_width self.thumbnail_height = thumbnail_height - # deprecated - self.thumb_url = thumbnail_url - self.thumb_width = thumbnail_width - self.thumb_height = thumbnail_height - + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url + + @property + def thumb_width(self): + logger.warning('The parameter "thumb_width" is deprecated, use "thumbnail_width" instead') + return self.thumbnail_width + + @property + def thumb_height(self): + logger.warning('The parameter "thumb_height" is deprecated, use "thumbnail_height" instead') + return self.thumbnail_height def to_dict(self): json_dict = super().to_dict() @@ -4848,12 +4902,20 @@ class InlineQueryResultContact(InlineQueryResultBase): self.thumbnail_width = thumbnail_width self.thumbnail_height = thumbnail_height - # deprecated - self.thumb_url = thumbnail_url - self.thumb_width = thumbnail_width - self.thumb_height = thumbnail_height + @property + def thumb_url(self): + logger.warning('The parameter "thumb_url" is deprecated, use "thumbnail_url" instead') + return self.thumbnail_url - + @property + def thumb_width(self): + logger.warning('The parameter "thumb_width" is deprecated, use "thumbnail_width" instead') + return self.thumbnail_width + + @property + def thumb_height(self): + logger.warning('The parameter "thumb_height" is deprecated, use "thumbnail_height" instead') + return self.thumbnail_height def to_dict(self): json_dict = super().to_dict() From 14434b398e59b425731421248c2ef2a74f398f60 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:34:08 +0300 Subject: [PATCH 07/16] send_animation thumbnail hint Co-authored-by: _run --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 8aec551..03910e4 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -2369,7 +2369,7 @@ class TeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From b0e64d828c7386583cdd0f900d176ba89e601244 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:36:10 +0300 Subject: [PATCH 08/16] send_video thumbnail hint Co-authored-by: _run --- telebot/async_telebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 04c4e6e..0dcb9e4 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -2766,7 +2766,7 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From f3486b3730524be5aa6e63dca50c1ba5e4d840b7 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:36:36 +0300 Subject: [PATCH 09/16] send_document thumbnail Co-authored-by: _run --- telebot/async_telebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 0dcb9e4..fa97afa 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -2933,7 +2933,7 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 018b89cdc077d421668925f68c4d6b39ebbf750a Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:37:03 +0300 Subject: [PATCH 10/16] send_document thumbnail Co-authored-by: _run --- telebot/async_telebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index fa97afa..bc3f5d6 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -3118,7 +3118,7 @@ class AsyncTeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 46100edd97ee5331cdf201b5464bf2fd4ed70132 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:37:22 +0300 Subject: [PATCH 11/16] send_video_note thumbnail hint Co-authored-by: _run --- telebot/async_telebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index bc3f5d6..bf85813 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -3305,7 +3305,7 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 6b5c263ee8529536f6f0fba02fcf7cb81987c2b5 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:37:46 +0300 Subject: [PATCH 12/16] send_animtion thumbnail hint Co-authored-by: _run --- telebot/async_telebot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index bf85813..64807ad 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -3224,7 +3224,7 @@ class AsyncTeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From b1c172c4211d6ca0774f48df939ff8d6ba87d2f9 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:38:05 +0300 Subject: [PATCH 13/16] send_document thumbnail hint Co-authored-by: _run --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 03910e4..75b410a 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -2075,7 +2075,7 @@ class TeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 39360e0640999730796375db45089df12a67175b Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sat, 25 Mar 2023 16:38:16 +0300 Subject: [PATCH 14/16] send_video thumbnail hint Co-authored-by: _run --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 75b410a..27f4ca6 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -2263,7 +2263,7 @@ class TeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead - +:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 2e589ab6e15df530a97e0a74600f1a32229f8abd Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 26 Mar 2023 18:00:35 +0300 Subject: [PATCH 15/16] Thumb type spec --- telebot/__init__.py | 12 ++++++++---- telebot/async_telebot.py | 20 ++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 27f4ca6..6c953e1 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -1892,7 +1892,7 @@ class TeleBot: The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under - :type thumbnail: :obj:`str` + :type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode :type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity` @@ -1907,6 +1907,7 @@ class TeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` @@ -2075,7 +2076,8 @@ class TeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2263,7 +2265,8 @@ class TeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2369,7 +2372,8 @@ class TeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ diff --git a/telebot/async_telebot.py b/telebot/async_telebot.py index 64807ad..ebf5e80 100644 --- a/telebot/async_telebot.py +++ b/telebot/async_telebot.py @@ -2058,8 +2058,7 @@ class AsyncTeleBot: """ This class sets webhooks and listens to a given url and port. - :param listen: IP address to listen to. Defaults to - 0.0.0.0 + :param listen: IP address to listen to. Defaults to 0.0.0.0 :param port: A port which will be used to listen to webhooks. :param url_path: Path to the webhook. Defaults to /token :param certificate: Path to the certificate file. @@ -2751,7 +2750,7 @@ class AsyncTeleBot: The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail's width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can't be reused and can be only uploaded as a new file, so you can pass “attach://” if the thumbnail was uploaded using multipart/form-data under - :type thumbnail: :obj:`str` + :type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` :param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode :type caption_entities: :obj:`list` of :class:`telebot.types.MessageEntity` @@ -2766,7 +2765,8 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -2933,7 +2933,8 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3118,7 +3119,8 @@ class AsyncTeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3224,7 +3226,8 @@ class AsyncTeleBot: :type has_spoiler: :obj:`bool` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ @@ -3305,7 +3308,8 @@ class AsyncTeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead -:type thumbnail: :obj:`str` or :class:`telebot.types.InputFile` + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` + :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """ From 3f07dc4ce809004dc23ee44faba488fec128ea27 Mon Sep 17 00:00:00 2001 From: Badiboy Date: Sun, 26 Mar 2023 20:04:29 +0300 Subject: [PATCH 16/16] thumb Co-authored-by: _run --- telebot/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 6c953e1..c385a29 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -2454,7 +2454,7 @@ class TeleBot: :type message_thread_id: :obj:`int` :param thumb: Deprecated. Use thumbnail instead - + :type thumb: :obj:`str` or :class:`telebot.types.InputFile` :return: On success, the sent Message is returned. :rtype: :class:`telebot.types.Message` """