diff --git a/userge/plugins/admin/gban.py b/userge/plugins/admin/gban.py index 11a1cc898..f1ab1ac0b 100644 --- a/userge/plugins/admin/gban.py +++ b/userge/plugins/admin/gban.py @@ -11,6 +11,8 @@ import requests import spamwatch +from pyrogram.errors import ChatAdminRequired + from userge import userge, Message, Config, get_collection, Filters GBAN_USER_BASE = get_collection("GBAN_USER") @@ -328,31 +330,30 @@ async def gban_at_entry(message: Message): if c['user_id'] == user_id: reason = c['reason'] try: - if await guadmin_check(chat_id, user_id): - await userge.kick_chat_member(chat_id, user_id) - await message.reply( - r"\\**#Userge_Antispam**//" - "\n\n\nGlobally Banned User Detected in this Chat.\n\n" - f"**User:** [{firstname}](tg://user?id={user_id})\n" - f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" - "**Quick Action:** Banned.") - await GBAN_LOG.log( - r"\\**#Antispam_Log**//" - "\n\n**GBanned User $SPOTTED**\n" - f"**User:** [{firstname}](tg://user?id={user_id})\n" - f"**ID:** `{user_id}`\n**Reason:** {reason}\n**Quick Action:** " - "Banned in {message.chat.title}") - except Exception: + await userge.kick_chat_member(chat_id, user_id) + await message.reply( + r"\\**#Userge_Antispam**//" + "\n\n\nGlobally Banned User Detected in this Chat.\n\n" + f"**User:** [{firstname}](tg://user?id={user_id})\n" + f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n\n" + "**Quick Action:** Banned.") + await GBAN_LOG.log( + r"\\**#Antispam_Log**//" + "\n\n**GBanned User $SPOTTED**\n" + f"**User:** [{firstname}](tg://user?id={user_id})\n" + f"**ID:** `{user_id}`\n**Reason:** {reason}\n**Quick Action:** " + "Banned in {message.chat.title}") + except ChatAdminRequired: break - except Exception: - pass + except Exception as e: + LOG.exception(e) if Config.ANTISPAM_SENTRY: try: if Config.SPAM_WATCH_API is not None: SENTRY = spamwatch.Client(Config.SPAM_WATCH_API) intruder = SENTRY.get_ban(user_id) - if intruder and await guadmin_check(chat_id, user_id): + if intruder: await userge.kick_chat_member(chat_id, user_id) await message.reply( r"\\**#Userge_Antispam**//" @@ -368,13 +369,13 @@ async def gban_at_entry(message: Message): f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{intruder.reason}`\n" "**Quick Action:** Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") - except Exception: + except ChatAdminRequired: pass try: res = requests.get(f'https://combot.org/api/cas/check?user_id={user_id}') res_dict = json.loads(res.text) - if res_dict['ok'] and await guadmin_check(chat_id, user_id): + if res_dict['ok']: try: reason = res_dict['result']['offenses'] await userge.kick_chat_member(chat_id, user_id) @@ -392,8 +393,9 @@ async def gban_at_entry(message: Message): f"\n**User:** [{firstname}](tg://user?id={user_id})\n" f"**ID:** `{user_id}`\n**Reason:** `{reason}`\n**Quick Action:**" " Banned in {message.chat.title}\n\n$AUTOBAN #id{user_id}") - except Exception: + except ChatAdminRequired: pass - except Exception: - pass + except Exception as e: + LOG.exception(e) + message.continue_propagation()