Skip to content

Commit 91e0a08

Browse files
committed
Merge branch 'chat-permissions-others'
2 parents 0ca8ab2 + c9d0c5d commit 91e0a08

File tree

2 files changed

+30
-53
lines changed

2 files changed

+30
-53
lines changed

pyrogram/methods/chats/set_chat_permissions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,27 @@ async def set_chat_permissions(
5252
# Completely restrict chat
5353
app.set_chat_permissions(chat_id, ChatPermissions())
5454
55-
# Chat members can only send text messages, media, stickers and GIFs
55+
# Chat members can only send text messages and media messages
5656
app.set_chat_permissions(
5757
chat_id,
5858
ChatPermissions(
5959
can_send_messages=True,
60-
can_send_media_messages=True,
61-
can_send_stickers=True,
62-
can_send_animations=True
60+
can_send_media_messages=True
6361
)
6462
)
6563
"""
64+
6665
r = await self.send(
6766
raw.functions.messages.EditChatDefaultBannedRights(
6867
peer=await self.resolve_peer(chat_id),
6968
banned_rights=raw.types.ChatBannedRights(
7069
until_date=0,
7170
send_messages=True if not permissions.can_send_messages else None,
7271
send_media=True if not permissions.can_send_media_messages else None,
73-
send_stickers=True if not permissions.can_send_stickers else None,
74-
send_gifs=True if not permissions.can_send_animations else None,
75-
send_games=True if not permissions.can_send_games else None,
76-
send_inline=True if not permissions.can_use_inline_bots else None,
72+
send_stickers=permissions.can_send_other_messages,
73+
send_gifs=permissions.can_send_other_messages,
74+
send_games=permissions.can_send_other_messages,
75+
send_inline=permissions.can_send_other_messages,
7776
embed_links=True if not permissions.can_add_web_page_previews else None,
7877
send_polls=True if not permissions.can_send_polls else None,
7978
change_info=True if not permissions.can_change_info else None,

pyrogram/types/user_and_chats/chat_permissions.py

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,31 @@
2121

2222

2323
class ChatPermissions(Object):
24-
"""A chat default permissions and a single member permissions within a chat.
25-
26-
Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or
27-
administrators in groups or channels.
28-
29-
.. note::
30-
31-
Pyrogram's chat permission are much more detailed. In particular, you can restrict sending stickers, animations,
32-
games and inline bot results individually, allowing a finer control.
33-
34-
If you wish to have the same permissions as seen in official apps or in bot API's *"can_send_other_messages"*
35-
simply set these arguments to True: ``can_send_stickers``, ``can_send_animations``, ``can_send_games`` and
36-
``can_use_inline_bots``.
24+
"""Describes actions that a non-administrator user is allowed to take in a chat.
3725
3826
Parameters:
3927
can_send_messages (``bool``, *optional*):
4028
True, if the user is allowed to send text messages, contacts, locations and venues.
4129
4230
can_send_media_messages (``bool``, *optional*):
43-
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies
44-
can_send_messages.
31+
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
32+
Implies *can_send_messages*.
4533
46-
can_send_stickers (``bool``, *optional*):
47-
True, if the user is allowed to send stickers, implies can_send_media_messages.
34+
can_send_other_messages (``bool``, *optional*):
35+
True, if the user is allowed to send animations, games, stickers and use inline bots.
36+
Implies *can_send_media_messages*.
4837
49-
can_send_animations (``bool``, *optional*):
50-
True, if the user is allowed to send animations (GIFs), implies can_send_media_messages.
51-
52-
can_send_games (``bool``, *optional*):
53-
True, if the user is allowed to send games, implies can_send_media_messages.
54-
55-
can_use_inline_bots (``bool``, *optional*):
56-
True, if the user is allowed to use inline bots, implies can_send_media_messages.
38+
can_send_polls (``bool``, *optional*):
39+
True, if the user is allowed to send polls.
40+
Implies can_send_messages
5741
5842
can_add_web_page_previews (``bool``, *optional*):
59-
True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
60-
61-
can_send_polls (``bool``, *optional*):
62-
True, if the user is allowed to send polls, implies can_send_messages.
43+
True, if the user is allowed to add web page previews to their messages.
44+
Implies *can_send_media_messages*.
6345
6446
can_change_info (``bool``, *optional*):
6547
True, if the user is allowed to change the chat title, photo and other settings.
66-
Ignored in public supergroups.
48+
Ignored in public supergroups
6749
6850
can_invite_users (``bool``, *optional*):
6951
True, if the user is allowed to invite new users to the chat.
@@ -77,13 +59,10 @@ def __init__(
7759
self,
7860
*,
7961
can_send_messages: bool = None, # Text, contacts, locations and venues
80-
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
81-
can_send_stickers: bool = None,
82-
can_send_animations: bool = None,
83-
can_send_games: bool = None,
84-
can_use_inline_bots: bool = None,
85-
can_add_web_page_previews: bool = None,
62+
can_send_media_messages: bool = None, # Audio files, documents, photos, videos, video notes and voice notes
63+
can_send_other_messages: bool = None, # Stickers, animations, games, inline bots
8664
can_send_polls: bool = None,
65+
can_add_web_page_previews: bool = None,
8766
can_change_info: bool = None,
8867
can_invite_users: bool = None,
8968
can_pin_messages: bool = None
@@ -92,12 +71,9 @@ def __init__(
9271

9372
self.can_send_messages = can_send_messages
9473
self.can_send_media_messages = can_send_media_messages
95-
self.can_send_stickers = can_send_stickers
96-
self.can_send_animations = can_send_animations
97-
self.can_send_games = can_send_games
98-
self.can_use_inline_bots = can_use_inline_bots
99-
self.can_add_web_page_previews = can_add_web_page_previews
74+
self.can_send_other_messages = can_send_other_messages
10075
self.can_send_polls = can_send_polls
76+
self.can_add_web_page_previews = can_add_web_page_previews
10177
self.can_change_info = can_change_info
10278
self.can_invite_users = can_invite_users
10379
self.can_pin_messages = can_pin_messages
@@ -108,10 +84,12 @@ def _parse(denied_permissions: "raw.types.ChatBannedRights") -> "ChatPermissions
10884
return ChatPermissions(
10985
can_send_messages=not denied_permissions.send_messages,
11086
can_send_media_messages=not denied_permissions.send_media,
111-
can_send_stickers=not denied_permissions.send_stickers,
112-
can_send_animations=not denied_permissions.send_gifs,
113-
can_send_games=not denied_permissions.send_games,
114-
can_use_inline_bots=not denied_permissions.send_inline,
87+
can_send_other_messages=any([
88+
not denied_permissions.send_stickers,
89+
not denied_permissions.send_gifs,
90+
not denied_permissions.send_games,
91+
not denied_permissions.send_inline
92+
]),
11593
can_add_web_page_previews=not denied_permissions.embed_links,
11694
can_send_polls=not denied_permissions.send_polls,
11795
can_change_info=not denied_permissions.change_info,

0 commit comments

Comments
 (0)