- Notifications
You must be signed in to change notification settings - Fork5.7k
Bot API 8.0: Gifts#4576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Bot API 8.0: Gifts#4576
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
769dcf5
Add `Gift` and `Gifts`
Bibo-Joshi6417fa3
Add `TransactionPartnerUser.(subscription_period|gift)`
Bibo-Joshi305f482
Improve Type Completeness
Bibo-Joshi677cd92
Add `Bot.(get_available_gifs|send_gift)`
Bibo-Joshi090f67c
Add Defaults Handling to `send_gift`
Bibo-Joshi1e077cf
Add Shortcut Methods
Bibo-Joshi9feb130
Add constants
Bibo-Joshid6fbcfb
fix a typo
Bibo-JoshiFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletionsdocs/source/inclusions/bot_methods.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletiondocs/source/telegram.at-tree.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletionsdocs/source/telegram.gift.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Gift | ||
==== | ||
.. autoclass:: telegram.Gift | ||
:members: | ||
:show-inheritance: |
6 changes: 6 additions & 0 deletionsdocs/source/telegram.gifts.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Gifts | ||
===== | ||
.. autoclass:: telegram.Gifts | ||
:members: | ||
:show-inheritance: |
3 changes: 3 additions & 0 deletionsdocs/source/telegram.stickers-tree.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionstelegram/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletionstelegram/_bot.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletionstelegram/_chat.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletionstelegram/_gifts.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#!/usr/bin/env python | ||
# pylint: disable=redefined-builtin | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2024 | ||
# Leandro Toledo de Souza <devs@python-telegram-bot.org> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser Public License | ||
# along with this program. If not, see [http://www.gnu.org/licenses/] | ||
"""This module contains classes related to gifs sent by bots.""" | ||
from collections.abc import Sequence | ||
from typing import TYPE_CHECKING, Optional | ||
from telegram._files.sticker import Sticker | ||
from telegram._telegramobject import TelegramObject | ||
from telegram._utils.argumentparsing import parse_sequence_arg | ||
from telegram._utils.types import JSONDict | ||
if TYPE_CHECKING: | ||
from telegram import Bot | ||
class Gift(TelegramObject): | ||
"""This object represents a gift that can be sent by the bot. | ||
Objects of this class are comparable in terms of equality. Two objects of this class are | ||
considered equal if their :attr:`id` is equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
id (:obj:`str`): Unique identifier of the gift | ||
sticker (:class:`~telegram.Sticker`): The sticker that represents the gift | ||
star_count (:obj:`int`): The number of Telegram Stars that must be paid to send the sticker | ||
total_count (:obj:`int`, optional): The total number of the gifts of this type that can be | ||
sent; for limited gifts only | ||
remaining_count (:obj:`int`, optional): The number of remaining gifts of this type that can | ||
be sent; for limited gifts only | ||
Attributes: | ||
id (:obj:`str`): Unique identifier of the gift | ||
sticker (:class:`~telegram.Sticker`): The sticker that represents the gift | ||
star_count (:obj:`int`): The number of Telegram Stars that must be paid to send the sticker | ||
total_count (:obj:`int`): Optional. The total number of the gifts of this type that can be | ||
sent; for limited gifts only | ||
remaining_count (:obj:`int`): Optional. The number of remaining gifts of this type that can | ||
be sent; for limited gifts only | ||
""" | ||
__slots__ = ("id", "remaining_count", "star_count", "sticker", "total_count") | ||
def __init__( | ||
self, | ||
id: str, | ||
sticker: Sticker, | ||
star_count: int, | ||
total_count: Optional[int] = None, | ||
remaining_count: Optional[int] = None, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_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 | ||
self._id_attrs = (self.id,) | ||
self._freeze() | ||
@classmethod | ||
def de_json(cls, data: Optional[JSONDict], bot: Optional["Bot"] = None) -> Optional["Gift"]: | ||
"""See :meth:`telegram.TelegramObject.de_json`.""" | ||
data = cls._parse_data(data) | ||
if not data: | ||
return None | ||
data["sticker"] = Sticker.de_json(data.get("sticker"), bot) | ||
return cls(**data) | ||
class Gifts(TelegramObject): | ||
"""This object represent a list of gifts. | ||
Objects of this class are comparable in terms of equality. Two objects of this class are | ||
considered equal if their :attr:`gifts` are equal. | ||
.. versionadded:: NEXT.VERSION | ||
Args: | ||
gifts (Sequence[:class:`Gift`]): The sequence of gifts | ||
Attributes: | ||
gifts (tuple[:class:`Gift`]): The sequence of gifts | ||
""" | ||
__slots__ = ("gifts",) | ||
def __init__( | ||
self, | ||
gifts: Sequence[Gift], | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.gifts: tuple[Gift, ...] = parse_sequence_arg(gifts) | ||
self._id_attrs = (self.gifts,) | ||
self._freeze() | ||
@classmethod | ||
def de_json(cls, data: Optional[JSONDict], bot: Optional["Bot"] = None) -> Optional["Gifts"]: | ||
"""See :meth:`telegram.TelegramObject.de_json`.""" | ||
data = cls._parse_data(data) | ||
if not data: | ||
return None | ||
data["gifts"] = Gift.de_list(data.get("gifts"), bot) | ||
return cls(**data) |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.