diff --git a/telethon/client/chats.py b/telethon/client/chats.py index 273979f6..9d6c56bd 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -611,5 +611,69 @@ 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 diff --git a/telethon_generator/data/errors.csv b/telethon_generator/data/errors.csv index 6439ea53..83b7015b 100644 --- a/telethon_generator/data/errors.csv +++ b/telethon_generator/data/errors.csv @@ -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 @@ -270,4 +270,4 @@ WALLPAPER_INVALID,400,The input wallpaper was not valid WC_CONVERT_URL_INVALID,400,WC convert URL invalid WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL WEBPAGE_MEDIA_EMPTY,400,Webpage media empty -YOU_BLOCKED_USER,400,You blocked this user +YOU_BLOCKED_USER,400,You blocked this user \ No newline at end of file