sb 修改逻辑

This commit is contained in:
xtaodada 2022-07-10 20:44:31 +08:00
parent 75fa516ae3
commit 799b901054
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 23 additions and 15 deletions

View File

@ -282,7 +282,7 @@
}, },
{ {
"name": "sb", "name": "sb",
"version": "1.001", "version": "1.01",
"section": "chat", "section": "chat",
"maintainer": "xtaodada", "maintainer": "xtaodada",
"size": "3.5 kb", "size": "3.5 kb",

View File

@ -22,25 +22,30 @@ async def delete_all_messages(chat: Chat, uid):
await bot.delete_user_history(chat.id, uid) await bot.delete_user_history(chat.id, uid)
async def check_uid(uid: str): async def check_uid(chat: Chat, uid: str):
channel = False channel = False
try: try:
uid = int(uid) uid = int(uid)
if uid < 0: if uid < 0:
channel = True channel = True
await bot.get_chat(uid) await bot.get_chat_member(chat.id, uid)
except ValueError: except ValueError:
try:
chat = await bot.get_chat(uid) chat = await bot.get_chat(uid)
uid = chat.id uid = chat.id
if chat.type in [ChatType.CHANNEL, ChatType.SUPERGROUP, ChatType.GROUP]: if chat.type in [ChatType.CHANNEL, ChatType.SUPERGROUP, ChatType.GROUP]:
channel = True channel = True
except PeerIdInvalid:
member = await bot.get_chat_member(chat.id, uid)
uid = member.user.id
return uid, channel return uid, channel
async def get_uid(message: Message): async def get_uid(chat: Chat, message: Message):
uid = None uid = None
channel = False channel = False
delete_all = True delete_all = True
sender = None
if reply := message.reply_to_message: if reply := message.reply_to_message:
if sender := reply.from_user: if sender := reply.from_user:
uid = sender.id uid = sender.id
@ -50,21 +55,22 @@ async def get_uid(message: Message):
if message.arguments: if message.arguments:
delete_all = False delete_all = False
elif len(message.parameter) == 2: elif len(message.parameter) == 2:
uid, channel = await check_uid(message.parameter[0]) uid, channel = await check_uid(chat, message.parameter[0])
delete_all = False delete_all = False
elif len(message.parameter) == 1: elif len(message.parameter) == 1:
uid, channel = await check_uid(message.arguments) uid, channel = await check_uid(chat, message.arguments)
return uid, channel, delete_all return uid, channel, delete_all, sender
@listener(command="sb", @listener(command="sb",
description=lang('sb_des'), description=lang('sb_des'),
need_admin=True, need_admin=True,
groups_only=True,
parameters="<reply|id|username> <do_not_del_all>") parameters="<reply|id|username> <do_not_del_all>")
async def super_ban(message: Message): async def super_ban(message: Message):
chat = message.chat chat = message.chat
try: try:
uid, channel, delete_all = await get_uid(message) uid, channel, delete_all, sender = await get_uid(chat, message)
except (ValueError, PeerIdInvalid, UsernameInvalid, FloodWait): except (ValueError, PeerIdInvalid, UsernameInvalid, FloodWait):
return await message.edit(lang("arg_error")) return await message.edit(lang("arg_error"))
if not uid: if not uid:
@ -104,11 +110,13 @@ async def super_ban(message: Message):
groups.append(mention_group(i)) groups.append(mention_group(i))
except Exception: # noqa except Exception: # noqa
pass pass
user = await bot.get_users(uid) if not sender:
member = await bot.get_chat_member(chat.id, uid)
sender = member.user
if count == 0: if count == 0:
text = f'{lang("sb_no")} {user.mention}' text = f'{lang("sb_no")} {sender.mention}'
else: else:
text = f'{lang("sb_per")} {count} {lang("sb_in")} {user.mention}' text = f'{lang("sb_per")} {count} {lang("sb_in")} {sender.mention}'
await message.edit(text) await message.edit(text)
groups = f'\n{lang("sb_pro")}\n' + "\n".join(groups) if groups else '' groups = f'\n{lang("sb_pro")}\n' + "\n".join(groups) if groups else ''
await log(f'{text}\nuid: `{uid}` {groups}') await log(f'{text}\nuid: `{uid}` {groups}')