Skip to content

Commit

Permalink
pyrofork: update StarGift type to new layer
Browse files Browse the repository at this point in the history
Signed-off-by: Yasir Aris <git@yasir.id>
  • Loading branch information
KurimuzonAkuma authored and yasirarism committed Jan 3, 2025
1 parent a861db1 commit 49cef06
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 48 deletions.
3 changes: 3 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def get_title_list(s: str) -> list:
send_payment_form
send_star_gift
show_star_gift
transfer_star_gift
upgrade_star_gift
""",
password="""
Password
Expand Down Expand Up @@ -562,6 +564,7 @@ def get_title_list(s: str) -> list:
ScreenshotTaken
Wallpaper
WallpaperSettings
StarGiftAttribute
""",
stories="""
Stories
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,4 @@ async def _execute_callback(self, handler: Handler, *args):
else:
await self.client.loop.run_in_executor(
self.client.executor, handler.callback, self.client, *args
)
)
2 changes: 2 additions & 0 deletions pyrogram/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .reaction_type import ReactionType
from .reply_color import ReplyColor
from .sent_code_type import SentCodeType
from .star_gift_attribute_type import StarGiftAttributeType
from .stories_privacy_rules import StoriesPrivacyRules
from .story_privacy import StoryPrivacy
from .user_status import UserStatus
Expand All @@ -64,6 +65,7 @@
'ReactionType',
'ReplyColor',
'SentCodeType',
'StarGiftAttributeType',
"StoriesPrivacyRules",
"StoryPrivacy",
'UserStatus'
Expand Down
33 changes: 33 additions & 0 deletions pyrogram/enums/star_gift_attribute_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.

from pyrogram import raw
from .auto_name import AutoName


class StarGiftAttributeType(AutoName):
"""Star gift attribute type enumeration used in :obj:`~pyrogram.types.StarGiftAttribute`."""

MODEL = raw.types.StarGiftAttributeModel
"Model attribute"

SYMBOL = raw.types.StarGiftAttributePattern
"Symbol attribute"

BACKDROP = raw.types.StarGiftAttributeBackdrop
"Backdrop attribute"
15 changes: 15 additions & 0 deletions pyrogram/methods/messages/search_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ async def search_global(
self: "pyrogram.Client",
query: str = "",
filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
channels_only: Optional[bool] = None,
groups_only: Optional[bool] = None,
users_only: Optional[bool] = None,
limit: int = 0,
) -> Optional[AsyncGenerator["types.Message", None]]:
"""Search messages globally from all of your chats.
Expand All @@ -56,6 +59,15 @@ async def search_global(
Limits the number of messages to be retrieved.
By default, no limit is applied and all messages are returned.
channels_only (``bool``, *optional*):
Pass True to search only in channels.
groups_only (``bool``, *optional*):
Pass True to search only in groups.
users_only (``bool``, *optional*):
Pass True to search only in users.
Returns:
``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.
Expand Down Expand Up @@ -93,6 +105,9 @@ async def search_global(
offset_rate=offset_date,
offset_peer=offset_peer,
offset_id=offset_id,
broadcasts_only=channels_only,
groups_only=groups_only,
users_only=users_only,
limit=limit
),
sleep_threshold=60
Expand Down
17 changes: 17 additions & 0 deletions pyrogram/methods/messages/search_global_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.

from typing import Optional

import pyrogram
from pyrogram import raw, enums

Expand All @@ -26,6 +28,9 @@ async def search_global_count(
self: "pyrogram.Client",
query: str = "",
filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
channels_only: Optional[bool] = None,
groups_only: Optional[bool] = None,
users_only: Optional[bool] = None,
) -> int:
"""Get the count of messages resulting from a global search.
Expand All @@ -41,6 +46,15 @@ async def search_global_count(
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
Pass a filter in order to search for specific kind of messages only:
channels_only (``bool``, *optional*):
Pass True to search only in channels.
groups_only (``bool``, *optional*):
Pass True to search only in groups.
users_only (``bool``, *optional*):
Pass True to search only in users.
Returns:
``int``: On success, the messages count is returned.
"""
Expand All @@ -53,6 +67,9 @@ async def search_global_count(
offset_rate=0,
offset_peer=raw.types.InputPeerEmpty(),
offset_id=0,
broadcasts_only=channels_only,
groups_only=groups_only,
users_only=users_only,
limit=1
)
)
Expand Down
6 changes: 5 additions & 1 deletion pyrogram/methods/payments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
from .send_payment_form import SendPaymentForm
from .send_star_gift import SendStarGift
from .show_star_gift import ShowStarGift
from .transfer_star_gift import TransferStarGift
from .upgrade_star_gift import UpgradeStarGift

class Payments(
ApplyGiftCode,
Expand All @@ -54,6 +56,8 @@ class Payments(
SendInvoice,
SendPaymentForm,
SendStarGift,
ShowStarGift
ShowStarGift,
TransferStarGift,
UpgradeStarGift
):
pass
14 changes: 1 addition & 13 deletions pyrogram/methods/payments/convert_star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,13 @@
class ConvertStarGift:
async def convert_star_gift(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_id: int
) -> bool:
"""Convert star gift to stars.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
message_id (``int``):
Unique message identifier of star gift.
Expand All @@ -50,16 +44,10 @@ async def convert_star_gift(
.. code-block:: python
# Convert gift
app.convert_star_gift(chat_id=chat_id, message_id=123)
app.convert_star_gift(message_id=123)
"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
raise ValueError("chat_id must belong to a user.")

r = await self.invoke(
raw.functions.payments.ConvertStarGift(
user_id=peer,
msg_id=message_id
)
)
Expand Down
17 changes: 1 addition & 16 deletions pyrogram/methods/payments/hide_star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,20 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.


from typing import Union

import pyrogram
from pyrogram import raw


class HideStarGift:
async def hide_star_gift(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_id: int
) -> bool:
"""Hide the star gift from your profile.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
message_id (``int``):
Unique message identifier of star gift.
Expand All @@ -50,16 +41,10 @@ async def hide_star_gift(
.. code-block:: python
# Hide gift
app.hide_star_gift(chat_id=chat_id, message_id=123)
app.hide_star_gift(message_id=123)
"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
raise ValueError("chat_id must belong to a user.")

r = await self.invoke(
raw.functions.payments.SaveStarGift(
user_id=peer,
msg_id=message_id,
unsave=True
)
Expand Down
17 changes: 1 addition & 16 deletions pyrogram/methods/payments/show_star_gift.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,20 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.


from typing import Union

import pyrogram
from pyrogram import raw


class ShowStarGift:
async def show_star_gift(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_id: int
) -> bool:
"""Display the star gift in your profile.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
message_id (``int``):
Unique message identifier of star gift.
Expand All @@ -49,16 +40,10 @@ async def show_star_gift(
.. code-block:: python
# Show gift
app.show_star_gift(chat_id=chat_id, message_id=123)
app.show_star_gift(message_id=123)
"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
raise ValueError("chat_id must belong to a user.")

r = await self.invoke(
raw.functions.payments.SaveStarGift(
user_id=peer,
msg_id=message_id,
unsave=False
)
Expand Down
65 changes: 65 additions & 0 deletions pyrogram/methods/payments/transfer_star_gift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.

from typing import Union

import pyrogram
from pyrogram import raw


class TransferStarGift:
async def transfer_star_gift(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_id: int,
) -> bool:
"""Transfer star gift to another user.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat you want to transfer the star gift to.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
message_id (``int``):
Unique message identifier of star gift.
Returns:
``bool``: On success, True is returned.
Example:
.. code-block:: python
# Show gift
app.transfer_star_gift(chat_id=123, message_id=123)
"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
raise ValueError("chat_id must belong to a user.")

await self.invoke(
raw.functions.payments.TransferStarGift(
msg_id=message_id,
keep_original_details=keep_details
)
)

return True # TODO:
Loading

0 comments on commit 49cef06

Please sign in to comment.