Improve documentation for ParticipantPermissions

This commit is contained in:
Lonami Exo 2020-10-06 11:06:37 +02:00
parent 7f61b92f81
commit cf1645b598
3 changed files with 58 additions and 1 deletions

View File

@ -136,10 +136,19 @@ MessageButton
:show-inheritance: :show-inheritance:
ParticipantPermissions
======================
.. automodule:: telethon.tl.custom.participantpermissions
:members:
:undoc-members:
:show-inheritance:
QRLogin QRLogin
======= =======
.. automodule:: telethon.qrlogin .. automodule:: telethon.tl.custom.qrlogin
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

@ -1174,6 +1174,11 @@ class ChatMethods:
user (`entity`): user (`entity`):
Target user. Target user.
Returns
A `ParticipantPermissions <telethon.tl.custom.participantpermissions.ParticipantPermissions>`
instance. Refer to its documentation to see what properties are
available.
Example Example
.. code-block:: python .. code-block:: python

View File

@ -24,6 +24,10 @@ class ParticipantPermissions:
@property @property
def is_admin(self): def is_admin(self):
"""
Whether the user is an administrator of the chat or not. The creator
also counts as begin an administrator, since they have all permissions.
"""
return self.is_creator or isinstance(self.participant, ( return self.is_creator or isinstance(self.participant, (
types.ChannelParticipantAdmin, types.ChannelParticipantAdmin,
types.ChatParticipantAdmin types.ChatParticipantAdmin
@ -31,6 +35,9 @@ class ParticipantPermissions:
@property @property
def is_creator(self): def is_creator(self):
"""
Whether the user is the creator of the chat or not.
"""
return isinstance(self.participant, ( return isinstance(self.participant, (
types.ChannelParticipantCreator, types.ChannelParticipantCreator,
types.ChatParticipantCreator types.ChatParticipantCreator
@ -38,6 +45,10 @@ class ParticipantPermissions:
@property @property
def has_default_permissions(self): def has_default_permissions(self):
"""
Whether the user is a normal user of the chat (not administrator, but
not banned either, and has no restrictions applied).
"""
return isinstance(self.participant, ( return isinstance(self.participant, (
types.ChannelParticipant, types.ChannelParticipant,
types.ChatParticipant, types.ChatParticipant,
@ -46,10 +57,16 @@ class ParticipantPermissions:
@property @property
def is_banned(self): def is_banned(self):
"""
Whether the user is banned in the chat.
"""
return isinstance(self.participant, types.ChannelParticipantBanned) return isinstance(self.participant, types.ChannelParticipantBanned)
@property @property
def ban_users(self): def ban_users(self):
"""
Whether the administrator can ban other users or not.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -58,6 +75,9 @@ class ParticipantPermissions:
@property @property
def pin_messages(self): def pin_messages(self):
"""
Whether the administrator can pin messages or not.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -66,6 +86,10 @@ class ParticipantPermissions:
@property @property
def add_admins(self): def add_admins(self):
"""
Whether the administrator can add new administrators with the same or
less permissions than them.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat and not self.is_creator: if self.is_chat and not self.is_creator:
@ -74,6 +98,9 @@ class ParticipantPermissions:
@property @property
def invite_users(self): def invite_users(self):
"""
Whether the administrator can add new users to the chat.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -82,6 +109,9 @@ class ParticipantPermissions:
@property @property
def delete_messages(self): def delete_messages(self):
"""
Whether the administrator can delete messages from other participants.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -90,6 +120,9 @@ class ParticipantPermissions:
@property @property
def edit_messages(self): def edit_messages(self):
"""
Whether the administrator can edit messages.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -98,6 +131,9 @@ class ParticipantPermissions:
@property @property
def post_messages(self): def post_messages(self):
"""
Whether the administrator can post messages in the broadcast channel.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -106,6 +142,10 @@ class ParticipantPermissions:
@property @property
def change_info(self): def change_info(self):
"""
Whether the administrator can change the information about the chat,
such as title or description.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat:
@ -114,6 +154,9 @@ class ParticipantPermissions:
@property @property
def anonymous(self): def anonymous(self):
"""
Whether the administrator will remain anonymous when sending messages.
"""
if not self.is_admin: if not self.is_admin:
return False return False
if self.is_chat: if self.is_chat: