From ae1c1b3912301b0f51ef0e3ad08f55c48438463d Mon Sep 17 00:00:00 2001 From: painor <30215770+painor@users.noreply.github.com> Date: Wed, 10 Jul 2019 22:19:50 +0100 Subject: [PATCH] Improve permission-related errors (#1231) --- telethon/client/chats.py | 6 ++++++ telethon_generator/data/errors.csv | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/telethon/client/chats.py b/telethon/client/chats.py index 74111ffb..91d0bd35 100644 --- a/telethon/client/chats.py +++ b/telethon/client/chats.py @@ -847,6 +847,9 @@ class ChatMethods: """ entity = await self.get_input_entity(entity) user = await self.get_input_entity(user) + if isinstance(user, types.InputPeerSelf): + raise ValueError('You cannot admin yourself') + if not isinstance(user, types.InputPeerUser): raise ValueError('You must pass a user entity') @@ -996,6 +999,9 @@ class ChatMethods: )) user = await self.get_input_entity(user) + if isinstance(user, types.InputPeerSelf): + raise ValueError('You cannot restrict yourself') + if not isinstance(user, types.InputPeerUser): raise ValueError('You must pass a user entity') diff --git a/telethon_generator/data/errors.csv b/telethon_generator/data/errors.csv index bdba3194..48a79654 100644 --- a/telethon_generator/data/errors.csv +++ b/telethon_generator/data/errors.csv @@ -207,7 +207,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 rights 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 @@ -249,7 +249,7 @@ USERNAME_NOT_OCCUPIED,400,The username is not in use by anyone else yet USERNAME_OCCUPIED,400,The username is already taken USERS_TOO_FEW,400,"Not enough users (to create a chat, for example)" USERS_TOO_MUCH,400,"The maximum number of users has been exceeded (to create a chat, for example)" -USER_ADMIN_INVALID,400,You're not an admin +USER_ADMIN_INVALID,400,Either you're not an admin or you tried to ban an admin that you didn't promote USER_ALREADY_PARTICIPANT,400,The authenticated user is already a participant of the chat USER_BANNED_IN_CHANNEL,400,You're banned from sending messages in supergroups/channels USER_BLOCKED,400,User blocked