Skip to content

Commit a91ab10

Browse files
committed
Update methods and types to Layer 223,
except Web Login and Text Entity
1 parent 207f7f5 commit a91ab10

File tree

12 files changed

+214
-13
lines changed

12 files changed

+214
-13
lines changed

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def get_title_list(s: str) -> list:
317317
restrict_chat_member
318318
promote_chat_member
319319
set_administrator_title
320+
set_chat_member_tag
320321
set_chat_permissions
321322
set_chat_photo
322323
delete_chat_photo
@@ -356,6 +357,7 @@ def get_title_list(s: str) -> list:
356357
get_send_as_chats
357358
set_send_as_chat
358359
set_chat_protected_content
360+
process_chat_protected_content_disable_request
359361
get_created_chats
360362
transfer_chat_ownership
361363
""",

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@ Changes in this Fork
3232
=====================
3333

3434
+------------------------+
35-
| Scheme layer used: 222 |
35+
| Scheme layer used: 223 |
3636
+------------------------+
3737

38+
39+
- Added the field ``can_edit_tag`` to the class :obj:`~pyrogram.types.ChatPermissions`.
40+
- Added the field ``tag`` to the class :obj:`~pyrogram.types.ChatMember`.
41+
- 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.
43+
- Added the field ``sender_tag`` to the class :obj:`~pyrogram.types.Message`.
3844
- Add ``location`` in :obj:`~pyrogram.types.Chat` and add missing parameters in :meth:`~pyrogram.Client.create_supergroup`.
3945
- fix: :meth:`~pyrogram.Client.get_media_group` concurrent logic (contributed by @Alekzum).
4046
- properly implement in_memory arg in client to support session string. (contributed by @anonymousx97 in `#222 <https://github.com/KurimuzonAkuma/kurigram/pull/222>`__).
47+
- View `new and changed <https://telegramplayground.github.io/TG-APIs/TL/diff/tdlib.html?from=222&to=223>`__ `raw API methods <https://telegramplayground.github.io/TG-APIs/TL/diff/tdesktop.html?from=222&to=223>`__.
48+
49+
+------------------------+
50+
| Scheme layer used: 222 |
51+
+------------------------+
4152

4253
- Added the field ``first_profile_audio`` to the class :obj:`~pyrogram.types.Chat` and the methods :meth:`~pyrogram.Client.get_chat_audios`, :meth:`~pyrogram.Client.get_chat_audios_count`, :meth:`~pyrogram.Client.add_profile_audio`, :meth:`~pyrogram.Client.remove_profile_audio`, :meth:`~pyrogram.Client.set_profile_audio_position`.
4354
- Removed the methods :meth:`~pyrogram.Client.get_received_gifts`, :meth:`~pyrogram.Client.sell_gift`, :meth:`~pyrogram.Client.send_gift`, :meth:`~pyrogram.Client.toggle_gift_is_saved` and the :obj:`~pyrogram.types.ReceivedGift`.

pyrogram/enums/chat_event_action.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,10 @@ class ChatEventAction(AutoName):
162162
``old_topic_info`` Information about the old pinned topic; may be null
163163
``new_topic_info`` Information about the new pinned topic; may be null"""
164164

165+
CHAT_MEMBER_TAG_CHANGED = auto()
166+
"""A chat member tag has been changed.
167+
```old_member_tag``` - Information about the old chat member tag
168+
```new_member_tag``` - Information about the new chat member tag"""
169+
165170
UNKNOWN = auto()
166171
"Unknown chat event action"

pyrogram/methods/chats/create_supergroup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def create_supergroup(
5555
Pass True to create a supergroup for `importing messages <https://core.telegram.org/api/import>`__.
5656
5757
location (:obj:`~pyrogram.types.ChatLocation`, *optional*):
58-
Chat location if a location-basAlekzumed supergroup is being created; pass None to create an ordinary supergroup chat.
58+
Chat location if a location-based supergroup is being created; pass None to create an ordinary supergroup chat.
5959
6060
Returns:
6161
:obj:`~pyrogram.types.Chat`: On success, a chat object is returned.

pyrogram/methods/chats/set_administrator_title.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async def set_administrator_title(
5555
.. code-block:: python
5656
5757
await app.set_administrator_title(chat_id, user_id, "Admin Title")
58+
5859
"""
5960
chat_id = await self.resolve_peer(chat_id)
6061
user_id = await self.resolve_peer(user_id)
@@ -83,3 +84,51 @@ async def set_administrator_title(
8384
)
8485

8586
return True
87+
88+
89+
async def set_chat_member_tag(
90+
self: "pyrogram.Client",
91+
chat_id: Union[int, str],
92+
user_id: Union[int, str],
93+
tag: str,
94+
) -> bool:
95+
"""Set a tag or custom title for a regular member in a group or a supergroup.
96+
97+
.. include:: /_includes/usable-by/users-bots.rst
98+
99+
The client must be an administrator in the chat (for basic groups and supergroups only) for this to work and must have the ``can_manage_tags`` administrator right.
100+
101+
Parameters:
102+
chat_id (``int`` | ``str``):
103+
Unique identifier (int) or username (str) of the target chat.
104+
105+
user_id (``int`` | ``str``):
106+
Unique identifier (int) or username (str) of the target user.
107+
For a contact that exists in your Telegram address book you can use his phone number (str).
108+
109+
tag (``str``, *optional*):
110+
The new tag of the member in the chat.
111+
0-16 characters without emoji.
112+
Pass None or "" (empty string) to remove the custom title.
113+
114+
Returns:
115+
``bool``: True on success.
116+
117+
Example:
118+
.. code-block:: python
119+
120+
await app.set_chat_member_tag(chat_id, user_id, "Member Tag")
121+
122+
"""
123+
chat_id = await self.resolve_peer(chat_id)
124+
user_id = await self.resolve_peer(user_id)
125+
126+
await self.invoke(
127+
raw.functions.messages.EditChatParticipantRank(
128+
peer=chat_id,
129+
participant=user_id,
130+
rank=title
131+
)
132+
)
133+
134+
return True

pyrogram/methods/chats/set_chat_protected_content.py

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@
1919
from typing import Union
2020

2121
import pyrogram
22-
from pyrogram import raw
22+
from pyrogram import raw, types
2323

2424

2525
class SetChatProtectedContent:
2626
async def set_chat_protected_content(
2727
self: "pyrogram.Client",
2828
chat_id: Union[int, str],
2929
enabled: bool
30-
) -> bool:
30+
) -> Union["types.Message", bool]:
3131
"""Set the chat protected content setting.
3232
3333
.. include:: /_includes/usable-by/users.rst
3434
35+
Changes the ability of users to save, forward, or copy chat content.
36+
37+
Requires owner privileges in basic groups, supergroups and channels.
38+
Requires Telegram Premium to enable protected content in private chats. Not available in Saved Messages and private chats with bots or support accounts.
39+
3540
Parameters:
3641
chat_id (``int`` | ``str``):
3742
Unique identifier (int) or username (str) of the target chat.
@@ -40,14 +45,73 @@ async def set_chat_protected_content(
4045
Pass True to enable the protected content setting, False to disable.
4146
4247
Returns:
43-
``bool``: On success, True is returned.
44-
"""
48+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
49+
otherwise, in case a message object couldn't be returned, True is returned.
4550
46-
await self.invoke(
51+
Raises:
52+
RPCError: In case of a Telegram RPCError.
53+
54+
"""
55+
r = await self.invoke(
4756
raw.functions.messages.ToggleNoForwards(
4857
peer=await self.resolve_peer(chat_id),
4958
enabled=enabled
5059
)
5160
)
61+
for i in r.updates:
62+
if isinstance(i, (raw.types.UpdateNewMessage, raw.types.UpdateNewChannelMessage)):
63+
return await types.Message._parse(
64+
self,
65+
i.message,
66+
{i.id: i for i in r.users},
67+
{i.id: i for i in r.chats},
68+
replies=self.fetch_replies
69+
)
70+
return True
71+
72+
73+
async def process_chat_protected_content_disable_request(
74+
self: "pyrogram.Client",
75+
chat_id: Union[int, str],
76+
request_message_id: int,
77+
enabled: bool
78+
) -> Union["types.Message", bool]:
79+
"""Processes request to disable ``has_protected_content`` in a chat.
80+
81+
.. include:: /_includes/usable-by/users.rst
82+
83+
Parameters:
84+
chat_id (``int`` | ``str``):
85+
Unique identifier (int) or username (str) of the target chat.
86+
87+
request_message_id (``int``):
88+
Identifier of the message with the request. The message must be incoming and has content of the type TODO.
5289
90+
enabled (``bool``):
91+
Pass True to approve the request; pass False to reject the request.
92+
93+
Returns:
94+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
95+
otherwise, in case a message object couldn't be returned, True is returned.
96+
97+
Raises:
98+
RPCError: In case of a Telegram RPCError.
99+
100+
"""
101+
r = await self.invoke(
102+
raw.functions.messages.ToggleNoForwards(
103+
peer=await self.resolve_peer(chat_id),
104+
enabled=enabled,
105+
request_msg_id=request_message_id
106+
)
107+
)
108+
for i in r.updates:
109+
if isinstance(i, (raw.types.UpdateNewMessage, raw.types.UpdateNewChannelMessage)):
110+
return await types.Message._parse(
111+
self,
112+
i.message,
113+
{i.id: i for i in r.users},
114+
{i.id: i for i in r.chats},
115+
replies=self.fetch_replies
116+
)
53117
return True

pyrogram/types/messages_and_media/message.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class Message(Object, Update):
8484
sender_business_bot (:obj:`~pyrogram.types.User`, *optional*):
8585
The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account.
8686
87+
sender_tag (``str``, *optional*):
88+
Tag of the sender of the message in the supergroup at the time the message was sent.
89+
May be empty if none or unknown.
90+
For messages sent by basic groups or supergroup administrators, the current custom title or tag must be used instead.
91+
8792
date (:py:obj:`~datetime.datetime`, *optional*):
8893
Date the message was sent.
8994
@@ -464,6 +469,7 @@ def __init__(
464469
sender_chat: "types.Chat" = None,
465470
sender_boost_count: int = None,
466471
sender_business_bot: "types.User" = None,
472+
sender_tag: str = None,
467473
date: datetime = None,
468474
business_connection_id: str = None,
469475
chat: "types.Chat" = None,
@@ -685,6 +691,7 @@ def __init__(
685691
self.general_forum_topic_unhidden = general_forum_topic_unhidden
686692
self.custom_action = custom_action
687693
self.sender_business_bot = sender_business_bot
694+
self.sender_tag = sender_tag
688695
self.business_connection_id = business_connection_id
689696
self.successful_payment = successful_payment
690697
self.paid_media = paid_media
@@ -1452,6 +1459,7 @@ async def _parse(
14521459
message.reply_to
14531460
)
14541461
parsed_message.sender_boost_count = getattr(message, "from_boosts_applied", None)
1462+
parsed_message.sender_tag = getattr(message, "from_rank", None)
14551463

14561464
if getattr(message, "via_business_bot_id", None):
14571465
parsed_message.sender_business_bot = types.User._parse(client, users.get(message.via_business_bot_id, None))

pyrogram/types/user_and_chats/chat_event.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class ChatEvent(Object):
169169
old_topic_info, new_topic_info (:obj:`~pyrogram.types.ForumTopic`, *optional*):
170170
Affected forum topic info of the chat.
171171
172+
old_member_tag, new_member_tag (``str``, *optional*):
173+
Affected tag of the chat member.
174+
172175
"""
173176

174177
def __init__(
@@ -247,6 +250,9 @@ def __init__(
247250

248251
old_topic_info: "types.ForumTopic" = None,
249252
new_topic_info: "types.ForumTopic" = None,
253+
254+
old_member_tag: str = None,
255+
new_member_tag: str = None,
250256
):
251257
super().__init__()
252258

@@ -325,6 +331,9 @@ def __init__(
325331
self.old_topic_info = old_topic_info
326332
self.new_topic_info = new_topic_info
327333

334+
self.old_member_tag = old_member_tag
335+
self.new_member_tag = new_member_tag
336+
328337

329338
@staticmethod
330339
async def _parse(
@@ -409,6 +418,9 @@ async def _parse(
409418
old_topic_info: Optional["types.ForumTopic"] = None
410419
new_topic_info: Optional["types.ForumTopic"] = None
411420

421+
old_member_tag: Optional[str] = None
422+
new_member_tag: Optional[str] = None
423+
412424
if isinstance(action, raw.types.ChannelAdminLogEventActionChangeAbout):
413425
old_description = action.prev_value
414426
new_description = action.new_value
@@ -625,6 +637,11 @@ async def _parse(
625637
)
626638
action = enums.ChatEventAction.CHAT_FORUM_TOPIC_PINNED
627639

640+
elif isinstance(action, raw.typs.ChannelAdminLogEventActionParticipantEditRank):
641+
old_member_tag = action.prev_rank
642+
new_member_tag = action.new_rank
643+
action = enums.ChatEventAction.CHAT_MEMBER_TAG_CHANGED
644+
628645
else:
629646
action = f"{enums.ChatEventAction.UNKNOWN}-{action.QUALNAME}"
630647

@@ -703,4 +720,7 @@ async def _parse(
703720

704721
old_topic_info=old_topic_info,
705722
new_topic_info=new_topic_info,
723+
724+
old_member_tag=old_member_tag,
725+
new_member_tag=new_member_tag,
706726
)

pyrogram/types/user_and_chats/chat_event_filter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class ChatEventFilter(Object):
7878
True, if subscription extensions need to be returned.
7979
Defaults to False.
8080
81+
member_tag_changes (``bool``, *optional*):
82+
True, if member tag and custom title change events need to be returned.
83+
8184
"""
8285

8386
def __init__(
@@ -95,6 +98,7 @@ def __init__(
9598
video_chats: bool = False,
9699
forum_changes: bool = False,
97100
subscription_extensions: bool = False,
101+
member_tag_changes: bool = False,
98102
):
99103
super().__init__()
100104

@@ -111,6 +115,7 @@ def __init__(
111115
self.video_chats = video_chats
112116
self.forum_changes = forum_changes
113117
self.subscription_extensions = subscription_extensions
118+
self.member_tag_changes = member_tag_changes
114119

115120
def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
116121
join = False
@@ -131,6 +136,7 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
131136
invites = False
132137
forum_changes = False
133138
subscription_extensions = False
139+
member_tag_changes = False
134140

135141
if self.new_restrictions:
136142
ban = True
@@ -175,6 +181,9 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
175181

176182
if self.subscription_extensions:
177183
subscription_extensions = True
184+
185+
if self.member_tag_changes:
186+
member_tag_changes = True
178187

179188
return raw.types.ChannelAdminLogEventsFilter(
180189
join=join,
@@ -193,7 +202,8 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
193202
delete=delete,
194203
group_call=group_call,
195204
invites=invites,
196-
# send
205+
send=False,
197206
forums=forum_changes,
198207
sub_extend=subscription_extensions,
208+
edit_rank=member_tag_changes,
199209
)

0 commit comments

Comments
 (0)