1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added support for .WEBP, .TGS, and .WEBM files in uploadStickerFile by replacing the parameter png_sticker in the method uploadStickerFile with the parameters sticker and sticker_format.

This commit is contained in:
coder2020official 2023-03-11 22:15:31 +04:00
parent 73135d6012
commit ae44b0022d
4 changed files with 36 additions and 12 deletions

View File

@ -4564,7 +4564,7 @@ class TeleBot:
result = apihelper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
return [types.Sticker.de_json(sticker) for sticker in result]
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
"""
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
methods (can be used multiple times). Returns the uploaded File on success.
@ -4574,14 +4574,26 @@ class TeleBot:
:param user_id: User identifier of sticker set owner
:type user_id: :obj:`int`
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
and either width or height must be exactly 512px.
:type png_sticker: :obj:`filelike object`
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
:type sticker: :class:`telebot.types.InputFile`
:param sticker_format: One of "static", "animated", "video".
:type sticker_format: :obj:`str`
:return: On success, the sent file is returned.
:rtype: :class:`telebot.types.File`
"""
result = apihelper.upload_sticker_file(self.token, user_id, png_sticker)
if png_sticker:
logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning)
sticker = png_sticker
sticker_format = "static"
result = apihelper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
return types.File.de_json(result)
def create_new_sticker_set(

View File

@ -1621,10 +1621,10 @@ def get_custom_emoji_stickers(token, custom_emoji_ids):
method_url = r'getCustomEmojiStickers'
return _make_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
def upload_sticker_file(token, user_id, png_sticker):
def upload_sticker_file(token, user_id, sticker, sticker_format):
method_url = 'uploadStickerFile'
payload = {'user_id': user_id}
files = {'png_sticker': png_sticker}
payload = {'user_id': user_id, 'sticker_format': sticker_format}
files = {'sticker': sticker}
return _make_request(token, method_url, params=payload, files=files, method='post')

View File

@ -5427,7 +5427,7 @@ class AsyncTeleBot:
result = await asyncio_helper.get_custom_emoji_stickers(self.token, custom_emoji_ids)
return [types.Sticker.de_json(sticker) for sticker in result]
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]) -> types.File:
async def upload_sticker_file(self, user_id: int, png_sticker: Union[Any, str]=None, sticker: Optional[types.InputFile]=None, sticker_format: Optional[str]=None) -> types.File:
"""
Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet
methods (can be used multiple times). Returns the uploaded File on success.
@ -5437,14 +5437,26 @@ class AsyncTeleBot:
:param user_id: User identifier of sticker set owner
:type user_id: :obj:`int`
:param png_sticker: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
:param png_sticker: DEPRECATED: PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px,
and either width or height must be exactly 512px.
:type png_sticker: :obj:`filelike object`
:param sticker: A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »
:type sticker: :class:`telebot.types.InputFile`
:param sticker_format: One of "static", "animated", "video".
:type sticker_format: :obj:`str`
:return: On success, the sent file is returned.
:rtype: :class:`telebot.types.File`
"""
result = await asyncio_helper.upload_sticker_file(self.token, user_id, png_sticker)
if png_sticker:
logger.warning("png_sticker is deprecated, use sticker instead", DeprecationWarning)
sticker = png_sticker
sticker_format = "static"
result = await asyncio_helper.upload_sticker_file(self.token, user_id, sticker, sticker_format)
return types.File.de_json(result)
async def create_new_sticker_set(

View File

@ -1608,10 +1608,10 @@ async def get_custom_emoji_stickers(token, custom_emoji_ids):
method_url = r'getCustomEmojiStickers'
return await _process_request(token, method_url, params={'custom_emoji_ids': custom_emoji_ids})
async def upload_sticker_file(token, user_id, png_sticker):
async def upload_sticker_file(token, user_id, sticker, sticker_format):
method_url = 'uploadStickerFile'
payload = {'user_id': user_id}
files = {'png_sticker': png_sticker}
payload = {'user_id': user_id, 'sticker_format': sticker_format}
files = {'sticker': sticker}
return await _process_request(token, method_url, params=payload, files=files, method='post')