Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
56 changes: 31 additions & 25 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def run_webhooks(self,
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.

Expand Down Expand Up @@ -1028,7 +1028,7 @@ def polling(self, non_stop: Optional[bool]=False, skip_pending: Optional[bool]=F
: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:
Expand Down Expand Up @@ -1906,6 +1906,8 @@ def send_audio(
: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`
"""
Expand All @@ -1916,7 +1918,7 @@ def send_audio(

if thumb is not None and thumbnail is None:
thumbnail = thumb
logger.warning('thumb is deprecated, use thumbnail instead')
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')

return types.Message.de_json(
apihelper.send_audio(
Expand Down Expand Up @@ -2072,6 +2074,8 @@ def send_document(
: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`
"""
Expand All @@ -2082,17 +2086,18 @@ def send_document(

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 is deprecated, use thumbnail instead')
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" 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))
Expand Down Expand Up @@ -2162,6 +2167,7 @@ def send_sticker(

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(
Expand Down Expand Up @@ -2256,6 +2262,8 @@ def send_video(
: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`
"""
Expand All @@ -2266,11 +2274,12 @@ def send_video(

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 is deprecated, use thumbnail instead')
logger.warning('The parameter "thumb" is deprecated. Use "thumbnail" instead.')

return types.Message.de_json(
apihelper.send_video(
Expand Down Expand Up @@ -2359,6 +2368,8 @@ def send_animation(
: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`
"""
Expand Down Expand Up @@ -2438,6 +2449,8 @@ def send_video_note(
: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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:type thumb: :obj:`str` or :class:`telebot.types.InputFile`

:return: On success, the sent Message is returned.
:rtype: :class:`telebot.types.Message`
"""
Expand Down Expand Up @@ -3023,9 +3036,7 @@ def restrict_chat_member(
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)

Expand Down Expand Up @@ -3108,7 +3119,7 @@ def promote_chat_member(
: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

Expand Down Expand Up @@ -4537,8 +4548,7 @@ def answer_callback_query(
"""
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.
Expand All @@ -4551,16 +4561,17 @@ def set_sticker_set_thumbnail(
: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.
Expand All @@ -4580,8 +4591,7 @@ def set_sticker_set_thumb(
: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:
"""
Expand Down Expand Up @@ -4736,7 +4746,7 @@ def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, s
: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"

Expand Down Expand Up @@ -4894,10 +4904,7 @@ def add_sticker_to_set(
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)
Expand Down Expand Up @@ -6740,7 +6747,6 @@ def _run_middlewares_and_handler(self, message, handlers, middlewares, update_ty
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:
Expand Down
75 changes: 38 additions & 37 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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'
Expand All @@ -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:
Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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}
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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'
Expand Down
Loading