2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Add extended chat permissions

This commit is contained in:
Dan 2020-03-30 15:24:07 +02:00
parent 75ad20bc57
commit b9c50b0ae0
2 changed files with 55 additions and 18 deletions

View File

@ -104,9 +104,17 @@ class ChatMember(Object):
Restricted only. Restricted only.
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
can_send_other_messages (``bool``, *optional*): can_send_stickers (``bool``, *optional*):
Restricted only. True, if the user is allowed to send stickers, implies can_send_media_messages.
True, if the user is allowed to send animations, games, stickers and use inline bots.
can_send_animations (``bool``, *optional*):
True, if the user is allowed to send animations (GIFs), implies can_send_media_messages.
can_send_games (``bool``, *optional*):
True, if the user is allowed to send games, implies can_send_media_messages.
can_use_inline_bots (``bool``, *optional*):
True, if the user is allowed to use inline bots, implies can_send_media_messages.
can_add_web_page_previews (``bool``, *optional*): can_add_web_page_previews (``bool``, *optional*):
Restricted only. Restricted only.
@ -145,7 +153,10 @@ class ChatMember(Object):
# Restricted user permissions # Restricted user permissions
can_send_messages: bool = None, # Text, contacts, locations and venues can_send_messages: bool = None, # Text, contacts, locations and venues
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results can_send_stickers: bool = None,
can_send_animations: bool = None,
can_send_games: bool = None,
can_use_inline_bots: bool = None,
can_add_web_page_previews: bool = None, can_add_web_page_previews: bool = None,
can_send_polls: bool = None can_send_polls: bool = None
): ):
@ -173,7 +184,10 @@ class ChatMember(Object):
self.can_send_messages = can_send_messages self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages self.can_send_media_messages = can_send_media_messages
self.can_send_other_messages = can_send_other_messages self.can_send_stickers = can_send_stickers
self.can_send_animations = can_send_animations
self.can_send_games = can_send_games
self.can_use_inline_bots = can_use_inline_bots
self.can_add_web_page_previews = can_add_web_page_previews self.can_add_web_page_previews = can_add_web_page_previews
self.can_send_polls = can_send_polls self.can_send_polls = can_send_polls
@ -246,10 +260,10 @@ class ChatMember(Object):
restricted_by=pyrogram.User._parse(client, users[member.kicked_by]), restricted_by=pyrogram.User._parse(client, users[member.kicked_by]),
can_send_messages=not denied_permissions.send_messages, can_send_messages=not denied_permissions.send_messages,
can_send_media_messages=not denied_permissions.send_media, can_send_media_messages=not denied_permissions.send_media,
can_send_other_messages=( can_send_stickers=not denied_permissions.send_stickers,
not denied_permissions.send_stickers or not denied_permissions.send_gifs or can_send_animations=not denied_permissions.send_gifs,
not denied_permissions.send_games or not denied_permissions.send_inline can_send_games=not denied_permissions.send_games,
), can_use_inline_bots=not denied_permissions.send_inline,
can_add_web_page_previews=not denied_permissions.embed_links, can_add_web_page_previews=not denied_permissions.embed_links,
can_send_polls=not denied_permissions.send_polls, can_send_polls=not denied_permissions.send_polls,
can_change_info=not denied_permissions.change_info, can_change_info=not denied_permissions.change_info,

View File

@ -26,6 +26,15 @@ class ChatPermissions(Object):
Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or
administrators in groups or channels. administrators in groups or channels.
.. note::
Pyrogram's chat permission are much more detailed. In particular, you can restrict sending stickers, animations,
games and inline bot results individually, allowing a finer control.
If you wish to have the same permissions as seen in official apps or in bot API's *"can_send_other_messages"*
simply set these arguments to True: ``can_send_stickers``, ``can_send_animations``, ``can_send_games`` and
``can_use_inline_bots``.
Parameters: Parameters:
can_send_messages (``bool``, *optional*): can_send_messages (``bool``, *optional*):
True, if the user is allowed to send text messages, contacts, locations and venues. True, if the user is allowed to send text messages, contacts, locations and venues.
@ -34,9 +43,17 @@ class ChatPermissions(Object):
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies
can_send_messages. can_send_messages.
can_send_other_messages (``bool``, *optional*): can_send_stickers (``bool``, *optional*):
True, if the user is allowed to send animations, games, stickers and use inline bots, implies True, if the user is allowed to send stickers, implies can_send_media_messages.
can_send_media_messages
can_send_animations (``bool``, *optional*):
True, if the user is allowed to send animations (GIFs), implies can_send_media_messages.
can_send_games (``bool``, *optional*):
True, if the user is allowed to send games, implies can_send_media_messages.
can_use_inline_bots (``bool``, *optional*):
True, if the user is allowed to use inline bots, implies can_send_media_messages.
can_add_web_page_previews (``bool``, *optional*): can_add_web_page_previews (``bool``, *optional*):
True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages. True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
@ -61,7 +78,10 @@ class ChatPermissions(Object):
*, *,
can_send_messages: bool = None, # Text, contacts, locations and venues can_send_messages: bool = None, # Text, contacts, locations and venues
can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes
can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results can_send_stickers: bool = None,
can_send_animations: bool = None,
can_send_games: bool = None,
can_use_inline_bots: bool = None,
can_add_web_page_previews: bool = None, can_add_web_page_previews: bool = None,
can_send_polls: bool = None, can_send_polls: bool = None,
can_change_info: bool = None, can_change_info: bool = None,
@ -72,7 +92,10 @@ class ChatPermissions(Object):
self.can_send_messages = can_send_messages self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages self.can_send_media_messages = can_send_media_messages
self.can_send_other_messages = can_send_other_messages self.can_send_stickers = can_send_stickers
self.can_send_animations = can_send_animations
self.can_send_games = can_send_games
self.can_use_inline_bots = can_use_inline_bots
self.can_add_web_page_previews = can_add_web_page_previews self.can_add_web_page_previews = can_add_web_page_previews
self.can_send_polls = can_send_polls self.can_send_polls = can_send_polls
self.can_change_info = can_change_info self.can_change_info = can_change_info
@ -85,10 +108,10 @@ class ChatPermissions(Object):
return ChatPermissions( return ChatPermissions(
can_send_messages=not denied_permissions.send_messages, can_send_messages=not denied_permissions.send_messages,
can_send_media_messages=not denied_permissions.send_media, can_send_media_messages=not denied_permissions.send_media,
can_send_other_messages=( can_send_stickers=not denied_permissions.send_stickers,
not denied_permissions.send_stickers or not denied_permissions.send_gifs or can_send_animations=not denied_permissions.send_gifs,
not denied_permissions.send_games or not denied_permissions.send_inline can_send_games=not denied_permissions.send_games,
), can_use_inline_bots=not denied_permissions.send_inline,
can_add_web_page_previews=not denied_permissions.embed_links, can_add_web_page_previews=not denied_permissions.embed_links,
can_send_polls=not denied_permissions.send_polls, can_send_polls=not denied_permissions.send_polls,
can_change_info=not denied_permissions.change_info, can_change_info=not denied_permissions.change_info,