Skip to content

Commit 1d75fbf

Browse files
author
Pyrogram-Mod - Dev
committed
feat(layer-228): implement Communities, Ephemeral messages and layer 228 API
New raw types from layer 228 TL (make api): - community, communityForbidden, communityFull, communityPeer, communityPeerRequest - ephemeralMessage, updateNew/Edit/DeleteEphemeralMessage - textDiff, dialogCommunity, dialogPeerCommunity, inputDialogPeerCommunity - inputNotifyCommunity, notifyCommunity, messageActionChangeCommunity - inputReplyToEphemeralMessage, chatInviteJoinResultWebView - inputAiComposeToneSingleUse, botCommand.ephemeral flag New high-level methods: - communities: create_community, get_joined_communities, toggle_community_peer_link, approve_community_peer_link, approve_all_community_peer_links, get_community_peer_link_requests, ban_community_participant, toggle_community_collapsed, get_community_participant_chats - ephemeral: send_ephemeral_message, delete_ephemeral_message, get_ephemeral_callback_answer, report_ephemeral_message - messages: translate_rich_message, compose_rich_message_with_ai, request_chat_join_web_view ChatPrivileges/ChatPermissions: add can_manage_linked_peers
1 parent 0f3d51c commit 1d75fbf

22 files changed

Lines changed: 815 additions & 2 deletions

pyrogram/methods/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
from .auth import Auth
2121
from .bots import Bots
2222
from .chats import Chats
23+
from .communities import Communities
2324
from .contacts import Contacts
2425
from .decorators import Decorators
26+
from .ephemeral import Ephemeral
2527
from .invite_links import InviteLinks
2628
from .messages import Messages
2729
from .password import Password
@@ -33,7 +35,9 @@ class Methods(
3335
Advanced,
3436
Auth,
3537
Bots,
38+
Communities,
3639
Contacts,
40+
Ephemeral,
3741
Password,
3842
Chats,
3943
Users,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from .approve_all_community_peer_links import ApproveAllCommunityPeerLinks
2+
from .approve_community_peer_link import ApproveCommunityPeerLink
3+
from .ban_community_participant import BanCommunityParticipant
4+
from .create_community import CreateCommunity
5+
from .get_community_participant_chats import GetCommunityParticipantChats
6+
from .get_community_peer_link_requests import GetCommunityPeerLinkRequests
7+
from .get_joined_communities import GetJoinedCommunities
8+
from .toggle_community_collapsed import ToggleCommunityCollapsed
9+
from .toggle_community_peer_link import ToggleCommunityPeerLink
10+
11+
12+
class Communities(
13+
ApproveAllCommunityPeerLinks,
14+
ApproveCommunityPeerLink,
15+
BanCommunityParticipant,
16+
CreateCommunity,
17+
GetCommunityParticipantChats,
18+
GetCommunityPeerLinkRequests,
19+
GetJoinedCommunities,
20+
ToggleCommunityCollapsed,
21+
ToggleCommunityPeerLink,
22+
):
23+
pass
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing import Union
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class ApproveAllCommunityPeerLinks:
8+
async def approve_all_community_peer_links(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
reject: bool = False
12+
) -> bool:
13+
"""Approve or reject all pending peer link requests in a community.
14+
15+
.. include:: /_includes/usable-by/users.rst
16+
17+
Parameters:
18+
community_id (``int`` | ``str``):
19+
The community channel.
20+
21+
reject (``bool``, *optional*):
22+
Pass True to reject all instead of approving. Defaults to False.
23+
24+
Returns:
25+
``bool``: True on success.
26+
27+
Example:
28+
.. code-block:: python
29+
30+
await app.approve_all_community_peer_links(community_id)
31+
"""
32+
33+
community = await self.resolve_peer(community_id)
34+
35+
await self.invoke(
36+
raw.functions.communities.ToggleAllPeerLinkRequestApproval(
37+
community=community,
38+
reject=reject or None
39+
)
40+
)
41+
42+
return True
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import Union, Optional
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class ApproveCommunityPeerLink:
8+
async def approve_community_peer_link(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
peer_id: Union[int, str],
12+
reject: bool = False
13+
) -> bool:
14+
"""Approve or reject a peer link request in a community.
15+
16+
.. include:: /_includes/usable-by/users.rst
17+
18+
Parameters:
19+
community_id (``int`` | ``str``):
20+
The community channel.
21+
22+
peer_id (``int`` | ``str``):
23+
The peer whose request to approve or reject.
24+
25+
reject (``bool``, *optional*):
26+
Pass True to reject instead of approving. Defaults to False.
27+
28+
Returns:
29+
``bool``: True on success.
30+
31+
Example:
32+
.. code-block:: python
33+
34+
await app.approve_community_peer_link(community_id, peer_id)
35+
await app.approve_community_peer_link(community_id, peer_id, reject=True)
36+
"""
37+
38+
community = await self.resolve_peer(community_id)
39+
peer = await self.resolve_peer(peer_id)
40+
41+
await self.invoke(
42+
raw.functions.communities.TogglePeerLinkRequestApproval(
43+
community=community,
44+
peer=peer,
45+
reject=reject or None
46+
)
47+
)
48+
49+
return True
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import Union
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class BanCommunityParticipant:
8+
async def ban_community_participant(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
participant_id: Union[int, str],
12+
unban: bool = False
13+
) -> bool:
14+
"""Ban or unban a participant in a community.
15+
16+
.. include:: /_includes/usable-by/users.rst
17+
18+
Parameters:
19+
community_id (``int`` | ``str``):
20+
The community channel.
21+
22+
participant_id (``int`` | ``str``):
23+
The participant to ban or unban.
24+
25+
unban (``bool``, *optional*):
26+
Pass True to unban. Defaults to False.
27+
28+
Returns:
29+
``bool``: True on success.
30+
31+
Example:
32+
.. code-block:: python
33+
34+
await app.ban_community_participant(community_id, user_id)
35+
await app.ban_community_participant(community_id, user_id, unban=True)
36+
"""
37+
38+
community = await self.resolve_peer(community_id)
39+
participant = await self.resolve_peer(participant_id)
40+
41+
await self.invoke(
42+
raw.functions.communities.ToggleParticipantBanned(
43+
community=community,
44+
participant=participant,
45+
unban=unban or None
46+
)
47+
)
48+
49+
return True
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from typing import Union, Optional
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class CreateCommunity:
8+
async def create_community(
9+
self: "pyrogram.Client",
10+
chat_id: Union[int, str],
11+
title: str,
12+
about: Optional[str] = None
13+
) -> "raw.base.Updates":
14+
"""Create a community linked to a channel or supergroup.
15+
16+
.. include:: /_includes/usable-by/users.rst
17+
18+
Parameters:
19+
chat_id (``int`` | ``str``):
20+
The channel or supergroup to link the community to.
21+
22+
title (``str``):
23+
Community title.
24+
25+
about (``str``, *optional*):
26+
Community description.
27+
28+
Returns:
29+
:obj:`~pyrogram.raw.base.Updates`: On success.
30+
31+
Example:
32+
.. code-block:: python
33+
34+
await app.create_community(-100123456789, "My Community")
35+
"""
36+
37+
peer = await self.resolve_peer(chat_id)
38+
39+
return await self.invoke(
40+
raw.functions.communities.Create(
41+
title=title,
42+
peer=peer,
43+
about=about
44+
)
45+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import Union
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class GetCommunityParticipantChats:
8+
async def get_community_participant_chats(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
participant_id: Union[int, str]
12+
) -> "raw.base.ParticipantJoinedChats":
13+
"""Get chats joined by a participant in a community.
14+
15+
.. include:: /_includes/usable-by/users.rst
16+
17+
Parameters:
18+
community_id (``int`` | ``str``):
19+
The community channel.
20+
21+
participant_id (``int`` | ``str``):
22+
The participant.
23+
24+
Returns:
25+
:obj:`~pyrogram.raw.base.ParticipantJoinedChats`: Chats the participant joined.
26+
27+
Example:
28+
.. code-block:: python
29+
30+
result = await app.get_community_participant_chats(community_id, user_id)
31+
"""
32+
33+
community = await self.resolve_peer(community_id)
34+
participant = await self.resolve_peer(participant_id)
35+
36+
return await self.invoke(
37+
raw.functions.communities.GetParticipantJoinedChats(
38+
community=community,
39+
participant=participant
40+
)
41+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from typing import Union
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class GetCommunityPeerLinkRequests:
8+
async def get_community_peer_link_requests(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
offset: str = "",
12+
limit: int = 100
13+
) -> "raw.base.PeerLinkRequests":
14+
"""Get pending peer link requests for a community.
15+
16+
.. include:: /_includes/usable-by/users.rst
17+
18+
Parameters:
19+
community_id (``int`` | ``str``):
20+
The community channel.
21+
22+
offset (``str``, *optional*):
23+
Pagination offset. Defaults to empty string (start from beginning).
24+
25+
limit (``int``, *optional*):
26+
Maximum number of results. Defaults to 100.
27+
28+
Returns:
29+
:obj:`~pyrogram.raw.base.PeerLinkRequests`: The pending requests.
30+
31+
Example:
32+
.. code-block:: python
33+
34+
requests = await app.get_community_peer_link_requests(community_id)
35+
"""
36+
37+
community = await self.resolve_peer(community_id)
38+
39+
return await self.invoke(
40+
raw.functions.communities.GetPeerLinkRequests(
41+
community=community,
42+
offset=offset,
43+
limit=limit
44+
)
45+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pyrogram
2+
from pyrogram import raw
3+
4+
5+
class GetJoinedCommunities:
6+
async def get_joined_communities(
7+
self: "pyrogram.Client"
8+
) -> "raw.base.messages.Chats":
9+
"""Get the list of communities the current user has joined.
10+
11+
.. include:: /_includes/usable-by/users.rst
12+
13+
Returns:
14+
:obj:`~pyrogram.raw.base.messages.Chats`: List of community chats.
15+
16+
Example:
17+
.. code-block:: python
18+
19+
communities = await app.get_joined_communities()
20+
"""
21+
22+
return await self.invoke(raw.functions.communities.GetJoinedCommunities())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from typing import Union, Optional
2+
3+
import pyrogram
4+
from pyrogram import raw
5+
6+
7+
class ToggleCommunityCollapsed:
8+
async def toggle_community_collapsed(
9+
self: "pyrogram.Client",
10+
community_id: Union[int, str],
11+
collapsed: Optional[bool] = None
12+
) -> "raw.base.Updates":
13+
"""Toggle whether a community is collapsed in the dialogs list.
14+
15+
.. include:: /_includes/usable-by/users.rst
16+
17+
Parameters:
18+
community_id (``int`` | ``str``):
19+
The community channel.
20+
21+
collapsed (``bool``, *optional*):
22+
Pass True to collapse, False to expand.
23+
24+
Returns:
25+
:obj:`~pyrogram.raw.base.Updates`: On success.
26+
27+
Example:
28+
.. code-block:: python
29+
30+
await app.toggle_community_collapsed(community_id, collapsed=True)
31+
"""
32+
33+
community = await self.resolve_peer(community_id)
34+
35+
return await self.invoke(
36+
raw.functions.communities.ToggleCommunityCollapsedInDialogs(
37+
community=community,
38+
collapsed=collapsed
39+
)
40+
)

0 commit comments

Comments
 (0)