Skip to content

Commit b9c50b0

Browse files
committed
Add extended chat permissions
1 parent 75ad20b commit b9c50b0

2 files changed

Lines changed: 55 additions & 18 deletions

File tree

pyrogram/client/types/user_and_chats/chat_member.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,17 @@ class ChatMember(Object):
104104
Restricted only.
105105
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
106106
107-
can_send_other_messages (``bool``, *optional*):
108-
Restricted only.
109-
True, if the user is allowed to send animations, games, stickers and use inline bots.
107+
can_send_stickers (``bool``, *optional*):
108+
True, if the user is allowed to send stickers, implies can_send_media_messages.
109+
110+
can_send_animations (``bool``, *optional*):
111+
True, if the user is allowed to send animations (GIFs), implies can_send_media_messages.
112+
113+
can_send_games (``bool``, *optional*):
114+
True, if the user is allowed to send games, implies can_send_media_messages.
115+
116+
can_use_inline_bots (``bool``, *optional*):
117+
True, if the user is allowed to use inline bots, implies can_send_media_messages.
110118
111119
can_add_web_page_previews (``bool``, *optional*):
112120
Restricted only.
@@ -145,7 +153,10 @@ def __init__(
145153
# Restricted user permissions
146154
can_send_messages: bool = None, # Text, contacts, locations and venues
147155
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
148-
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results
156+
can_send_stickers: bool = None,
157+
can_send_animations: bool = None,
158+
can_send_games: bool = None,
159+
can_use_inline_bots: bool = None,
149160
can_add_web_page_previews: bool = None,
150161
can_send_polls: bool = None
151162
):
@@ -173,7 +184,10 @@ def __init__(
173184

174185
self.can_send_messages = can_send_messages
175186
self.can_send_media_messages = can_send_media_messages
176-
self.can_send_other_messages = can_send_other_messages
187+
self.can_send_stickers = can_send_stickers
188+
self.can_send_animations = can_send_animations
189+
self.can_send_games = can_send_games
190+
self.can_use_inline_bots = can_use_inline_bots
177191
self.can_add_web_page_previews = can_add_web_page_previews
178192
self.can_send_polls = can_send_polls
179193

@@ -246,10 +260,10 @@ def _parse(client, member, users) -> "ChatMember":
246260
restricted_by=pyrogram.User._parse(client, users[member.kicked_by]),
247261
can_send_messages=not denied_permissions.send_messages,
248262
can_send_media_messages=not denied_permissions.send_media,
249-
can_send_other_messages=(
250-
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
251-
not denied_permissions.send_games or not denied_permissions.send_inline
252-
),
263+
can_send_stickers=not denied_permissions.send_stickers,
264+
can_send_animations=not denied_permissions.send_gifs,
265+
can_send_games=not denied_permissions.send_games,
266+
can_use_inline_bots=not denied_permissions.send_inline,
253267
can_add_web_page_previews=not denied_permissions.embed_links,
254268
can_send_polls=not denied_permissions.send_polls,
255269
can_change_info=not denied_permissions.change_info,

pyrogram/client/types/user_and_chats/chat_permissions.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ class ChatPermissions(Object):
2626
Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or
2727
administrators in groups or channels.
2828
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``.
37+
2938
Parameters:
3039
can_send_messages (``bool``, *optional*):
3140
True, if the user is allowed to send text messages, contacts, locations and venues.
@@ -34,9 +43,17 @@ class ChatPermissions(Object):
3443
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies
3544
can_send_messages.
3645
37-
can_send_other_messages (``bool``, *optional*):
38-
True, if the user is allowed to send animations, games, stickers and use inline bots, implies
39-
can_send_media_messages
46+
can_send_stickers (``bool``, *optional*):
47+
True, if the user is allowed to send stickers, implies can_send_media_messages.
48+
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.
4057
4158
can_add_web_page_previews (``bool``, *optional*):
4259
True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
@@ -61,7 +78,10 @@ def __init__(
6178
*,
6279
can_send_messages: bool = None, # Text, contacts, locations and venues
6380
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
64-
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results
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,
6585
can_add_web_page_previews: bool = None,
6686
can_send_polls: bool = None,
6787
can_change_info: bool = None,
@@ -72,7 +92,10 @@ def __init__(
7292

7393
self.can_send_messages = can_send_messages
7494
self.can_send_media_messages = can_send_media_messages
75-
self.can_send_other_messages = can_send_other_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
7699
self.can_add_web_page_previews = can_add_web_page_previews
77100
self.can_send_polls = can_send_polls
78101
self.can_change_info = can_change_info
@@ -85,10 +108,10 @@ def _parse(denied_permissions: types.ChatBannedRights) -> "ChatPermissions":
85108
return ChatPermissions(
86109
can_send_messages=not denied_permissions.send_messages,
87110
can_send_media_messages=not denied_permissions.send_media,
88-
can_send_other_messages=(
89-
not denied_permissions.send_stickers or not denied_permissions.send_gifs or
90-
not denied_permissions.send_games or not denied_permissions.send_inline
91-
),
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,
92115
can_add_web_page_previews=not denied_permissions.embed_links,
93116
can_send_polls=not denied_permissions.send_polls,
94117
can_change_info=not denied_permissions.change_info,

0 commit comments

Comments
 (0)