-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary by Sourcery Add new features for sending and managing gifts, including methods for sending gifts and managing their visibility. Enhance the chat event system with new event types and improve message handling with support for new message types and translation. Update the build process to separate build and publish steps. New Features: - Introduce the ability to send and manage gifts, including methods for sending gifts, getting available gifts, and toggling gift visibility on user profiles. - Add support for new message types such as user gifts, star gifts, and gift codes, enhancing the messaging capabilities. - Implement a new method for translating message text to different languages, expanding the functionality of message handling. Enhancements: - Enhance the chat event system by adding new event types related to usernames, membership changes, and chat settings toggles. - Improve the message reply system by adding support for cross-chat replies and allowing paid broadcasts for bots. - Refactor the message parsing logic to support new service message types and improve the handling of existing ones. Build: - Update the build and publish process in the CI workflow to separate the build and publish steps, and switch to using a GitHub Action for publishing to PyPI.
- Loading branch information
Showing
53 changed files
with
1,317 additions
and
219 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,6 +7,8 @@ on: | |
|
||
jobs: | ||
lint-format-and-test: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
from __future__ import annotations | ||
|
||
import pyrogram | ||
from pyrogram import raw, types | ||
|
||
|
||
class GetAvailableGifts: | ||
async def get_available_gifts( | ||
self: pyrogram.Client, | ||
) -> list[types.Gift]: | ||
"""Get all gifts that can be sent to other users. | ||
.. include:: /_includes/usable-by/users.rst | ||
Returns: | ||
List of :obj:`~pyrogram.types.Gift`: On success, a list of star gifts is returned. | ||
Example: | ||
.. code-block:: python | ||
app.get_available_gifts() | ||
""" | ||
r = await self.invoke(raw.functions.payments.GetStarGifts(hash=0)) | ||
|
||
return types.List([await types.Gift._parse(self, gift) for gift in r.gifts]) |
This file contains 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,81 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pyrogram | ||
from pyrogram import raw, types | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import AsyncGenerator | ||
|
||
|
||
class GetUserGifts: | ||
async def get_user_gifts( | ||
self: pyrogram.Client, | ||
user_id: int | str, | ||
offset: str = "", | ||
limit: int = 0, | ||
) -> AsyncGenerator[types.UserGift, None] | None: | ||
"""Get gifts saved to profile by the given user. | ||
.. include:: /_includes/usable-by/users.rst | ||
Parameters: | ||
user_id (``int`` | ``str``): | ||
Unique identifier (int) or username (str) of the target user. | ||
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). | ||
offset (``str``, *optional*): | ||
Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results. | ||
limit (``int``, *optional*): | ||
The maximum number of gifts to be returned; must be positive and can't be greater than 100. For optimal performance, the number of returned objects is chosen by Telegram Server and can be smaller than the specified limit. | ||
Returns: | ||
``Generator``: A generator yielding :obj:`~pyrogram.types.UserGift` objects. | ||
Example: | ||
.. code-block:: python | ||
async for user_gift in app.get_user_gifts(user_id): | ||
print(user_gift) | ||
""" | ||
peer = await self.resolve_peer(user_id) | ||
|
||
if not isinstance(peer, raw.types.InputPeerUser | raw.types.InputPeerSelf): | ||
raise ValueError("user_id must belong to a user.") | ||
|
||
current = 0 | ||
total = abs(limit) or (1 << 31) - 1 | ||
limit = min(100, total) | ||
|
||
while True: | ||
r = await self.invoke( | ||
raw.functions.payments.GetUserStarGifts( | ||
user_id=peer, offset=offset, limit=limit | ||
), | ||
sleep_threshold=max(60, self.sleep_threshold), | ||
) | ||
|
||
users = {u.id: u for u in r.users} | ||
|
||
user_gifts = [ | ||
await types.UserGift._parse(self, gift, users) for gift in r.gifts | ||
] | ||
|
||
if not user_gifts: | ||
return | ||
|
||
for user_gift in user_gifts: | ||
yield user_gift | ||
|
||
current += 1 | ||
|
||
if current >= total: | ||
return | ||
|
||
offset = r.next_offset | ||
|
||
if not offset: | ||
return |
Oops, something went wrong.