mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Replaced the parameters png_sticker, tgs_sticker, webm_sticker, emojis and mask_position in the method addStickerToSet with the parameter sticker of the type InputSticker.
This commit is contained in:
parent
c0185dad44
commit
f527fc91f6
@ -4653,12 +4653,14 @@ class TeleBot:
|
|||||||
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
self.token, user_id, name, title, emojis, png_sticker, tgs_sticker,
|
||||||
mask_position, webm_sticker, sticker_type, needs_repainting)
|
mask_position, webm_sticker, sticker_type, needs_repainting)
|
||||||
|
|
||||||
|
|
||||||
def add_sticker_to_set(
|
def add_sticker_to_set(
|
||||||
self, user_id: int, name: str, emojis: str,
|
self, user_id: int, name: str, emojis: List[str]=None,
|
||||||
png_sticker: Optional[Union[Any, str]]=None,
|
png_sticker: Optional[Union[Any, str]]=None,
|
||||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||||
webm_sticker: Optional[Union[Any, str]]=None,
|
webm_sticker: Optional[Union[Any, str]]=None,
|
||||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
mask_position: Optional[types.MaskPosition]=None,
|
||||||
|
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||||
"""
|
"""
|
||||||
Use this method to add a new sticker to a set created by the bot.
|
Use this method to add a new sticker to a set created by the bot.
|
||||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||||
@ -4666,6 +4668,9 @@ class TeleBot:
|
|||||||
|
|
||||||
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
Telegram documentation: https://core.telegram.org/bots/api#addstickertoset
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
**_sticker parameters are deprecated, use stickers 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`
|
||||||
|
|
||||||
@ -4689,11 +4694,19 @@ class TeleBot:
|
|||||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||||
|
|
||||||
|
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||||
|
:type sticker: :class:`telebot.types.InputSticker`
|
||||||
|
|
||||||
:return: On success, True is returned.
|
:return: On success, True is returned.
|
||||||
:rtype: :obj:`bool`
|
:rtype: :obj:`bool`
|
||||||
"""
|
"""
|
||||||
|
# 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
|
||||||
|
sticker = types.InputSticker(sticker, emojis, mask_position)
|
||||||
|
|
||||||
return apihelper.add_sticker_to_set(
|
return apihelper.add_sticker_to_set(
|
||||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
self.token, user_id, name, sticker)
|
||||||
|
|
||||||
def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -1654,23 +1654,11 @@ def create_new_sticker_set(
|
|||||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
def add_sticker_to_set(token, user_id, name, sticker):
|
||||||
method_url = 'addStickerToSet'
|
method_url = 'addStickerToSet'
|
||||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
json_dict, files = sticker.convert_input_sticker()
|
||||||
if png_sticker:
|
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||||
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()
|
|
||||||
return _make_request(token, method_url, params=payload, files=files, method='post')
|
return _make_request(token, method_url, params=payload, files=files, method='post')
|
||||||
|
|
||||||
|
|
||||||
|
@ -5518,11 +5518,12 @@ class AsyncTeleBot:
|
|||||||
|
|
||||||
|
|
||||||
async def add_sticker_to_set(
|
async def add_sticker_to_set(
|
||||||
self, user_id: int, name: str, emojis: str,
|
self, user_id: int, name: str, emojis: List[str]=None,
|
||||||
png_sticker: Optional[Union[Any, str]]=None,
|
png_sticker: Optional[Union[Any, str]]=None,
|
||||||
tgs_sticker: Optional[Union[Any, str]]=None,
|
tgs_sticker: Optional[Union[Any, str]]=None,
|
||||||
webm_sticker: Optional[Union[Any, str]]=None,
|
webm_sticker: Optional[Union[Any, str]]=None,
|
||||||
mask_position: Optional[types.MaskPosition]=None) -> bool:
|
mask_position: Optional[types.MaskPosition]=None,
|
||||||
|
sticker: Optional[List[types.InputSticker]]=None) -> bool:
|
||||||
"""
|
"""
|
||||||
Use this method to add a new sticker to a set created by the bot.
|
Use this method to add a new sticker to a set created by the bot.
|
||||||
It's required to pass `png_sticker` or `tgs_sticker`.
|
It's required to pass `png_sticker` or `tgs_sticker`.
|
||||||
@ -5553,11 +5554,19 @@ class AsyncTeleBot:
|
|||||||
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
|
||||||
:type mask_position: :class:`telebot.types.MaskPosition`
|
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||||
|
|
||||||
|
:param sticker: A JSON-serialized list of 1-50 initial stickers to be added to the sticker set
|
||||||
|
:type sticker: :class:`telebot.types.InputSticker`
|
||||||
|
|
||||||
:return: On success, True is returned.
|
:return: On success, True is returned.
|
||||||
:rtype: :obj:`bool`
|
:rtype: :obj:`bool`
|
||||||
"""
|
"""
|
||||||
|
# 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
|
||||||
|
sticker = types.InputSticker(sticker, emojis, mask_position)
|
||||||
|
|
||||||
return await asyncio_helper.add_sticker_to_set(
|
return await asyncio_helper.add_sticker_to_set(
|
||||||
self.token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker)
|
self.token, user_id, name, sticker)
|
||||||
|
|
||||||
|
|
||||||
async def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
async def set_sticker_position_in_set(self, sticker: str, position: int) -> bool:
|
||||||
|
@ -1641,27 +1641,12 @@ async def create_new_sticker_set(
|
|||||||
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')
|
||||||
|
|
||||||
|
|
||||||
async def add_sticker_to_set(token, user_id, name, emojis, png_sticker, tgs_sticker, mask_position, webm_sticker):
|
async def add_sticker_to_set(token, user_id, name, sticker):
|
||||||
method_url = 'addStickerToSet'
|
method_url = 'addStickerToSet'
|
||||||
payload = {'user_id': user_id, 'name': name, 'emojis': emojis}
|
json_dict, files = sticker.convert_input_sticker()
|
||||||
if png_sticker:
|
payload = {'user_id': user_id, 'name': name, 'sticker': json_dict}
|
||||||
stype = 'png_sticker'
|
|
||||||
elif webm_sticker:
|
|
||||||
stype = 'webm_sticker'
|
|
||||||
else:
|
|
||||||
stype = 'tgs_sticker'
|
|
||||||
files = None
|
|
||||||
sticker = png_sticker or tgs_sticker or webm_sticker
|
|
||||||
|
|
||||||
if not util.is_string(sticker):
|
|
||||||
files = {stype: sticker}
|
|
||||||
else:
|
|
||||||
payload[stype] = sticker
|
|
||||||
if mask_position:
|
|
||||||
payload['mask_position'] = mask_position.to_json()
|
|
||||||
|
|
||||||
if webm_sticker:
|
|
||||||
payload['webm_sticker'] = webm_sticker
|
|
||||||
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')
|
||||||
|
|
||||||
|
|
||||||
|
@ -7346,4 +7346,66 @@ class BotShortDescription(JsonDeserializable):
|
|||||||
return cls(**obj)
|
return cls(**obj)
|
||||||
|
|
||||||
def __init__(self, short_description: str) -> None:
|
def __init__(self, short_description: str) -> None:
|
||||||
self.short_description: str = short_description
|
self.short_description: str = short_description
|
||||||
|
|
||||||
|
|
||||||
|
class InputSticker(Dictionaryable, JsonSerializable):
|
||||||
|
"""
|
||||||
|
This object describes a sticker to be added to a sticker set.
|
||||||
|
|
||||||
|
:param sticker: The added sticker. 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.
|
||||||
|
Animated and video stickers can't be uploaded via HTTP URL.
|
||||||
|
:type sticker: :obj:`str` or :obj:`telebot.types.InputFile`
|
||||||
|
|
||||||
|
:param emoji_list: One or more(up to 20) emoji(s) corresponding to the sticker
|
||||||
|
:type emoji_list: :obj:`list` of :obj:`str`
|
||||||
|
|
||||||
|
:param mask_position: Optional. Position where the mask should be placed on faces. For “mask” stickers only.
|
||||||
|
:type mask_position: :class:`telebot.types.MaskPosition`
|
||||||
|
|
||||||
|
:param keywords: Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters.
|
||||||
|
For “regular” and “custom_emoji” stickers only.
|
||||||
|
:type keywords: :obj:`list` of :obj:`str`
|
||||||
|
|
||||||
|
:return: Instance of the class
|
||||||
|
:rtype: :class:`telebot.types.InputSticker`
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, sticker: Union[str, InputFile], emoji_list: List[str], mask_position: Optional[MaskPosition]=None, keywords: Optional[List[str]]=None) -> None:
|
||||||
|
self.sticker: Union[str, InputFile] = sticker
|
||||||
|
self.emoji_list: List[str] = emoji_list
|
||||||
|
self.mask_position: Optional[MaskPosition] = mask_position
|
||||||
|
self.keywords: Optional[List[str]] = keywords
|
||||||
|
|
||||||
|
if service_utils.is_string(self.sticker):
|
||||||
|
self._sticker_name = ''
|
||||||
|
self._sticker_dic = self.sticker
|
||||||
|
else:
|
||||||
|
self._sticker_name = service_utils.generate_random_token()
|
||||||
|
self._sticker_dic = 'attach://{0}'.format(self._sticker_name)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
json_dict = {
|
||||||
|
'sticker': self._sticker_dic,
|
||||||
|
'emojis': self.emoji_list
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.mask_position is not None:
|
||||||
|
json_dict['mask_position'] = self.mask_position.to_dict()
|
||||||
|
if self.keywords is not None:
|
||||||
|
json_dict['keywords'] = self.keywords
|
||||||
|
|
||||||
|
return json_dict
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
return json.dumps(self.to_dict())
|
||||||
|
|
||||||
|
def convert_input_sticker(self):
|
||||||
|
if service_utils.is_string(self.sticker):
|
||||||
|
return self.to_json(), None
|
||||||
|
|
||||||
|
return self.to_json(), {self._sticker_name: self.sticker}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user