Skip to content

Commit d1528d0

Browse files
committed
Added CHAT_OWNER_LEFT, CHAT_OWNER_CHANGED, CHAT_HAS_PROTECTED_CONTENT_TOGGLED, CHAT_HAS_PROTECTED_CONTENT_DISABLE_REQUESTED to Message
1 parent 7cd5a8c commit d1528d0

File tree

10 files changed

+290
-3
lines changed

10 files changed

+290
-3
lines changed

compiler/docs/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ def get_title_list(s: str) -> list:
663663
ContactRegistered
664664
ScreenshotTaken
665665
DraftMessage
666+
ChatOwnerLeft
667+
ChatOwnerChanged
668+
ChatHasProtectedContentToggled
669+
ChatHasProtectedContentDisableRequested
666670
""",
667671
chat_topics="""
668672
Chat Forum Topics

docs/source/releases/changes-in-this-fork.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ Changes in this Fork
3535
| Scheme layer used: 223 |
3636
+------------------------+
3737

38-
38+
- Added the fields ``chat_owner_left``, ``chat_owner_changed``, ``chat_has_protected_content_toggled`` and ``chat_has_protected_content_disable_requested`` to the class :obj:`~pyrogram.types.Message`.
3939
- Added the field ``can_edit_tag`` to the class :obj:`~pyrogram.types.ChatPermissions`.
4040
- Added the field ``tag`` to the class :obj:`~pyrogram.types.ChatMember`.
4141
- Added the field ``can_manage_tags`` to the class :obj:`~pyrogram.types.ChatPrivileges`.
42-
- Added the methods :meth:`~pyrogram.Client.set_chat_member_tag` and :meth:`~pyrogram.Client.process_chat_protected_content_disable_request`. Updated the method :meth:`~pyyrogram.Client.set_chat_protected_content` to return the appropriate service message, if available.
42+
- Added the methods :meth:`~pyrogram.Client.set_chat_member_tag` and :meth:`~pyrogram.Client.process_chat_protected_content_disable_request`. Updated the method :meth:`~pyrogram.Client.set_chat_protected_content` to return the appropriate service message, if available.
4343
- Added the field ``sender_tag`` to the class :obj:`~pyrogram.types.Message`.
4444
- Add ``location`` in :obj:`~pyrogram.types.Chat` and add missing parameters in :meth:`~pyrogram.Client.create_supergroup`.
4545
- fix: :meth:`~pyrogram.Client.get_media_group` concurrent logic (contributed by @Alekzum).

pyrogram/enums/message_service_type.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,17 @@ class MessageServiceType(AutoName):
156156
CHECKLIST_TASKS_ADDED = auto()
157157
"Checklist tasks added"
158158

159+
CHAT_OWNER_LEFT = auto()
160+
"Chat owner left"
161+
162+
CHAT_OWNER_CHANGED = auto()
163+
"Chat owner changed"
164+
165+
CHAT_HAS_PROTECTED_CONTENT_TOGGLED = auto()
166+
"Chat has_protected_content setting was changed or request to change it was rejected"
167+
168+
CHAT_HAS_PROTECTED_CONTENT_DISABLE_REQUESTED = auto()
169+
"Chat has_protected_content setting was requested to be disabled"
170+
159171
UNKNOWN = auto()
160172
"This service message is unsupported by the current version of Pyrogram"

pyrogram/methods/chats/set_chat_protected_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async def process_chat_protected_content_disable_request(
8585
Unique identifier (int) or username (str) of the target chat.
8686
8787
request_message_id (``int``):
88-
Identifier of the message with the request. The message must be incoming and has content of the type TODO.
88+
Identifier of the message with the request. The message must be incoming and has ``message.service`` of the type :obj:`~pyrogram.types.ChatHasProtectedContentToggled`.
8989
9090
enabled (``bool``):
9191
Pass True to approve the request; pass False to reject the request.

pyrogram/types/messages_and_media/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
from .checklist_tasks_added import ChecklistTasksAdded
7777
from .checklist_tasks_done import ChecklistTasksDone
7878
from .direct_message_price_changed import DirectMessagePriceChanged
79+
from .chat_owner_left import ChatOwnerLeft
80+
from .chat_owner_changed import ChatOwnerChanged
81+
from .chat_has_protected_content_toggled import ChatHasProtectedContentToggled
82+
from .chat_has_protected_content_disable_requested import ChatHasProtectedContentDisableRequested
7983

8084
__all__ = [
8185
"Animation",
@@ -137,4 +141,8 @@
137141
"ChecklistTasksDone",
138142
"DirectMessagePriceChanged",
139143
"DirectMessagesTopic",
144+
"ChatOwnerLeft",
145+
"ChatOwnerChanged",
146+
"ChatHasProtectedContentToggled",
147+
"ChatHasProtectedContentDisableRequested",
140148
]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
import pyrogram
20+
from pyrogram import raw, types
21+
22+
from ..object import Object
23+
24+
25+
class ChatHasProtectedContentDisableRequested(Object):
26+
"""Describes a service message about a chat ``has_protected_content`` setting was requested to be disabled.
27+
28+
Parameters:
29+
is_expired (``bool``):
30+
True, if the request has expired.
31+
32+
old_has_protected_content (``bool``):
33+
Previous value of the setting.
34+
35+
new_has_protected_content (``bool``):
36+
New value of the setting.
37+
38+
"""
39+
40+
def __init__(
41+
self, *,
42+
is_expired: bool = None,
43+
old_has_protected_content: bool = None,
44+
new_has_protected_content: bool = None,
45+
):
46+
super().__init__()
47+
48+
self.is_expired = is_expired
49+
self.old_has_protected_content = old_has_protected_content
50+
self.new_has_protected_content = new_has_protected_content
51+
52+
@staticmethod
53+
def _parse(
54+
client: "pyrogram.Client",
55+
action: "raw.types.MessageActionNoForwardsRequest",
56+
) -> "ChatHasProtectedContentDisableRequested":
57+
if isinstance(action, raw.types.MessageActionNoForwardsRequest):
58+
return ChatHasProtectedContentDisableRequested(
59+
is_expired=action.expired,
60+
old_has_protected_content=action.prev_value,
61+
new_has_protected_content=action.new_value,
62+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
import pyrogram
20+
from pyrogram import raw, types
21+
22+
from ..object import Object
23+
24+
25+
class ChatHasProtectedContentToggled(Object):
26+
"""Describes a service message about a chat ``has_protected_content`` setting was changed or request to change it was rejected.
27+
28+
Parameters:
29+
request_message_id (``int``):
30+
Identifier of the message with the request to change the setting; can be an identifier of a deleted message or 0.
31+
32+
old_has_protected_content (``bool``):
33+
Previous value of the setting.
34+
35+
new_has_protected_content (``bool``):
36+
New value of the setting.
37+
38+
"""
39+
40+
def __init__(
41+
self, *,
42+
request_message_id: int = None,
43+
old_has_protected_content: bool = None,
44+
new_has_protected_content: bool = None,
45+
):
46+
super().__init__()
47+
48+
self.request_message_id = request_message_id
49+
self.old_has_protected_content = old_has_protected_content
50+
self.new_has_protected_content = new_has_protected_content
51+
52+
@staticmethod
53+
def _parse(
54+
client: "pyrogram.Client",
55+
message: "raw.types.MessageService",
56+
) -> "ChatHasProtectedContentToggled":
57+
action: "raw.types.MessageActionNoForwardsToggle" = message.action
58+
if isinstance(action, raw.types.MessageActionNoForwardsToggle):
59+
return ChatHasProtectedContentToggled(
60+
request_message_id=message.id,
61+
old_has_protected_content=action.prev_value,
62+
new_has_protected_content=action.new_value,
63+
)
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+
import pyrogram
20+
from pyrogram import raw, types
21+
22+
from ..object import Object
23+
24+
25+
class ChatOwnerChanged(Object):
26+
"""Describes a service message about an ownership change in the chat.
27+
28+
Parameters:
29+
new_owner (:obj:`~pyrogram.types.User`):
30+
The new owner of the chat.
31+
32+
"""
33+
34+
def __init__(self, *, new_owner: "types.User"):
35+
super().__init__()
36+
37+
self.new_owner = new_owner
38+
39+
@staticmethod
40+
def _parse(
41+
client: "pyrogram.Client",
42+
action: "raw.types.MessageActionChangeCreator",
43+
users: dict[int, "types.User"],
44+
) -> "ChatOwnerChanged":
45+
if isinstance(action, raw.types.MessageActionChangeCreator):
46+
return ChatOwnerChanged(
47+
new_owner=types.User._parse(client, users.get(action.new_creator_id))
48+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 Optional
20+
21+
import pyrogram
22+
from pyrogram import raw, types
23+
24+
from ..object import Object
25+
26+
27+
class ChatOwnerLeft(Object):
28+
"""Describes a service message about the chat owner leaving the chat.
29+
30+
Parameters:
31+
new_owner (:obj:`~pyrogram.types.User`, *optional*):
32+
The user which will be the new owner of the chat if the previous owner does not return to the chat.
33+
34+
"""
35+
36+
def __init__(self, *, new_owner: Optional["types.User"] = None):
37+
super().__init__()
38+
39+
self.new_owner = new_owner
40+
41+
@staticmethod
42+
def _parse(
43+
client: "pyrogram.Client",
44+
action: "raw.types.MessageActionNewCreatorPending",
45+
users: dict[int, "types.User"],
46+
) -> "ChatOwnerLeft":
47+
if isinstance(action, raw.types.MessageActionNewCreatorPending):
48+
return ChatOwnerLeft(
49+
new_owner=types.User._parse(client, users.get(action.new_creator_id))
50+
)

pyrogram/types/messages_and_media/message.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,18 @@ class Message(Object, Update):
239239
left_chat_member (:obj:`~pyrogram.types.User`, *optional*):
240240
A member was removed from the group, information about them (this member may be the bot itself).
241241
242+
chat_owner_left (:obj:`~pyrogram.types.ChatOwnerLeft`, *optional*):
243+
Service message: chat owner has left.
244+
245+
chat_owner_changed (:obj:`~pyrogram.types.ChatOwnerChanged`, *optional*):
246+
Service message: chat owner has changed.
247+
248+
chat_has_protected_content_toggled (:obj:`~pyrogram.types.ChatHasProtectedContentToggled`, *optional*):
249+
Service message: Chat has_protected_content setting was changed or request to change it was rejected.
250+
251+
chat_has_protected_content_disable_requested (:obj:`~pyrogram.types.ChatHasProtectedContentDisableRequested`, *optional*):
252+
Service message: Chat has_protected_content setting was requested to be disabled.
253+
242254
old_chat_title (``str``, *optional*):
243255
The supergroup has been migrated from a group with the specified title.
244256
@@ -516,6 +528,10 @@ def __init__(
516528
location: "types.Location" = None,
517529
new_chat_members: list["types.User"] = None,
518530
left_chat_member: "types.User" = None,
531+
chat_owner_left: Optional["types.ChatOwnerLeft"] = None,
532+
chat_owner_changed: Optional["types.ChatOwnerChanged"] = None,
533+
chat_has_protected_content_toggled: Optional["types.ChatHasProtectedContentToggled"] = None,
534+
chat_has_protected_content_disable_requested: Optional["types.ChatHasProtectedContentDisableRequested"] = None,
519535
old_chat_title: str = None,
520536
new_chat_title: str = None,
521537
new_chat_photo: "types.Photo" = None,
@@ -633,6 +649,10 @@ def __init__(
633649
self.dice = dice
634650
self.new_chat_members = new_chat_members
635651
self.left_chat_member = left_chat_member
652+
self.chat_owner_left = chat_owner_left
653+
self.chat_owner_changed = chat_owner_changed
654+
self.chat_has_protected_content_toggled = chat_has_protected_content_toggled
655+
self.chat_has_protected_content_disable_requested = chat_has_protected_content_disable_requested
636656
self.old_chat_title = old_chat_title
637657
self.new_chat_title = new_chat_title
638658
self.new_chat_photo = new_chat_photo
@@ -769,6 +789,10 @@ async def _parse(
769789

770790
new_chat_members = None
771791
left_chat_member = None
792+
chat_owner_left = None
793+
chat_owner_changed = None
794+
chat_has_protected_content_toggled = None
795+
chat_has_protected_content_disable_requested = None
772796
old_chat_title = None
773797
new_chat_title = None
774798
delete_chat_photo = None
@@ -833,6 +857,18 @@ async def _parse(
833857
elif isinstance(action, raw.types.MessageActionChatDeleteUser):
834858
left_chat_member = types.User._parse(client, users[action.user_id])
835859
service_type = enums.MessageServiceType.LEFT_CHAT_MEMBERS
860+
elif isinstance(action, raw.types.MessageActionNewCreatorPending):
861+
service_type = enums.MessageServiceType.CHAT_OWNER_LEFT
862+
chat_owner_left = types.ChatOwnerLeft._parse(client, action, users)
863+
elif isinstance(action, raw.types.MessageActionChangeCreator):
864+
service_type = enums.MessageServiceType.CHAT_OWNER_CHANGED
865+
chat_owner_changed = types.ChatOwnerChanged._parse(client, action, users)
866+
elif isinstance(action, raw.types.MessageActionNoForwardsToggle):
867+
service_type = enums.MessageServiceType.CHAT_HAS_PROTECTED_CONTENT_TOGGLED
868+
chat_has_protected_content_toggled = types.ChatHasProtectedContentToggled._parse(client, message)
869+
elif isinstance(action, raw.types.MessageActionNoForwardsRequest):
870+
service_type = enums.MessageServiceType.CHAT_HAS_PROTECTED_CONTENT_DISABLE_REQUESTED
871+
chat_has_protected_content_disable_requested = types.ChatHasProtectedContentDisableRequested._parse(client, action)
836872
elif isinstance(action, raw.types.MessageActionChatEditTitle):
837873
new_chat_title = action.title
838874
service_type = enums.MessageServiceType.NEW_CHAT_TITLE
@@ -1108,6 +1144,10 @@ async def _parse(
11081144
service=service_type,
11091145
new_chat_members=new_chat_members,
11101146
left_chat_member=left_chat_member,
1147+
chat_owner_left=chat_owner_left,
1148+
chat_owner_changed=chat_owner_changed,
1149+
chat_has_protected_content_toggled=chat_has_protected_content_toggled,
1150+
chat_has_protected_content_disable_requested=chat_has_protected_content_disable_requested,
11111151
old_chat_title=old_chat_title,
11121152
new_chat_title=new_chat_title,
11131153
new_chat_photo=new_chat_photo,

0 commit comments

Comments
 (0)