Sync chat permissions with official clients
This commit is contained in:
parent
6cb3e92838
commit
c9d0c5d75a
@ -52,17 +52,16 @@ class SetChatPermissions(Scaffold):
|
||||
# Completely restrict chat
|
||||
app.set_chat_permissions(chat_id, ChatPermissions())
|
||||
|
||||
# Chat members can only send text messages, media, stickers and GIFs
|
||||
# Chat members can only send text messages and media messages
|
||||
app.set_chat_permissions(
|
||||
chat_id,
|
||||
ChatPermissions(
|
||||
can_send_messages=True,
|
||||
can_send_media_messages=True,
|
||||
can_send_stickers=True,
|
||||
can_send_animations=True
|
||||
can_send_media_messages=True
|
||||
)
|
||||
)
|
||||
"""
|
||||
|
||||
r = await self.send(
|
||||
raw.functions.messages.EditChatDefaultBannedRights(
|
||||
peer=await self.resolve_peer(chat_id),
|
||||
@ -70,10 +69,10 @@ class SetChatPermissions(Scaffold):
|
||||
until_date=0,
|
||||
send_messages=True if not permissions.can_send_messages else None,
|
||||
send_media=True if not permissions.can_send_media_messages else None,
|
||||
send_stickers=True if not permissions.can_send_stickers else None,
|
||||
send_gifs=True if not permissions.can_send_animations else None,
|
||||
send_games=True if not permissions.can_send_games else None,
|
||||
send_inline=True if not permissions.can_use_inline_bots else None,
|
||||
send_stickers=permissions.can_send_other_messages,
|
||||
send_gifs=permissions.can_send_other_messages,
|
||||
send_games=permissions.can_send_other_messages,
|
||||
send_inline=permissions.can_send_other_messages,
|
||||
embed_links=True if not permissions.can_add_web_page_previews else None,
|
||||
send_polls=True if not permissions.can_send_polls else None,
|
||||
change_info=True if not permissions.can_change_info else None,
|
||||
|
@ -21,49 +21,31 @@ from ..object import Object
|
||||
|
||||
|
||||
class ChatPermissions(Object):
|
||||
"""A chat default permissions and a single member permissions within a chat.
|
||||
|
||||
Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or
|
||||
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``.
|
||||
"""Describes actions that a non-administrator user is allowed to take in a chat.
|
||||
|
||||
Parameters:
|
||||
can_send_messages (``bool``, *optional*):
|
||||
True, if the user is allowed to send text messages, contacts, locations and venues.
|
||||
|
||||
can_send_media_messages (``bool``, *optional*):
|
||||
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies
|
||||
can_send_messages.
|
||||
True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes.
|
||||
Implies *can_send_messages*.
|
||||
|
||||
can_send_stickers (``bool``, *optional*):
|
||||
True, if the user is allowed to send stickers, implies 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*):
|
||||
True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
|
||||
can_send_other_messages (``bool``, *optional*):
|
||||
True, if the user is allowed to send animations, games, stickers and use inline bots.
|
||||
Implies *can_send_media_messages*.
|
||||
|
||||
can_send_polls (``bool``, *optional*):
|
||||
True, if the user is allowed to send polls, implies can_send_messages.
|
||||
True, if the user is allowed to send polls.
|
||||
Implies can_send_messages
|
||||
|
||||
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*.
|
||||
|
||||
can_change_info (``bool``, *optional*):
|
||||
True, if the user is allowed to change the chat title, photo and other settings.
|
||||
Ignored in public supergroups.
|
||||
Ignored in public supergroups
|
||||
|
||||
can_invite_users (``bool``, *optional*):
|
||||
True, if the user is allowed to invite new users to the chat.
|
||||
@ -77,13 +59,10 @@ class ChatPermissions(Object):
|
||||
self,
|
||||
*,
|
||||
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_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_send_media_messages: bool = None, # Audio files, documents, photos, videos, video notes and voice notes
|
||||
can_send_other_messages: bool = None, # Stickers, animations, games, inline bots
|
||||
can_send_polls: bool = None,
|
||||
can_add_web_page_previews: bool = None,
|
||||
can_change_info: bool = None,
|
||||
can_invite_users: bool = None,
|
||||
can_pin_messages: bool = None
|
||||
@ -92,12 +71,9 @@ class ChatPermissions(Object):
|
||||
|
||||
self.can_send_messages = can_send_messages
|
||||
self.can_send_media_messages = can_send_media_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_send_other_messages = can_send_other_messages
|
||||
self.can_send_polls = can_send_polls
|
||||
self.can_add_web_page_previews = can_add_web_page_previews
|
||||
self.can_change_info = can_change_info
|
||||
self.can_invite_users = can_invite_users
|
||||
self.can_pin_messages = can_pin_messages
|
||||
@ -108,10 +84,12 @@ class ChatPermissions(Object):
|
||||
return ChatPermissions(
|
||||
can_send_messages=not denied_permissions.send_messages,
|
||||
can_send_media_messages=not denied_permissions.send_media,
|
||||
can_send_stickers=not denied_permissions.send_stickers,
|
||||
can_send_animations=not denied_permissions.send_gifs,
|
||||
can_send_games=not denied_permissions.send_games,
|
||||
can_use_inline_bots=not denied_permissions.send_inline,
|
||||
can_send_other_messages=any([
|
||||
not denied_permissions.send_stickers,
|
||||
not denied_permissions.send_gifs,
|
||||
not denied_permissions.send_games,
|
||||
not denied_permissions.send_inline
|
||||
]),
|
||||
can_add_web_page_previews=not denied_permissions.embed_links,
|
||||
can_send_polls=not denied_permissions.send_polls,
|
||||
can_change_info=not denied_permissions.change_info,
|
||||
|
Loading…
Reference in New Issue
Block a user