From aed8ccf18d857faf7af77e189d0086ee5fb8e7ed Mon Sep 17 00:00:00 2001 From: mrmissx Date: Tue, 31 May 2022 21:34:09 +0700 Subject: [PATCH] SpamPrediction: Fix case when ban button is invoked by non chat member --- anjani/plugins/spam_prediction.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/anjani/plugins/spam_prediction.py b/anjani/plugins/spam_prediction.py index 3311d4e52..4cf4d6bde 100644 --- a/anjani/plugins/spam_prediction.py +++ b/anjani/plugins/spam_prediction.py @@ -31,6 +31,7 @@ MessageNotModified, QueryIdInvalid, UserAdminInvalid, + UserNotParticipant ) from pyrogram.types import ( CallbackQuery, @@ -178,7 +179,14 @@ async def on_callback_query(self, query: CallbackQuery) -> None: async def _spam_ban_handler(self, query: CallbackQuery, user: str) -> None: chat = query.message.chat - invoker = await chat.get_member(query.from_user.id) + try: + invoker = await chat.get_member(query.from_user.id) + except UserNotParticipant: + return await query.answer( + await self.get_text(chat.id, "error-no-rights"), + show_alert=True + ) + if not invoker.privileges or not invoker.privileges.can_restrict_members: return await query.answer(await self.get_text(chat.id, "spampredict-ban-no-perm"))