Add a convenience method for editing admin rights.

This commit is contained in:
painor 2019-05-11 14:29:55 +01:00
parent 278f0e9e98
commit 065414657a
2 changed files with 66 additions and 2 deletions

View File

@ -612,4 +612,68 @@ class ChatMethods(UserMethods):
return _ChatAction(
self, entity, action, delay=delay, auto_cancel=auto_cancel)
async def edit_admin(self, entity, user, change_info=None, post_messages=None, edit_messages=None,
delete_messages=None, ban_users=None, invite_users=None, pin_messages=None, add_admins=None, is_admin=None):
"""
Edits admin permissions for the given entity
will raise an error if wrong comibnation of rights are given
:param entity (`entity`):
either a channel or a supergroup or a chat
:param user (`entity`):
the user to be promoted
:param change_info (`bool`, optional):
wether the user will be able to change info. works in channels and supergrous.
:param post_messages (`bool`, optional):
wether the user will be able to post in the channel. only works in channels.
:param edit_messages (`bool`, optional):
wether the user will be able to edit messages in the channel. only works in channels.
:param delete_messages (`bool`, optional):
wether the user will be able to delete messages. works in channels and supergroups.
:param ban_users (`bool`, optional):
wether the user will be able to ban users. works in channels and supergroups.
:param invite_users (`bool`, optional):
wether the user will be able to invite users. Needs some testing.
:param pin_messages (`bool`, optional):
wether the user will be able to pin messages. works in channels and supergroups.
:param add_admins (`bool`, optional):
wether the user will be able to add admins. works in channels and supergroups.
:param is_admin (`bool`, optional):
wether the user will be an admin in the chat. only works in chats.
:return: returns None
"""
entity = await self.get_input_entity(entity)
user = await self.get_input_entity(user)
if not isinstance(user, types.InputPeerUser):
raise ValueError("You must pass a user")
if isinstance(entity, types.InputPeerChannel):
await self(functions.channels.EditAdminRequest(
entity,
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
)
))
elif isinstance(entity, types.InputPeerChat):
await self(functions.messages.EditChatAdminRequest(entity,user,is_admin=is_admin))
else:
raise ValueError("you must pass either a channel or a supergroup or a normal group")
# endregion

View File

@ -201,7 +201,7 @@ REPLY_MARKUP_TOO_LONG,400,The data embedded in the reply markup buttons was too
RESULT_ID_DUPLICATE,400,Duplicated IDs on the sent results. Make sure to use unique IDs.
RESULT_TYPE_INVALID,400,Result type invalid
RESULTS_TOO_MUCH,400,You sent too many results. See https://core.telegram.org/bots/api#answerinlinequery for the current limit.
RIGHT_FORBIDDEN,403,Your admin rights do not allow you to do this
RIGHT_FORBIDDEN,403,Either your admin rights do not allow you to do this or you passed the wrong admin combination.(Some rights only apply to channels and vice versa).
RPC_CALL_FAIL,,"Telegram is having internal issues, please try again later."
RPC_MCGET_FAIL,,"Telegram is having internal issues, please try again later."
RSA_DECRYPT_FAILED,400,Internal RSA decryption failed

1 name codes description
201 RESULT_ID_DUPLICATE 400 Duplicated IDs on the sent results. Make sure to use unique IDs.
202 RESULT_TYPE_INVALID 400 Result type invalid
203 RESULTS_TOO_MUCH 400 You sent too many results. See https://core.telegram.org/bots/api#answerinlinequery for the current limit.
204 RIGHT_FORBIDDEN 403 Your admin rights do not allow you to do this Either your admin rights do not allow you to do this or you passed the wrong admin combination.(Some rights only apply to channels and vice versa).
205 RPC_CALL_FAIL Telegram is having internal issues, please try again later.
206 RPC_MCGET_FAIL Telegram is having internal issues, please try again later.
207 RSA_DECRYPT_FAILED 400 Internal RSA decryption failed