Skip to content

Commit ed3b76f

Browse files
committed
Merge remote-tracking branch 'KurimuzonAkuma/dev' into dev
2 parents d434c49 + fd29eef commit ed3b76f

20 files changed

Lines changed: 613 additions & 134 deletions

compiler/docs/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ def get_title_list(s: str) -> list:
327327
pin_chat_message
328328
unpin_chat_message
329329
pin_forum_topic
330+
process_chat_has_protected_content_disable_request
330331
unpin_forum_topic
331332
unpin_all_chat_messages
332333
get_chat
@@ -384,6 +385,7 @@ def get_title_list(s: str) -> list:
384385
transfer_chat_ownership
385386
get_suitable_discussion_chats
386387
set_chat_discussion_group
388+
set_chat_member_tag
387389
set_main_profile_tab
388390
""",
389391
users="""
@@ -798,6 +800,8 @@ def get_title_list(s: str) -> list:
798800
ChatBoost
799801
ChatOwnerChanged
800802
ChatOwnerLeft
803+
ChatHasProtectedContentToggled
804+
ChatHasProtectedContentDisableRequested
801805
ContactRegistered
802806
ScreenshotTaken
803807
StarAmount

compiler/errors/source/400_BAD_REQUEST.tsv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ RANDOM_ID_EMPTY The random ID is empty.
424424
RANDOM_ID_INVALID The provided random ID is invalid.
425425
RANDOM_LENGTH_INVALID The random length is invalid.
426426
RANGES_INVALID Invalid range provided.
427+
RANK_INVALID The specified member tag is invalid.
427428
REACTIONS_COUNT_INVALID The count of the reactions should be less than `stars_paid_reaction_amount_max` stars, you can't react with more number of stars, see [the docs for more info](https://core.telegram.org/api/config#client-configuration).
428429
REACTIONS_TOO_MANY Non-premium users, can set up only one reaction per message.
429430
REACTION_EMPTY The specified reaction is empty.
@@ -644,4 +645,4 @@ WEBPAGE_URL_INVALID The specified webpage `url` is invalid.
644645
WEBPUSH_AUTH_INVALID The specified web push authentication secret is invalid.
645646
WEBPUSH_KEY_INVALID The specified web push elliptic curve Diffie-Hellman public key is invalid.
646647
WEBPUSH_TOKEN_INVALID The specified web push token is invalid.
647-
YOU_BLOCKED_USER You blocked this user.
648+
YOU_BLOCKED_USER You blocked this user.

pyrogram/enums/message_entity_type.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@ class MessageEntityType(AutoName):
8080
CUSTOM_EMOJI = raw.types.MessageEntityCustomEmoji
8181
"Custom emoji"
8282

83+
DATE_TIME = raw.types.MessageEntityFormattedDate
84+
"Date time"
85+
8386
UNKNOWN = raw.types.MessageEntityUnknown
8487
"Unknown message entity type"

pyrogram/enums/message_service_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,9 @@ class MessageServiceType(AutoName):
218218

219219
UPGRADED_GIFT_PURCHASE_OFFER_REJECTED = auto()
220220
"Upgraded gift purchase offer declined"
221+
222+
CHAT_HAS_PROTECTED_CONTENT_TOGGLED = auto()
223+
"Chat has protected content toggled"
224+
225+
CHAT_HAS_PROTECTED_CONTENT_DISABLE_REQUESTED = auto()
226+
"Chat has protected content disable requested"

pyrogram/methods/chats/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@
6161
from .mark_chat_unread import MarkChatUnread
6262
from .pin_chat_message import PinChatMessage
6363
from .pin_forum_topic import PinForumTopic
64+
from .process_chat_has_protected_content_disable_request import ProcessChatHasProtectedContentDisableRequest
6465
from .promote_chat_member import PromoteChatMember
6566
from .restrict_chat_member import RestrictChatMember
6667
from .set_administrator_title import SetAdministratorTitle
6768
from .set_chat_description import SetChatDescription
6869
from .set_chat_direct_messages_group import SetChatDirectMessagesGroup
6970
from .set_chat_permissions import SetChatPermissions
7071
from .set_chat_discussion_group import SetChatDiscussionGroup
72+
from .set_chat_member_tag import SetChatMemberTag
7173
from .set_main_profile_tab import SetMainProfileTab
7274
from .set_chat_photo import SetChatPhoto
7375
from .set_chat_protected_content import SetChatProtectedContent
@@ -115,6 +117,7 @@ class Chats(
115117
PinChatMessage,
116118
UnpinChatMessage,
117119
PinForumTopic,
120+
ProcessChatHasProtectedContentDisableRequest,
118121
UnpinForumTopic,
119122
UpdateChatNotifications,
120123
UpdateColor,
@@ -126,6 +129,7 @@ class Chats(
126129
SetChatUsername,
127130
SetChatPermissions,
128131
SetChatDiscussionGroup,
132+
SetChatMemberTag,
129133
SetMainProfileTab,
130134
GetDialogsCount,
131135
GetFolders,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 Union
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils
23+
24+
25+
class ProcessChatHasProtectedContentDisableRequest:
26+
async def process_chat_has_protected_content_disable_request(
27+
self: "pyrogram.Client", chat_id: Union[int, str], request_message_id: int, approve: bool
28+
) -> Union["types.Message", bool]:
29+
"""Processes request to disable has_protected_content in a chat.
30+
31+
.. include:: /_includes/usable-by/users.rst
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
37+
request_message_id (``int``):
38+
Identifier of the message with the request.
39+
The message must be incoming and contain ``chat_protected_content_disable_requested`` param set.
40+
41+
approve (``bool``):
42+
Pass True to approve the request, False to reject the request.
43+
44+
Returns:
45+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
46+
otherwise, in case a message object couldn't be returned, True is returned.
47+
"""
48+
49+
r = await self.invoke(
50+
raw.functions.messages.ToggleNoForwards(
51+
peer=await self.resolve_peer(chat_id),
52+
enabled=approve,
53+
request_msg_id=request_message_id,
54+
)
55+
)
56+
57+
return next(iter(await utils.parse_messages(client=self, messages=r)), True)

pyrogram/methods/chats/promote_chat_member.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async def promote_chat_member(
9696
add_admins=privileges.can_promote_members,
9797
manage_call=privileges.can_manage_video_chats,
9898
manage_topics=privileges.can_manage_topics,
99+
manage_ranks=privileges.can_manage_tags,
99100
other=privileges.can_manage_chat
100101
),
101102
rank=rank or ""
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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, Union
20+
21+
import pyrogram
22+
from pyrogram import raw
23+
24+
25+
class SetChatMemberTag:
26+
async def set_chat_member_tag(
27+
self: "pyrogram.Client",
28+
chat_id: Union[int, str],
29+
user_id: Union[int, str],
30+
tag: Optional[str] = None,
31+
) -> bool:
32+
"""Use this method to set a tag for a regular member in a group or a supergroup.
33+
34+
.. note::
35+
36+
The bot must be an administrator in the chat for this to work and must have the ``can_manage_tags`` administrator right.
37+
38+
.. include:: /_includes/usable-by/users-bots.rst
39+
40+
Parameters:
41+
chat_id (``int`` | ``str``):
42+
Unique identifier (int) or username (str) of the target chat.
43+
44+
user_id (``int`` | ``str``):
45+
Unique identifier (int) or username (str) of the target user.
46+
For a contact that exists in your Telegram address book you can use his phone number (str).
47+
48+
tag (``str``, *optional*):
49+
New tag for the member, 0-16 characters, emoji are not allowed.
50+
51+
Returns:
52+
``bool``: True on success.
53+
54+
Example:
55+
.. code-block:: python
56+
57+
await app.set_chat_member_tag(chat_id, user_id, "Cool guy")
58+
"""
59+
chat_id = await self.resolve_peer(chat_id)
60+
user_id = await self.resolve_peer(user_id)
61+
62+
await self.invoke(
63+
raw.functions.messages.EditChatParticipantRank(
64+
peer=chat_id, participant=user_id, rank=tag or ""
65+
)
66+
)
67+
68+
return True

pyrogram/methods/chats/set_chat_protected_content.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
from typing import Union
2020

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

2424

2525
class SetChatProtectedContent:
2626
async def set_chat_protected_content(
27-
self: "pyrogram.Client",
28-
chat_id: Union[int, str],
29-
enabled: bool
30-
) -> bool:
27+
self: "pyrogram.Client", chat_id: Union[int, str], enabled: bool
28+
) -> Union["types.Message", bool]:
3129
"""Set the chat protected content setting.
3230
3331
.. include:: /_includes/usable-by/users-bots.rst
@@ -40,14 +38,14 @@ async def set_chat_protected_content(
4038
Pass True to enable the protected content setting, False to disable.
4139
4240
Returns:
43-
``bool``: On success, True is returned.
41+
:obj:`~pyrogram.types.Message` | ``bool``: On success, a service message will be returned (when applicable),
42+
otherwise, in case a message object couldn't be returned, True is returned.
4443
"""
4544

46-
await self.invoke(
45+
r = await self.invoke(
4746
raw.functions.messages.ToggleNoForwards(
48-
peer=await self.resolve_peer(chat_id),
49-
enabled=enabled
47+
peer=await self.resolve_peer(chat_id), enabled=enabled
5048
)
5149
)
5250

53-
return True
51+
return next(iter(await utils.parse_messages(client=self, messages=r)), True)

pyrogram/methods/messages/send_message_draft.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ async def send_message_draft(
3939
Parameters:
4040
chat_id (``int`` | ``str``):
4141
Unique identifier (int) or username (str) of the target chat.
42-
For your personal cloud (Saved Messages) you can simply use "me" or "self".
43-
For a contact that exists in your Telegram address book you can use his phone number (str).
4442
4543
draft_id (``int``):
4644
Unique identifier of the message draft, must be non-zero.
@@ -61,6 +59,25 @@ async def send_message_draft(
6159
6260
Returns:
6361
``bool``: On success, True is returned.
62+
63+
Example:
64+
.. code-block:: python
65+
66+
text = "Hello! I'm your Pyrogram bot! How can I help you?"
67+
words = text.split()
68+
draft_id = app.rnd_id()
69+
70+
for i, word in enumerate(words):
71+
await app.send_message_draft(
72+
chat_id=chat_id,
73+
draft_id=draft_id,
74+
text=" ".join(words[:i+1]),
75+
)
76+
77+
await asyncio.sleep(0.33)
78+
79+
await app.send_message(chat_id, text)
80+
6481
"""
6582
return await self.invoke(
6683
raw.functions.messages.SetTyping(

0 commit comments

Comments
 (0)