diff --git a/telethon/client/chats.py b/telethon/client/chats.py index 9dbdadb2..71c6be91 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -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', diff --git a/telethon/tl/custom/__init__.py b/telethon/tl/custom/__init__.py index b5599c53..15aff945 100644 --- a/telethon/tl/custom/__init__.py +++ b/telethon/tl/custom/__init__.py @@ -11,3 +11,4 @@ from .inlineresult import InlineResult from .inlineresults import InlineResults from .conversation import Conversation from .qrlogin import QRLogin +from .userpermissions import ParticipantPermissions diff --git a/telethon/tl/custom/participantpermissions.py b/telethon/tl/custom/participantpermissions.py new file mode 100644 index 00000000..25641b30 --- /dev/null +++ b/telethon/tl/custom/participantpermissions.py @@ -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)