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

Added support for the creation of sticker sets with multiple initial stickers in createNewStickerSet by replacing the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position with the parameters stickers and sticker_format.

This commit is contained in:
coder2020official 2023-03-11 21:59:22 +04:00
parent f527fc91f6
commit 19dcce0d5b
5 changed files with 104 additions and 45 deletions

View File

@ -4586,14 +4586,16 @@ class TeleBot:
def create_new_sticker_set(
self, user_id: int, name: str, title: str,
emojis: str,
emojis: Optional[List[str]]=None,
png_sticker: Union[Any, str]=None,
tgs_sticker: Union[Any, str]=None,
webm_sticker: Union[Any, str]=None,
contains_masks: Optional[bool]=None,
sticker_type: Optional[str]=None,
mask_position: Optional[types.MaskPosition]=None,
needs_repainting: Optional[bool]=None) -> bool:
needs_repainting: Optional[bool]=None,
stickers: List[types.InputSticker]=None,
sticker_format: Optional[str]=None) -> bool:
"""
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
@ -4601,6 +4603,9 @@ class TeleBot:
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
.. note::
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
:param user_id: User identifier of created sticker set owner
:type user_id: :obj:`int`
@ -4641,17 +4646,37 @@ class TeleBot:
for custom emoji sticker sets only
:type needs_repainting: :obj:`bool`
:param stickers: List of stickers to be added to the set
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
:param sticker_format: Format of stickers in the set, must be one of static, animated, video
:type sticker_format: :obj:`str`
:return: On success, True is returned.
:rtype: :obj:`bool`
"""
if tgs_sticker:
sticker_format = 'animated'
elif webm_sticker:
sticker_format = 'video'
elif png_sticker:
sticker_format = 'static'
if contains_masks is not None:
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
if sticker_type is None:
sticker_type = 'mask' if contains_masks else 'regular'
if stickers is None:
stickers = png_sticker or tgs_sticker or webm_sticker
if stickers is None:
raise ValueError('You must pass at least one sticker')
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
return apihelper.create_new_sticker_set(
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
mask_position, webm_sticker, sticker_type, needs_repainting)
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
def add_sticker_to_set(

View File

@ -1629,28 +1629,32 @@ def upload_sticker_file(token, user_id, png_sticker):
def create_new_sticker_set(
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
mask_position=None, webm_sticker=None, sticker_type=None, needs_repainting=None):
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
method_url = 'createNewStickerSet'
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
if png_sticker:
stype = 'png_sticker'
elif webm_sticker:
stype = 'webm_sticker'
else:
stype = 'tgs_sticker'
sticker = png_sticker or tgs_sticker or webm_sticker
files = None
if not util.is_string(sticker):
files = {stype: sticker}
else:
payload[stype] = sticker
if mask_position:
payload['mask_position'] = mask_position.to_json()
payload = {'user_id': user_id, 'name': name, 'title': title}
if sticker_type:
payload['sticker_type'] = sticker_type
if needs_repainting is not None:
if needs_repainting:
payload['needs_repainting'] = needs_repainting
if sticker_format:
payload['sticker_format'] = sticker_format
files = {}
lst = []
for sticker in stickers:
json_dict, file = sticker.convert_input_sticker()
json_dict = sticker.to_dict()
if file:
list_keys = list(file.keys())
files[list_keys[0]] = file[list_keys[0]]
lst.append(json_dict)
payload['stickers'] = json.dumps(lst)
return _make_request(token, method_url, params=payload, files=files, method='post')

View File

@ -5449,14 +5449,16 @@ class AsyncTeleBot:
async def create_new_sticker_set(
self, user_id: int, name: str, title: str,
emojis: str,
emojis: Optional[str]=None,
png_sticker: Union[Any, str]=None,
tgs_sticker: Union[Any, str]=None,
webm_sticker: Union[Any, str]=None,
contains_masks: Optional[bool]=None,
sticker_type: Optional[str]=None,
mask_position: Optional[types.MaskPosition]=None,
needs_repainting: Optional[bool]=None) -> bool:
needs_repainting: Optional[bool]=None,
stickers: List[types.InputSticker]=None,
sticker_format: Optional[str]=None) -> bool:
"""
Use this method to create new sticker set owned by a user.
The bot will be able to edit the created sticker set.
@ -5464,6 +5466,9 @@ class AsyncTeleBot:
Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset
.. note::
Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.
:param user_id: User identifier of created sticker set owner
:type user_id: :obj:`int`
@ -5504,17 +5509,37 @@ class AsyncTeleBot:
for custom emoji sticker sets only
:type needs_repainting: :obj:`bool`
:param stickers: List of stickers to be added to the set
:type stickers: :obj:`list` of :class:`telebot.types.InputSticker`
:param sticker_format: Format of stickers in the set, must be one of static, animated, video
:type sticker_format: :obj:`str`
:return: On success, True is returned.
:rtype: :obj:`bool`
"""
if tgs_sticker:
sticker_format = 'animated'
elif webm_sticker:
sticker_format = 'video'
elif png_sticker:
sticker_format = 'static'
if contains_masks is not None:
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
if sticker_type is None:
sticker_type = 'mask' if contains_masks else 'regular'
if stickers is None:
stickers = png_sticker or tgs_sticker or webm_sticker
if stickers is None:
raise ValueError('You must pass at least one sticker')
stickers = [types.InputSticker(sticker=stickers, emoji_list=emojis, mask_position=mask_position)]
return await asyncio_helper.create_new_sticker_set(
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
mask_position, webm_sticker, sticker_type, needs_repainting)
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
async def add_sticker_to_set(
@ -5563,6 +5588,8 @@ class AsyncTeleBot:
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
if sticker is None:
sticker = png_sticker or tgs_sticker or webm_sticker
if sticker is None:
raise ValueError('You must pass at least one sticker')
sticker = types.InputSticker(sticker, emojis, mask_position)
return await asyncio_helper.add_sticker_to_set(

View File

@ -1616,28 +1616,31 @@ async def upload_sticker_file(token, user_id, png_sticker):
async def create_new_sticker_set(
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
mask_position=None, webm_sticker=None, sticker_type=None, needs_repainting=None):
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
method_url = 'createNewStickerSet'
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
if png_sticker:
stype = 'png_sticker'
elif webm_sticker:
stype = 'webm_sticker'
else:
stype = 'tgs_sticker'
sticker = png_sticker or tgs_sticker or webm_sticker
files = None
if not util.is_string(sticker):
files = {stype: sticker}
else:
payload[stype] = sticker
if mask_position:
payload['mask_position'] = mask_position.to_json()
payload = {'user_id': user_id, 'name': name, 'title': title}
if sticker_type:
payload['sticker_type'] = sticker_type
if needs_repainting is not None:
if needs_repainting:
payload['needs_repainting'] = needs_repainting
if sticker_format:
payload['sticker_format'] = sticker_format
files = {}
lst = []
for sticker in stickers:
json_dict, file = sticker.convert_input_sticker()
json_dict = sticker.to_dict()
if file:
list_keys = list(file.keys())
files[list_keys[0]] = file[list_keys[0]]
lst.append(json_dict)
payload['stickers'] = json.dumps(lst)
return await _process_request(token, method_url, params=payload, files=files, method='post')

View File

@ -7388,7 +7388,7 @@ class InputSticker(Dictionaryable, JsonSerializable):
def to_dict(self) -> dict:
json_dict = {
'sticker': self._sticker_dic,
'emojis': self.emoji_list
'emoji_list': self.emoji_list
}
if self.mask_position is not None: