From 6f24f45ee20c115a6ccc355285b814628f864e9e Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 31 Jul 2023 11:29:27 +0800 Subject: [PATCH] =?UTF-8?q?sb=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sb/DES.md | 3 ++- sb/main.py | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sb/DES.md b/sb/DES.md index 54943cb..22ed33b 100644 --- a/sb/DES.md +++ b/sb/DES.md @@ -1,2 +1,3 @@ 在自己拥有管理员权限的共同群组中封禁一位用户。 -指令:,sb \ No newline at end of file + +指令: `,sb` 回复用户 diff --git a/sb/main.py b/sb/main.py index aa12d32..3080f20 100644 --- a/sb/main.py +++ b/sb/main.py @@ -1,3 +1,4 @@ +import contextlib from asyncio import sleep from pyrogram.enums import ChatType @@ -36,20 +37,18 @@ async def delete_all_messages(chat: Chat, uid): async def check_uid(chat: Chat, uid: str): channel = False - try: + with contextlib.suppress(ValueError): uid = int(uid) if uid < 0: channel = True + try: await bot.get_chat_member(chat.id, uid) - except ValueError: - try: + except ChatAdminRequired: + with contextlib.suppress(PeerIdInvalid): chat = await bot.get_chat(uid) uid = chat.id if chat.type in [ChatType.CHANNEL, ChatType.SUPERGROUP, ChatType.GROUP]: channel = True - except PeerIdInvalid: - member = await bot.get_chat_member(chat.id, uid) - uid = member.user.id return uid, channel @@ -70,7 +69,7 @@ async def get_uid(chat: Chat, message: Message): uid, channel = await check_uid(chat, message.parameter[0]) delete_all = False elif len(message.parameter) == 1: - uid, channel = await check_uid(chat, message.arguments) + uid, channel = await check_uid(chat, message.parameter[0]) return uid, channel, delete_all, sender @@ -85,16 +84,17 @@ async def super_ban(message: Message): chat = message.chat try: uid, channel, delete_all, sender = await get_uid(chat, message) + if not uid: + raise ValueError + if channel and uid == chat.id: + raise ValueError except (ValueError, PeerIdInvalid, UsernameInvalid, FloodWait): await message.edit(lang("arg_error")) - return add_delete_message_job(message, 10) - if not uid: - await message.edit(lang("arg_error")) - return add_delete_message_job(message, 10) + return add_delete_message_job(message, 30) + except Exception as e: + await message.edit(f"出现错误:{e}") + return add_delete_message_job(message, 30) if channel: - if uid == chat.id: - await message.edit(lang("arg_error")) - return add_delete_message_job(message, 10) try: await ban_one(chat, uid) except ChatAdminRequired: @@ -131,8 +131,7 @@ async def super_ban(message: Message): except Exception: # noqa pass if not sender: - member = await bot.get_chat_member(chat.id, uid) - sender = member.user + sender = await bot.get_users(uid) if count == 0: text = f'{lang("sb_no")} {sender.mention}' else: