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:
parent
f527fc91f6
commit
19dcce0d5b
@ -4586,14 +4586,16 @@ class TeleBot:
|
|||||||
|
|
||||||
def create_new_sticker_set(
|
def create_new_sticker_set(
|
||||||
self, user_id: int, name: str, title: str,
|
self, user_id: int, name: str, title: str,
|
||||||
emojis: str,
|
emojis: Optional[List[str]]=None,
|
||||||
png_sticker: Union[Any, str]=None,
|
png_sticker: Union[Any, str]=None,
|
||||||
tgs_sticker: Union[Any, str]=None,
|
tgs_sticker: Union[Any, str]=None,
|
||||||
webm_sticker: Union[Any, str]=None,
|
webm_sticker: Union[Any, str]=None,
|
||||||
contains_masks: Optional[bool]=None,
|
contains_masks: Optional[bool]=None,
|
||||||
sticker_type: Optional[str]=None,
|
sticker_type: Optional[str]=None,
|
||||||
mask_position: Optional[types.MaskPosition]=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.
|
Use this method to create new sticker set owned by a user.
|
||||||
The bot will be able to edit the created sticker set.
|
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
|
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
|
:param user_id: User identifier of created sticker set owner
|
||||||
:type user_id: :obj:`int`
|
:type user_id: :obj:`int`
|
||||||
|
|
||||||
@ -4641,17 +4646,37 @@ class TeleBot:
|
|||||||
for custom emoji sticker sets only
|
for custom emoji sticker sets only
|
||||||
:type needs_repainting: :obj:`bool`
|
: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.
|
:return: On success, True is returned.
|
||||||
:rtype: :obj:`bool`
|
: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:
|
if contains_masks is not None:
|
||||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||||
if sticker_type is None:
|
if sticker_type is None:
|
||||||
sticker_type = 'mask' if contains_masks else 'regular'
|
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(
|
return apihelper.create_new_sticker_set(
|
||||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||||
mask_position, webm_sticker, sticker_type, needs_repainting)
|
|
||||||
|
|
||||||
|
|
||||||
def add_sticker_to_set(
|
def add_sticker_to_set(
|
||||||
|
@ -1629,28 +1629,32 @@ def upload_sticker_file(token, user_id, png_sticker):
|
|||||||
|
|
||||||
|
|
||||||
def create_new_sticker_set(
|
def create_new_sticker_set(
|
||||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
|
||||||
mask_position=None, webm_sticker=None, sticker_type=None, needs_repainting=None):
|
|
||||||
method_url = 'createNewStickerSet'
|
method_url = 'createNewStickerSet'
|
||||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
payload = {'user_id': user_id, 'name': name, 'title': title}
|
||||||
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()
|
|
||||||
if sticker_type:
|
if sticker_type:
|
||||||
payload['sticker_type'] = sticker_type
|
payload['sticker_type'] = sticker_type
|
||||||
if needs_repainting is not None:
|
if needs_repainting:
|
||||||
payload['needs_repainting'] = 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')
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
@ -5449,14 +5449,16 @@ class AsyncTeleBot:
|
|||||||
|
|
||||||
async def create_new_sticker_set(
|
async def create_new_sticker_set(
|
||||||
self, user_id: int, name: str, title: str,
|
self, user_id: int, name: str, title: str,
|
||||||
emojis: str,
|
emojis: Optional[str]=None,
|
||||||
png_sticker: Union[Any, str]=None,
|
png_sticker: Union[Any, str]=None,
|
||||||
tgs_sticker: Union[Any, str]=None,
|
tgs_sticker: Union[Any, str]=None,
|
||||||
webm_sticker: Union[Any, str]=None,
|
webm_sticker: Union[Any, str]=None,
|
||||||
contains_masks: Optional[bool]=None,
|
contains_masks: Optional[bool]=None,
|
||||||
sticker_type: Optional[str]=None,
|
sticker_type: Optional[str]=None,
|
||||||
mask_position: Optional[types.MaskPosition]=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.
|
Use this method to create new sticker set owned by a user.
|
||||||
The bot will be able to edit the created sticker set.
|
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
|
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
|
:param user_id: User identifier of created sticker set owner
|
||||||
:type user_id: :obj:`int`
|
:type user_id: :obj:`int`
|
||||||
|
|
||||||
@ -5504,17 +5509,37 @@ class AsyncTeleBot:
|
|||||||
for custom emoji sticker sets only
|
for custom emoji sticker sets only
|
||||||
:type needs_repainting: :obj:`bool`
|
: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.
|
:return: On success, True is returned.
|
||||||
:rtype: :obj:`bool`
|
: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:
|
if contains_masks is not None:
|
||||||
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
logger.warning('The parameter "contains_masks" is deprecated, use "sticker_type" instead')
|
||||||
if sticker_type is None:
|
if sticker_type is None:
|
||||||
sticker_type = 'mask' if contains_masks else 'regular'
|
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(
|
return await asyncio_helper.create_new_sticker_set(
|
||||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
self.token, user_id, name, title, stickers, sticker_format, sticker_type, needs_repainting)
|
||||||
mask_position, webm_sticker, sticker_type, needs_repainting)
|
|
||||||
|
|
||||||
|
|
||||||
async def add_sticker_to_set(
|
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
|
# Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position
|
||||||
if sticker is None:
|
if sticker is None:
|
||||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
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)
|
sticker = types.InputSticker(sticker, emojis, mask_position)
|
||||||
|
|
||||||
return await asyncio_helper.add_sticker_to_set(
|
return await asyncio_helper.add_sticker_to_set(
|
||||||
|
@ -1616,28 +1616,31 @@ async def upload_sticker_file(token, user_id, png_sticker):
|
|||||||
|
|
||||||
|
|
||||||
async def create_new_sticker_set(
|
async def create_new_sticker_set(
|
||||||
token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
token, user_id, name, title, stickers, sticker_format=None, sticker_type=None, needs_repainting=None):
|
||||||
mask_position=None, webm_sticker=None, sticker_type=None, needs_repainting=None):
|
|
||||||
method_url = 'createNewStickerSet'
|
method_url = 'createNewStickerSet'
|
||||||
payload = {'user_id': user_id, 'name': name, 'title': title, 'emojis': emojis}
|
payload = {'user_id': user_id, 'name': name, 'title': title}
|
||||||
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()
|
|
||||||
if sticker_type:
|
if sticker_type:
|
||||||
payload['sticker_type'] = sticker_type
|
payload['sticker_type'] = sticker_type
|
||||||
if needs_repainting is not None:
|
if needs_repainting:
|
||||||
payload['needs_repainting'] = 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')
|
return await _process_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
@ -7388,7 +7388,7 @@ class InputSticker(Dictionaryable, JsonSerializable):
|
|||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
json_dict = {
|
json_dict = {
|
||||||
'sticker': self._sticker_dic,
|
'sticker': self._sticker_dic,
|
||||||
'emojis': self.emoji_list
|
'emoji_list': self.emoji_list
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.mask_position is not None:
|
if self.mask_position is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user