Skip to content

Commit

Permalink
Added the classes Gift and Gifts and the method getAvailableGifts, a…
Browse files Browse the repository at this point in the history
…llowing bots to get all gifts available for sending.
  • Loading branch information
coder2020official committed Nov 17, 2024
1 parent bee6bab commit 3d740ff
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
12 changes: 12 additions & 0 deletions telebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6249,7 +6249,19 @@ def delete_sticker_set(self, name:str) -> bool:
:rtype: :obj:`bool`
"""
return apihelper.delete_sticker_set(self.token, name)

def get_available_gifts(self) -> types.Gifts:
"""
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
Telegram documentation: https://core.telegram.org/bots/api#getavailablegifts
:return: On success, a Gifts object is returned.
:rtype: :class:`telebot.types.Gifts`
"""
return types.Gifts.de_json(
apihelper.get_available_gifts(self.token)
)

def replace_sticker_in_set(self, user_id: int, name: str, old_sticker: str, sticker: types.InputSticker) -> bool:
"""
Expand Down
5 changes: 5 additions & 0 deletions telebot/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,11 @@ def delete_sticker_set(token, name):
return _make_request(token, method_url, params=payload, method='post')


def get_available_gifts(token):
method_url = 'getAvailableGifts'
return _make_request(token, method_url)


def set_sticker_emoji_list(token, sticker, emoji_list):
method_url = 'setStickerEmojiList'
payload = {'sticker': sticker, 'emoji_list': json.dumps(emoji_list)}
Expand Down
12 changes: 12 additions & 0 deletions telebot/async_telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7707,6 +7707,18 @@ async def delete_sticker_set(self, name:str) -> bool:

return await asyncio_helper.delete_sticker_set(self.token, name)

async def get_available_gifts(self) -> types.Gifts:
"""
Returns the list of gifts that can be sent by the bot to users. Requires no parameters. Returns a Gifts object.
Telegram documentation: https://core.telegram.org/bots/api#getavailablegifts
:return: On success, a Gifts object is returned.
:rtype: :class:`telebot.types.Gifts`
"""

return types.Gifts.de_json(await asyncio_helper.get_available_gifts(self.token))

async def replace_sticker_in_set(self, user_id: int, name: str, old_sticker: str, sticker: types.InputSticker) -> bool:
"""
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet,
Expand Down
4 changes: 4 additions & 0 deletions telebot/asyncio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,10 @@ async def delete_sticker_set(token, name):
payload = {'name': name}
return await _process_request(token, method_url, params=payload, method='post')

async def get_available_gifts(token):
method_url = 'getAvailableGifts'
return await _process_request(token, method_url)

async def set_custom_emoji_sticker_set_thumbnail(token, name, custom_emoji_id=None):
method_url = 'setCustomEmojiStickerSetThumbnail'
payload = {'name': name}
Expand Down
63 changes: 63 additions & 0 deletions telebot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11025,3 +11025,66 @@ def de_json(cls, json_string):
obj = cls.check_json(json_string)
return cls(**obj)


class Gift(JsonDeserializable):
"""
This object represents a gift that can be sent by the bot.
Telegram documentation: https://core.telegram.org/bots/api#gift
:param id: Unique identifier of the gift
:type id: :obj:`str`
:param sticker: The sticker that represents the gift
:type sticker: :class:`Sticker`
:param star_count: The number of Telegram Stars that must be paid to send the sticker
:type star_count: :obj:`int`
:param total_count: Optional. The total number of the gifts of this type that can be sent; for limited gifts only
:type total_count: :obj:`int`
:param remaining_count: Optional. The number of remaining gifts of this type that can be sent; for limited gifts only
:type remaining_count: :obj:`int`
:return: Instance of the class
:rtype: :class:`Gift`
"""

def __init__(self, id, sticker, star_count, total_count=None, remaining_count=None, **kwargs):
self.id: str = id
self.sticker: Sticker = sticker
self.star_count: int = star_count
self.total_count: Optional[int] = total_count
self.remaining_count: Optional[int] = remaining_count

@classmethod
def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
obj['sticker'] = Sticker.de_json(obj['sticker'])
return cls(**obj)

class Gifts(JsonDeserializable):
"""
This object represent a list of gifts.
Telegram documentation: https://core.telegram.org/bots/api#gifts
:param gifts: The list of gifts
:type gifts: :obj:`list` of :class:`Gift`
:return: Instance of the class
:rtype: :class:`Gifts`
"""

def __init__(self, gifts, **kwargs):
self.gifts: List[Gift] = gifts

@classmethod
def de_json(cls, json_string):
if json_string is None: return None
obj = cls.check_json(json_string)
obj['gifts'] = [Gift.de_json(gift) for gift in obj['gifts']]
return cls(**obj)

0 comments on commit 3d740ff

Please sign in to comment.