added get_permissions method from #1574

This commit is contained in:
kolay 2020-10-01 23:55:09 +03:00
parent 18f70b3bac
commit c4ab662e8b
3 changed files with 47 additions and 0 deletions

View File

@ -1145,6 +1145,23 @@ class ChatMethods:
else:
raise ValueError('You must pass either a channel or a chat')
async def get_permissions(
self: 'TelegramClient',
channel: 'hints.EntityLike',
user: 'hints.EntityLike'
) -> 'custom.ParticipantPermissions':
channel = await self.get_input_entity(channel)
user = await self.get_input_entity(user)
if helpers._entity_type(user) != helpers._EntityType.USER:
raise ValueError('You must pass a user entity')
if helpers._entity_type(channel) != helpers._EntityType.CHANNEL:
raise ValueError('You must pass a channel entity')
participant = await self(functions.channels.GetParticipantRequest(
channel,
user
))
return custom.ParticipantPermissions(participant.participant)
async def get_stats(
self: 'TelegramClient',
entity: 'hints.EntityLike',

View File

@ -11,3 +11,4 @@ from .inlineresult import InlineResult
from .inlineresults import InlineResults
from .conversation import Conversation
from .qrlogin import QRLogin
from .userpermissions import ParticipantPermissions

View File

@ -0,0 +1,29 @@
from .. import types
class ParticipantPermissions:
"""
Participant permissions information
"""
def __init__(self, participant):
self.participant = participant
@property
def is_admin(self):
return self.is_creator or isinstance(self.participant, types.ChannelParticipantAdmin)
@property
def is_creator(self):
return isinstance(self.participant, types.ChannelParticipantCreator)
@property
def is_default_permissions(self):
return isinstance(self.participant, types.ChannelParticipant)
@property
def is_banned(self):
return isinstance(self.participant, types.ChannelParticipantBanned)
@property
def is_self(self):
return isinstance(self.participant, types.ChannelParticipantSelf)