diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py
index 138f01298..0f9704453 100644
--- a/compiler/docs/compiler.py
+++ b/compiler/docs/compiler.py
@@ -518,6 +518,7 @@ def get_title_list(s: str) -> list:
Venue
Gift
UserGift
+ UpgradedGift
WebAppData
MessageAutoDeleteTimerChanged
ChatBoostAdded
diff --git a/docs/source/releases/changes-in-this-fork.rst b/docs/source/releases/changes-in-this-fork.rst
index d5a404250..727116122 100644
--- a/docs/source/releases/changes-in-this-fork.rst
+++ b/docs/source/releases/changes-in-this-fork.rst
@@ -25,6 +25,7 @@ Changes in this Fork
| Scheme layer used: 196 |
+------------------------+
+- Added the :obj:`~pyrogram.types.UpgradedGift` and changed return type :meth:`~pyrogram.Client.get_available_gifts` and :meth:`~pyrogram.Client.get_user_gifts`.
- Added the ``pay_for_upgrade`` in the :meth:`~pyrogram.Client.send_gift`.
- Added the parameters ``upgrade_star_count`` and ``is_for_birthday`` in :obj:`~pyrogram.types.Gift`.
- Added the :meth:`~pyrogram.Client.on_bot_purchased_paid_media` and :meth:`~pyrogram.Client.on_bot_business_connection`.
diff --git a/pyrogram/methods/business/get_available_gifts.py b/pyrogram/methods/business/get_available_gifts.py
index f2ca2f793..598f44abc 100644
--- a/pyrogram/methods/business/get_available_gifts.py
+++ b/pyrogram/methods/business/get_available_gifts.py
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+from typing import Union
+
import pyrogram
from pyrogram import raw, types
@@ -23,13 +25,13 @@
class GetAvailableGifts:
async def get_available_gifts(
self: "pyrogram.Client",
- ) -> list["types.Gift"]:
+ ) -> list[Union["types.Gift", "types.UpgradedGift"]]:
"""Get all gifts that can be sent to other users.
.. include:: /_includes/usable-by/users-bots.rst
Returns:
- List of :obj:`~pyrogram.types.Gift`: On success, a list of star gifts is returned.
+ List of :obj:`~pyrogram.types.Gift` | :obj:`~pyrogram.types.UpgradedGift`: On success, a list of star gifts is returned.
Example:
.. code-block:: python
diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py
index 87740b9c9..35f71b533 100644
--- a/pyrogram/types/messages_and_media/__init__.py
+++ b/pyrogram/types/messages_and_media/__init__.py
@@ -42,6 +42,7 @@
from .sponsored_message import SponsoredMessage
from .gift import Gift
from .user_gift import UserGift
+from .upgraded_gift import UpgradedGift
from .sticker import Sticker
from .stripped_thumbnail import StrippedThumbnail
from .thumbnail import Thumbnail
@@ -111,6 +112,7 @@
"SponsoredMessage",
"Gift",
"UserGift",
+ "UpgradedGift",
"Sticker",
"Story",
"Venue",
diff --git a/pyrogram/types/messages_and_media/gift.py b/pyrogram/types/messages_and_media/gift.py
index ae2fb27e1..7663eda3b 100644
--- a/pyrogram/types/messages_and_media/gift.py
+++ b/pyrogram/types/messages_and_media/gift.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from datetime import datetime
-from typing import Optional
+from typing import Optional, Union
import pyrogram
from pyrogram import raw, types, utils
@@ -101,8 +101,11 @@ def __init__(
@staticmethod
async def _parse(
client,
- star_gift: "raw.types.StarGift",
- ) -> "Gift":
+ star_gift: "raw.base.StarGift",
+ ) -> Union["Gift", "types.UpgradedGift"]:
+ if isinstance(star_gift, raw.types.StarGiftUnique):
+ return types.UpgradedGift._parse(client, star_gift)
+
doc = star_gift.sticker
attributes = {type(i): i for i in doc.attributes}
diff --git a/pyrogram/types/messages_and_media/upgraded_gift.py b/pyrogram/types/messages_and_media/upgraded_gift.py
new file mode 100644
index 000000000..2d95c2991
--- /dev/null
+++ b/pyrogram/types/messages_and_media/upgraded_gift.py
@@ -0,0 +1,87 @@
+# Pyrogram - Telegram MTProto API Client Library for Python
+# Copyright (C) 2017-present Dan
+#
+# This file is part of Pyrogram.
+#
+# Pyrogram is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pyrogram 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 General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Pyrogram. If not, see .
+
+from typing import Optional
+
+import pyrogram
+from pyrogram import raw, utils
+from ..object import Object
+
+
+class UpgradedGift(Object):
+ """Describes an upgraded gift that can be gifted to another user or transferred to TON blockchain as an NFT.
+
+ Parameters:
+ id (``int``):
+ Unique identifier of the gift.
+
+ title (``str``):
+ The title of the upgraded gift.
+
+ number (``int``):
+ Unique number of the upgraded gift among gifts upgraded from the same gift.
+
+ total_upgraded_count (``int``):
+ Total number of gifts that were upgraded from the same gift.
+
+ max_upgraded_count (``int``):
+ The maximum number of gifts that can be upgraded from the same gift.
+
+ owner_user_id (``int``, *optional*):
+ User identifier of the user that owns the upgraded gift.
+
+ """
+
+ def __init__(
+ self,
+ *,
+ client: "pyrogram.Client" = None,
+ id: int,
+ title: str,
+ number: int,
+ total_upgraded_count: int,
+ max_upgraded_count: int,
+ owner_user_id: Optional[int] = None,
+ _raw: "raw.types.StarGiftUnique" = None,
+ ):
+ super().__init__(client)
+
+ self.id = id
+ self.title = title
+ self.number = number
+ self.total_upgraded_count = total_upgraded_count
+ self.max_upgraded_count = max_upgraded_count
+ self.owner_user_id = owner_user_id
+ self._raw = _raw # TODO
+
+
+ @staticmethod
+ def _parse(
+ client,
+ star_gift: "raw.types.StarGiftUnique"
+ ) -> "UpgradedGift":
+ return UpgradedGift(
+ id=star_gift.id,
+ title=star_gift.title,
+ number=star_gift.num,
+ total_upgraded_count=star_gift.availability_issued,
+ max_upgraded_count=star_gift.availability_total,
+ owner_user_id=utils.get_raw_peer_id(getattr(star_gift, "owner_id", None)),
+ _raw=star_gift,
+ client=client
+ )
diff --git a/pyrogram/types/messages_and_media/user_gift.py b/pyrogram/types/messages_and_media/user_gift.py
index 125dc5b88..f97ef134d 100644
--- a/pyrogram/types/messages_and_media/user_gift.py
+++ b/pyrogram/types/messages_and_media/user_gift.py
@@ -17,7 +17,7 @@
# along with Pyrogram. If not, see .
from datetime import datetime
-from typing import Optional
+from typing import Optional, Union
import pyrogram
from pyrogram import raw, types, utils
@@ -47,7 +47,7 @@ class UserGift(Object):
date (:py:obj:`~datetime.datetime`, *optional*):
Date when the gift was sent.
- gift (:obj:`~pyrogram.types.Gift`, *optional*):
+ gift (:obj:`~pyrogram.types.Gift` | :obj:`~pyrogram.types.UpgradedGift`, *optional*):
Information about the gift.
message_id (``int``, *optional*):
@@ -89,7 +89,7 @@ def __init__(
date: datetime,
is_private: Optional[bool] = None,
is_saved: Optional[bool] = None,
- gift: Optional["types.Gift"] = None,
+ gift: Optional[Union["types.Gift", "types.UpgradedGift"]] = None,
message_id: Optional[int] = None,
sell_star_count: Optional[int] = None,
was_converted: Optional[bool] = None,
@@ -153,9 +153,6 @@ async def _parse_action(
) -> "UserGift":
action = message.action
- doc = action.gift.sticker
- attributes = {type(i): i for i in doc.attributes}
-
text, entities = None, None
if getattr(action, "message", None):
text = action.message.text or None
@@ -164,17 +161,7 @@ async def _parse_action(
if isinstance(action, raw.types.MessageActionStarGift):
return UserGift(
- gift=types.Gift(
- id=action.gift.id,
- sticker=await types.Sticker._parse(client, doc, attributes),
- star_count=action.gift.stars,
- total_count=getattr(action.gift, "availability_total", None),
- remaining_count=getattr(action.gift, "availability_remains", None),
- default_sell_star_count=action.gift.convert_stars,
- is_limited=getattr(action.gift, "limited", None),upgrade_star_count=getattr(star_gift, "upgrade_stars", 0),
- is_for_birthday=getattr(star_gift, "birthday", None),
- client=client
- ),
+ gift=await types.Gift._parse(client, action.gift),
date=utils.timestamp_to_datetime(message.date),
is_private=getattr(action, "name_hidden", None),
is_saved=getattr(action, "saved", None),
@@ -192,18 +179,7 @@ async def _parse_action(
if isinstance(action, raw.types.MessageActionStarGiftUnique):
return UserGift(
- gift=types.Gift(
- id=action.gift.id,
- sticker=await types.Sticker._parse(client, doc, attributes),
- star_count=action.gift.stars,
- total_count=getattr(action.gift, "availability_total", None),
- remaining_count=getattr(action.gift, "availability_remains", None),
- default_sell_star_count=action.gift.convert_stars,
- is_limited=getattr(action.gift, "limited", None),
- upgrade_star_count=getattr(star_gift, "upgrade_stars", 0),
- is_for_birthday=getattr(star_gift, "birthday", None),
- client=client
- ),
+ gift=await types.Gift._parse(client, action.gift),
date=utils.timestamp_to_datetime(message.date),
sender_user=types.User._parse(client, users.get(utils.get_raw_peer_id(message.peer_id))),
message_id=message.id,
@@ -225,7 +201,6 @@ async def toggle(self, is_saved: bool) -> bool:
.. code-block:: python
await client.toggle_gift_is_saved(
- sender_user_id=user_id,
message_id=message_id
)
@@ -243,7 +218,6 @@ async def toggle(self, is_saved: bool) -> bool:
"""
return await self._client.toggle_gift_is_saved(
- sender_user_id=self.sender_user.id,
message_id=self.message_id,
is_saved=is_saved
)