Skip to content

Commit

Permalink
sb 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jul 31, 2023
1 parent e06796d commit 6f24f45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion sb/DES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
在自己拥有管理员权限的共同群组中封禁一位用户。
指令:,sb

指令: `,sb` 回复用户
31 changes: 15 additions & 16 deletions sb/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
from asyncio import sleep

from pyrogram.enums import ChatType
Expand Down Expand Up @@ -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


Expand All @@ -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


Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6f24f45

Please sign in to comment.