Skip to content

Commit 4db60b4

Browse files
feat: Bot API 10.2 (1/3 - Communities)
1 parent 5826bce commit 4db60b4

15 files changed

Lines changed: 756 additions & 163 deletions

compiler/docs/compiler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,15 @@ def get_title_list(s: str) -> list:
717717
GlobalPrivacySettings
718718
HistoryCleared
719719
ChatFolderInviteLinkInfo
720+
Community
721+
CommunityAdministratorRights
722+
CommunityMemberStatus
723+
CommunityMemberStatusCreator
724+
CommunityMemberStatusAdministrator
725+
CommunityMemberStatusMember
726+
CommunityMemberStatusLeft
727+
CommunityMemberStatusBanned
728+
CommunityPermissions
720729
""",
721730
messages_media="""
722731
Messages & Media
@@ -859,6 +868,8 @@ def get_title_list(s: str) -> list:
859868
ChecklistTask
860869
ChecklistTasksAdded
861870
ChecklistTasksDone
871+
CommunityChatAdded
872+
CommunityChatRemoved
862873
Checklist
863874
RefundedPayment
864875
ReplyParameters

pyrogram/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def set_parse_mode(self, parse_mode: Optional["enums.ParseMode"]):
746746

747747
self.parse_mode = parse_mode
748748

749-
async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, raw.types.Channel]]) -> bool:
749+
async def fetch_peers(self, peers: List[Union["raw.base.User", "raw.base.Chat"]]) -> bool:
750750
is_min = False
751751
parsed_peers = []
752752
parsed_usernames = []
@@ -786,6 +786,10 @@ async def fetch_peers(self, peers: List[Union[raw.types.User, raw.types.Chat, ra
786786
peer_id = utils.get_channel_id(peer.id)
787787
access_hash = peer.access_hash
788788
peer_type = "channel" if peer.broadcast else "supergroup"
789+
elif isinstance(peer, (raw.types.Community, raw.types.CommunityForbidden)):
790+
peer_id = utils.get_channel_id(peer.id)
791+
access_hash = peer.access_hash
792+
peer_type = "community"
789793
else:
790794
continue
791795

pyrogram/enums/message_service_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ class MessageServiceType(AutoName):
222222
CHECKLIST_TASKS_ADDED = auto()
223223
"Checklist tasks added"
224224

225+
COMMUNITY_CHAT_ADDED = auto()
226+
"Community chat added"
227+
228+
COMMUNITY_CHAT_REMOVED = auto()
229+
"Community chat removed"
230+
225231
UPGRADED_GIFT_PURCHASE_OFFER = auto()
226232
"Upgraded gift purchase offer"
227233

pyrogram/storage/sqlite_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def get_input_peer(peer_id: int, access_hash: int, peer_type: str):
141141
chat_id=-peer_id
142142
)
143143

144-
if peer_type in ["direct", "channel", "forum", "supergroup"]:
144+
if peer_type in ["direct", "channel", "forum", "supergroup", "community"]:
145145
return raw.types.InputPeerChannel(
146146
channel_id=utils.get_channel_id(peer_id),
147147
access_hash=access_hash

pyrogram/types/messages_and_media/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from .checklist_task import ChecklistTask
3737
from .checklist_tasks_added import ChecklistTasksAdded
3838
from .checklist_tasks_done import ChecklistTasksDone
39+
from .community_chat_added import CommunityChatAdded
40+
from .community_chat_removed import CommunityChatRemoved
3941
from .contact import Contact
4042
from .contact_registered import ContactRegistered
4143
from .craft_gift_result import CraftGiftResult, CraftGiftResultFail, CraftGiftResultSuccess
@@ -235,6 +237,8 @@
235237
"ChecklistTask",
236238
"ChecklistTasksAdded",
237239
"ChecklistTasksDone",
240+
"CommunityChatAdded",
241+
"CommunityChatRemoved",
238242
"Contact",
239243
"ContactRegistered",
240244
"CraftGiftResult",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Dict
20+
21+
import pyrogram
22+
from pyrogram import raw, types
23+
24+
from ..object import Object
25+
26+
27+
class CommunityChatAdded(Object):
28+
"""Describes a service message about a chat being added to a community.
29+
30+
Parameters:
31+
community (:obj:`~pyrogram.types.Community`):
32+
The new community to which the chat belongs.
33+
"""
34+
35+
def __init__(self, *, community: "types.ChecklistTask"):
36+
super().__init__()
37+
38+
self.community = community
39+
40+
@staticmethod
41+
def _parse(
42+
client: "pyrogram.Client",
43+
action: "raw.types.MessageActionChangeCommunity",
44+
chats: Dict[int, "raw.base.Chat"],
45+
) -> "CommunityChatAdded":
46+
return CommunityChatAdded(
47+
community=types.Community._parse(client, chats.get(action.community_id)),
48+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from ..object import Object
20+
21+
22+
class CommunityChatRemoved(Object):
23+
"""Describes a service message about a chat being removed from a community.
24+
25+
Currently holds no information.
26+
"""
27+
28+
def __init__(self):
29+
super().__init__()

pyrogram/types/messages_and_media/message.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,12 @@ class Message(Object, Update):
438438
checklist_tasks_added (:obj:`~pyrogram.types.ChecklistTasksAdded`, *optional*):
439439
Service message: checklist tasks added.
440440
441+
community_chat_added (:obj:`~pyrogram.types.CommunityChatAdded`, *optional*):
442+
Service message: chat added to a Community.
443+
444+
community_chat_removed (:obj:`~pyrogram.types.CommunityChatRemoved`, *optional*):
445+
Service message: chat removed from a Community.
446+
441447
premium_gift_code (:obj:`~pyrogram.types.PremiumGiftCode`, *optional*):
442448
Service message: premium gift code information.
443449
@@ -734,6 +740,8 @@ def __init__(
734740
direct_message_price_changed: Optional["types.DirectMessagePriceChanged"] = None,
735741
checklist_tasks_done: Optional[List["types.ChecklistTasksDone"]] = None,
736742
checklist_tasks_added: Optional[List["types.ChecklistTasksAdded"]] = None,
743+
community_chat_added: Optional[List["types.CommunityChatAdded"]] = None,
744+
community_chat_removed: Optional[List["types.CommunityChatRemoved"]] = None,
737745
premium_gift_code: Optional["types.PremiumGiftCode"] = None,
738746
gifted_premium: Optional["types.GiftedPremium"] = None,
739747
gifted_stars: Optional["types.GiftedStars"] = None,
@@ -916,6 +924,8 @@ def __init__(
916924
self.direct_message_price_changed = direct_message_price_changed
917925
self.checklist_tasks_done = checklist_tasks_done
918926
self.checklist_tasks_added = checklist_tasks_added
927+
self.community_chat_added = community_chat_added
928+
self.community_chat_removed = community_chat_removed
919929
self.premium_gift_code = premium_gift_code
920930
self.gifted_premium = gifted_premium
921931
self.gifted_stars = gifted_stars
@@ -1064,6 +1074,8 @@ async def _parse_service(
10641074
direct_message_price_changed = None
10651075
checklist_tasks_done = None
10661076
checklist_tasks_added = None
1077+
community_chat_added = None
1078+
community_chat_removed = None
10671079

10681080
service_type = enums.MessageServiceType.UNSUPPORTED
10691081

@@ -1335,6 +1347,14 @@ async def _parse_service(
13351347
elif isinstance(action, raw.types.MessageActionTodoAppendTasks):
13361348
service_type = enums.MessageServiceType.CHECKLIST_TASKS_ADDED
13371349
checklist_tasks_added = types.ChecklistTasksAdded._parse(client, message, users, chats)
1350+
elif isinstance(action, raw.types.MessageActionChangeCommunity):
1351+
if action.community_id:
1352+
service_type = enums.MessageServiceType.COMMUNITY_CHAT_ADDED
1353+
community_chat_added = types.CommunityChatAdded._parse(client, action, chats)
1354+
else:
1355+
service_type = enums.MessageServiceType.COMMUNITY_CHAT_REMOVED
1356+
community_chat_removed = types.CommunityChatRemoved()
1357+
13381358

13391359
parsed_message = Message(
13401360
id=message.id,
@@ -1411,6 +1431,8 @@ async def _parse_service(
14111431
direct_message_price_changed=direct_message_price_changed,
14121432
checklist_tasks_done=checklist_tasks_done,
14131433
checklist_tasks_added=checklist_tasks_added,
1434+
community_chat_added=community_chat_added,
1435+
community_chat_removed=community_chat_removed,
14141436
reactions=types.MessageReactions._parse(client, message.reactions, users, chats),
14151437
business_connection_id=business_connection_id,
14161438
raw=message,

pyrogram/types/user_and_chats/__init__.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,31 @@
3434
from .chat_folder_invite_link_info import ChatFolderInviteLinkInfo
3535
from .chat_invite_link import ChatInviteLink
3636
from .chat_join_request import ChatJoinRequest
37-
from .chat_join_result import ChatJoinResult, ChatJoinResultSuccess, ChatJoinResultRequestSent, ChatJoinResultGuardBotApprovalRequired, ChatJoinResultDeclined
37+
from .chat_join_result import (
38+
ChatJoinResult,
39+
ChatJoinResultDeclined,
40+
ChatJoinResultGuardBotApprovalRequired,
41+
ChatJoinResultRequestSent,
42+
ChatJoinResultSuccess,
43+
)
3844
from .chat_joiner import ChatJoiner
3945
from .chat_member import ChatMember
4046
from .chat_member_updated import ChatMemberUpdated
4147
from .chat_permissions import ChatPermissions
4248
from .chat_photo import ChatPhoto
4349
from .chat_reactions import ChatReactions
4450
from .chat_settings import ChatSettings
51+
from .community import Community
52+
from .community_administrator_rights import CommunityAdministratorRights
53+
from .community_member_status import (
54+
CommunityMemberStatus,
55+
CommunityMemberStatusAdministrator,
56+
CommunityMemberStatusBanned,
57+
CommunityMemberStatusCreator,
58+
CommunityMemberStatusLeft,
59+
CommunityMemberStatusMember,
60+
)
61+
from .community_permissions import CommunityPermissions
4562
from .dialog import Dialog
4663
from .emoji_status import EmojiStatus
4764
from .failed_to_add_member import FailedToAddMember
@@ -86,10 +103,10 @@
86103
"ChatInviteLink",
87104
"ChatJoinRequest",
88105
"ChatJoinResult",
89-
"ChatJoinResultSuccess",
90-
"ChatJoinResultRequestSent",
91-
"ChatJoinResultGuardBotApprovalRequired",
92106
"ChatJoinResultDeclined",
107+
"ChatJoinResultGuardBotApprovalRequired",
108+
"ChatJoinResultRequestSent",
109+
"ChatJoinResultSuccess",
93110
"ChatJoiner",
94111
"ChatMember",
95112
"ChatMemberUpdated",
@@ -98,6 +115,15 @@
98115
"ChatPrivileges",
99116
"ChatReactions",
100117
"ChatSettings",
118+
"Community",
119+
"CommunityAdministratorRights",
120+
"CommunityMemberStatus",
121+
"CommunityMemberStatusAdministrator",
122+
"CommunityMemberStatusBanned",
123+
"CommunityMemberStatusCreator",
124+
"CommunityMemberStatusLeft",
125+
"CommunityMemberStatusMember",
126+
"CommunityPermissions",
101127
"Dialog",
102128
"EmojiStatus",
103129
"FailedToAddMember",
@@ -120,5 +146,5 @@
120146
"VideoChatEnded",
121147
"VideoChatMembersInvited",
122148
"VideoChatScheduled",
123-
"VideoChatStarted"
149+
"VideoChatStarted",
124150
]

0 commit comments

Comments
 (0)