mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-01 10:49:58 +03:00
added get_permissions method from #1574
This commit is contained in:
parent
18f70b3bac
commit
c4ab662e8b
|
@ -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',
|
||||
|
|
|
@ -11,3 +11,4 @@ from .inlineresult import InlineResult
|
|||
from .inlineresults import InlineResults
|
||||
from .conversation import Conversation
|
||||
from .qrlogin import QRLogin
|
||||
from .userpermissions import ParticipantPermissions
|
||||
|
|
29
telethon/tl/custom/participantpermissions.py
Normal file
29
telethon/tl/custom/participantpermissions.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user