mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-03 11:40:11 +03:00
Better is_admin behaviour
This commit is contained in:
parent
0edb44091e
commit
37c3c8a85e
|
@ -820,6 +820,13 @@ class ChatMethods(UserMethods):
|
||||||
is_admin (`bool`, optional):
|
is_admin (`bool`, optional):
|
||||||
Whether the user will be an admin in the chat.
|
Whether the user will be an admin in the chat.
|
||||||
This will only work in small group chats.
|
This will only work in small group chats.
|
||||||
|
Whether the user will be an admin in the chat. This is the
|
||||||
|
only permission available in small group chats, and when
|
||||||
|
used in megagroups, all non-explicitly set permissions will
|
||||||
|
have this value.
|
||||||
|
|
||||||
|
Essentially, only passing ``is_admin=True`` will grant all
|
||||||
|
permissions, but you can still disable those you need.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
The resulting :tl:`Updates` object.
|
The resulting :tl:`Updates` object.
|
||||||
|
@ -829,31 +836,40 @@ class ChatMethods(UserMethods):
|
||||||
|
|
||||||
# Allowing `user` to pin messages in `chat`
|
# Allowing `user` to pin messages in `chat`
|
||||||
client.edit_admin(chat, user, pin_messages=True)
|
client.edit_admin(chat, user, pin_messages=True)
|
||||||
|
|
||||||
|
# Granting all permissions except for `add_admins`
|
||||||
|
client.edit_admin(chat, user, is_admin=True, add_admins=False)
|
||||||
"""
|
"""
|
||||||
entity = await self.get_input_entity(entity)
|
entity = await self.get_input_entity(entity)
|
||||||
user = await self.get_input_entity(user)
|
user = await self.get_input_entity(user)
|
||||||
if not isinstance(user, types.InputPeerUser):
|
if not isinstance(user, types.InputPeerUser):
|
||||||
raise ValueError('You must pass a user entity')
|
raise ValueError('You must pass a user entity')
|
||||||
|
|
||||||
if isinstance(entity, types.InputPeerChannel):
|
perm_names = (
|
||||||
return await self(functions.channels.EditAdminRequest(
|
'change_info', 'post_messages', 'edit_messages', 'delete_messages',
|
||||||
entity,
|
'ban_users', 'invite_users', 'pin_messages', 'add_admins'
|
||||||
user,
|
|
||||||
types.ChatAdminRights(
|
|
||||||
change_info=change_info,
|
|
||||||
post_messages=post_messages,
|
|
||||||
edit_messages=edit_messages,
|
|
||||||
delete_messages=delete_messages,
|
|
||||||
ban_users=ban_users,
|
|
||||||
invite_users=invite_users,
|
|
||||||
pin_messages=pin_messages,
|
|
||||||
add_admins=add_admins
|
|
||||||
)
|
)
|
||||||
))
|
|
||||||
|
if isinstance(entity, types.InputPeerChannel):
|
||||||
|
perms = locals()
|
||||||
|
return await self(functions.channels.EditAdminRequest(entity, user, types.ChatAdminRights(**{
|
||||||
|
# A permission is its explicit (not-None) value or `is_admin`.
|
||||||
|
# This essentially makes `is_admin` be the default value.
|
||||||
|
name: perms[name] if perms[name] is not None else is_admin
|
||||||
|
for name in perm_names
|
||||||
|
})))
|
||||||
|
|
||||||
elif isinstance(entity, types.InputPeerChat):
|
elif isinstance(entity, types.InputPeerChat):
|
||||||
return await self(functions.messages.EditChatAdminRequest(entity, user, is_admin=is_admin))
|
# If the user passed any permission in a small
|
||||||
|
# group chat, they must be a full admin to have it.
|
||||||
|
if is_admin is None:
|
||||||
|
is_admin = any(locals()[x] for x in perm_names)
|
||||||
|
|
||||||
|
return await self(functions.messages.EditChatAdminRequest(
|
||||||
|
entity, user, is_admin=is_admin))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError('You must pass either a channel or a supergroup or a normal group')
|
raise ValueError('You can only edit permissions in groups and channels')
|
||||||
|
|
||||||
async def edit_restriction(
|
async def edit_restriction(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user