Skip to content

Commit ef14d4c

Browse files
authored
New bound method for Gift type (#188)
1 parent 213c159 commit ef14d4c

5 files changed

Lines changed: 45 additions & 10 deletions

File tree

pyrogram/methods/payments/get_chat_gifts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import Optional, Union
19+
from typing import Optional, Union, AsyncGenerator
2020

2121
import pyrogram
2222
from pyrogram import raw, types
@@ -34,7 +34,7 @@ async def get_chat_gifts(
3434
sort_by_price: Optional[bool] = None,
3535
limit: int = 0,
3636
offset: str = ""
37-
):
37+
) -> AsyncGenerator["types.Gift", None]:
3838
"""Get all gifts owned by specified chat.
3939
4040
.. include:: /_includes/usable-by/users.rst

pyrogram/methods/payments/get_gift_upgrade_preview.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18-
19-
import re
20-
2118
import pyrogram
2219
from pyrogram import raw, types
2320

@@ -26,7 +23,7 @@ class GetGiftUpgradePreview:
2623
async def get_gift_upgrade_preview(
2724
self: "pyrogram.Client",
2825
gift_id: int
29-
):
26+
) -> "types.GiftUpgradePreview":
3027
"""Return examples of possible upgraded gifts for a regular gift.
3128
3229
.. include:: /_includes/usable-by/users.rst

pyrogram/methods/payments/get_upgraded_gift.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GetUpgradedGift:
2424
async def get_upgraded_gift(
2525
self: "pyrogram.Client",
2626
link: str
27-
):
27+
) -> "types.Gift":
2828
"""Get information about upgraded gift.
2929
3030
.. include:: /_includes/usable-by/users.rst

pyrogram/methods/payments/search_gifts_for_resale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from typing import List, Optional
19+
from typing import List, Optional, AsyncGenerator
2020

2121
import pyrogram
2222
from pyrogram import enums, raw, types
@@ -30,7 +30,7 @@ async def search_gifts_for_resale(
3030
attributes: Optional[List["types.UpgradedGiftAttributeId"]] = None,
3131
limit: int = 0,
3232
offset: str = ""
33-
):
33+
) -> AsyncGenerator["types.Gift", None]:
3434
"""Get upgraded gifts that can be bought from other owners.
3535
3636
.. include:: /_includes/usable-by/users.rst

pyrogram/types/messages_and_media/gift.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import Dict, List, Optional, Union
2121

2222
import pyrogram
23-
from pyrogram import raw, types, utils
23+
from pyrogram import raw, types, utils, enums
2424

2525
from ..object import Object
2626

@@ -600,3 +600,41 @@ async def buy(self) -> Optional["types.Message"]:
600600
gift_link=self.link,
601601
new_owner_chat_id="me"
602602
)
603+
604+
async def send(
605+
self,
606+
chat_id: Union[int, str],
607+
text: Optional[str] = None,
608+
parse_mode: Optional["enums.ParseMode"] = None,
609+
entities: Optional[List["types.MessageEntity"]] = None,
610+
is_private: Optional[bool] = None,
611+
pay_for_upgrade: Optional[bool] = None,
612+
) -> Optional["types.Message"]:
613+
"""Bound method *send* of :obj:`~pyrogram.types.Gift`.
614+
615+
Use as a shortcut for:
616+
617+
.. code-block:: python
618+
619+
await client.send_gift(
620+
chat_id="me",
621+
gift_id=gift.id
622+
)
623+
624+
Example:
625+
.. code-block:: python
626+
627+
await gift.send("me")
628+
629+
Returns:
630+
:obj:`~pyrogram.types.Message`: On success, the sent message is returned.
631+
"""
632+
return await self._client.send_gift(
633+
chat_id=chat_id,
634+
gift_id=self.id,
635+
text=text,
636+
parse_mode=parse_mode,
637+
entities=entities,
638+
is_private=is_private,
639+
pay_for_upgrade=pay_for_upgrade
640+
)

0 commit comments

Comments
 (0)