mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
⚡️优化ban插件
This commit is contained in:
parent
3eb107a79d
commit
ecc8ec3fd8
@ -30,12 +30,12 @@ __plugin_meta__ = PluginMetadata(
|
||||
usage="""
|
||||
普通管理员
|
||||
格式:
|
||||
ban [At用户] [时长(分钟)]
|
||||
ban [At用户] -t [时长(分钟)]
|
||||
|
||||
示例:
|
||||
ban @用户 : 永久拉黑用户
|
||||
ban @用户 100 : 拉黑用户100分钟
|
||||
unban @用户 : 从小黑屋中拉出来
|
||||
ban @用户 : 永久拉黑用户
|
||||
ban @用户 -t 100 : 拉黑用户100分钟
|
||||
unban @用户 : 从小黑屋中拉出来
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="HibiKier",
|
||||
@ -46,15 +46,23 @@ __plugin_meta__ = PluginMetadata(
|
||||
格式:
|
||||
ban [At用户/用户Id] [时长]
|
||||
ban列表: 获取所有Ban数据
|
||||
|
||||
群组ban列表: 获取群组Ban数据
|
||||
用户ban列表: 获取用户Ban数据
|
||||
|
||||
ban列表 -u [用户Id]: 查找指定用户ban数据
|
||||
ban列表 -g [群组Id]: 查找指定群组ban数据
|
||||
示例:
|
||||
ban列表 -u 123456789 : 查找用户123456789的ban数据
|
||||
ban列表 -g 123456789 : 查找群组123456789的ban数据
|
||||
|
||||
私聊下:
|
||||
示例:
|
||||
ban 123456789 : 永久拉黑用户123456789
|
||||
ban 123456789 100 : 拉黑用户123456789 100分钟
|
||||
ban 123456789 : 永久拉黑用户123456789
|
||||
ban 123456789 -t 100 : 拉黑用户123456789 100分钟
|
||||
|
||||
ban -g 999999 : 拉黑群组为999999的群组
|
||||
ban -g 999999 : 拉黑群组为999999的群组
|
||||
ban -g 999999 -t 100 : 拉黑群组为999999的群组 100分钟
|
||||
|
||||
unban 123456789 : 从小黑屋中拉出来
|
||||
unban -g 999999 : 将群组9999999从小黑屋中拉出来
|
||||
@ -76,8 +84,9 @@ __plugin_meta__ = PluginMetadata(
|
||||
_ban_matcher = on_alconna(
|
||||
Alconna(
|
||||
"ban",
|
||||
Args["user?", [str, At]]["duration?", int],
|
||||
Args["user?", [str, At]],
|
||||
Option("-g|--group", Args["group_id", str]),
|
||||
Option("-t|--time", Args["duration", int]),
|
||||
),
|
||||
rule=admin_check("ban", "BAN_LEVEL"),
|
||||
priority=5,
|
||||
@ -97,33 +106,27 @@ _unban_matcher = on_alconna(
|
||||
|
||||
_status_matcher = on_alconna(
|
||||
Alconna(
|
||||
"ban-status",
|
||||
Option("-u|--user", action=store_true, help_text="过滤用户"),
|
||||
Option("-g|--group", action=store_true, help_text="过滤群组"),
|
||||
"ban列表",
|
||||
Option("-u", Args["user_id", str], help_text="查找用户"),
|
||||
Option("-g", Args["group_id", str], help_text="查找群组"),
|
||||
Option("--user", action=store_true, help_text="过滤用户"),
|
||||
Option("--group", action=store_true, help_text="过滤群组"),
|
||||
),
|
||||
permission=SUPERUSER,
|
||||
priority=1,
|
||||
block=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
"ban列表",
|
||||
command="ban-status",
|
||||
arguments=[],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
|
||||
_status_matcher.shortcut(
|
||||
"用户ban列表",
|
||||
command="ban-status",
|
||||
command="ban列表",
|
||||
arguments=["--user"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
"群组ban列表",
|
||||
command="ban-status",
|
||||
command="ban列表",
|
||||
arguments=["--group"],
|
||||
prefix=True,
|
||||
)
|
||||
@ -131,8 +134,6 @@ _status_matcher.shortcut(
|
||||
|
||||
@_status_matcher.handle()
|
||||
async def _(
|
||||
bot: Bot,
|
||||
session: EventSession,
|
||||
arparma: Arparma,
|
||||
user_id: Match[str],
|
||||
group_id: Match[str],
|
||||
@ -144,7 +145,7 @@ async def _(
|
||||
filter_type = "group"
|
||||
_user_id = user_id.result if user_id.available else None
|
||||
_group_id = group_id.result if group_id.available else None
|
||||
if image := await BanManage.build_ban_image(filter_type):
|
||||
if image := await BanManage.build_ban_image(filter_type, _user_id, _group_id):
|
||||
await Image(image.pic2bytes()).finish(reply=True)
|
||||
else:
|
||||
await Text("数据为空捏...").finish(reply=True)
|
||||
@ -164,9 +165,11 @@ async def _(
|
||||
if isinstance(user.result, At):
|
||||
user_id = user.result.target
|
||||
else:
|
||||
if session.id1 not in bot.config.superusers:
|
||||
await Text("权限不足捏...").finish(reply=True)
|
||||
user_id = user.result
|
||||
_duration = duration.result * 60 if duration.available else -1
|
||||
if gid := session.id3 or session.id2:
|
||||
if (gid := session.id3 or session.id2) and not group_id.available:
|
||||
if group_id.available:
|
||||
gid = group_id.result
|
||||
await BanManage.ban(
|
||||
@ -181,7 +184,7 @@ async def _(
|
||||
await MessageFactory(
|
||||
[
|
||||
Text("对 "),
|
||||
Mention(user_id), # type: ignore
|
||||
Mention(user_id) if isinstance(user.result, At) else Text(user_id), # type: ignore
|
||||
Text(f" 狠狠惩戒了一番,一脚踢进了小黑屋!"),
|
||||
]
|
||||
).finish(reply=True)
|
||||
@ -211,34 +214,40 @@ async def _(
|
||||
if isinstance(user.result, At):
|
||||
user_id = user.result.target
|
||||
else:
|
||||
if session.id1 not in bot.config.superusers:
|
||||
await Text("权限不足捏...").finish(reply=True)
|
||||
user_id = user.result
|
||||
if gid := session.id3 or session.id2:
|
||||
if group_id.available:
|
||||
gid = group_id.result
|
||||
await BanManage.unban(
|
||||
if await BanManage.unban(
|
||||
user_id, gid, session, session.id1 in bot.config.superusers
|
||||
)
|
||||
logger.info(
|
||||
f"管理员UnBan",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
target=f"{gid}:{user_id}",
|
||||
)
|
||||
await MessageFactory(
|
||||
[
|
||||
Text("将 "),
|
||||
Mention(user_id), # type: ignore
|
||||
Text(f" 从黑屋中拉了出来并急救了一下!"),
|
||||
]
|
||||
).finish(reply=True)
|
||||
):
|
||||
logger.info(
|
||||
f"管理员UnBan",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
target=f"{gid}:{user_id}",
|
||||
)
|
||||
await MessageFactory(
|
||||
[
|
||||
Text("将 "),
|
||||
Mention(user_id) if isinstance(user.result, At) else Text(user_id), # type: ignore
|
||||
Text(f" 从黑屋中拉了出来并急救了一下!"),
|
||||
]
|
||||
).finish(reply=True)
|
||||
else:
|
||||
await Text(f"该用户不在黑名单中捏...").finish(reply=True)
|
||||
elif session.id1 in bot.config.superusers:
|
||||
_group_id = group_id.result if group_id.available else None
|
||||
await BanManage.unban(user_id, _group_id, session, True)
|
||||
logger.info(
|
||||
f"超级用户UnBan",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
target=f"{_group_id}:{user_id}",
|
||||
)
|
||||
at_msg = user_id if user_id else f"群组:{_group_id}"
|
||||
await Text(f"对 {at_msg} 从黑屋中拉了出来并急救了一下!").finish(reply=True)
|
||||
if await BanManage.unban(user_id, _group_id, session, True):
|
||||
logger.info(
|
||||
f"超级用户UnBan",
|
||||
arparma.header_result,
|
||||
session=session,
|
||||
target=f"{_group_id}:{user_id}",
|
||||
)
|
||||
at_msg = user_id if user_id else f"群组:{_group_id}"
|
||||
await Text(f"对 {at_msg} 从黑屋中拉了出来并急救了一下!").finish(reply=True)
|
||||
else:
|
||||
await Text(f"该用户不在黑名单中捏...").finish(reply=True)
|
||||
|
||||
@ -14,22 +14,31 @@ class BanManage:
|
||||
async def build_ban_image(
|
||||
cls,
|
||||
filter_type: Literal["group", "user"] | None,
|
||||
user_id: str | None = None,
|
||||
group_id: str | None = None,
|
||||
) -> BuildImage | None:
|
||||
"""构造Ban列表图片
|
||||
|
||||
参数:
|
||||
filter_type: 过滤类型
|
||||
user_id: 用户id
|
||||
group_id: 群组id
|
||||
|
||||
返回:
|
||||
BuildImage | None: Ban列表图片
|
||||
"""
|
||||
data_list = None
|
||||
if not filter_type:
|
||||
data_list = await BanConsole.all()
|
||||
elif filter_type == "user":
|
||||
data_list = await BanConsole.filter(group_id__isnull=True).all()
|
||||
elif filter_type == "group":
|
||||
data_list = await BanConsole.filter(user_id__isnull=True).all()
|
||||
query = BanConsole
|
||||
if user_id:
|
||||
query = query.filter(user_id=user_id)
|
||||
elif group_id:
|
||||
query = query.filter(group_id=group_id)
|
||||
else:
|
||||
if filter_type == "user":
|
||||
query = query.filter(group_id__isnull=True)
|
||||
elif filter_type == "group":
|
||||
query = query.filter(user_id__isnull=True)
|
||||
data_list = await query.all()
|
||||
if not data_list:
|
||||
return None
|
||||
column_name = [
|
||||
|
||||
@ -10,6 +10,7 @@ from nonebot_plugin_session import EventSession
|
||||
from pydantic import BaseModel
|
||||
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.models.ban_console import BanConsole
|
||||
from zhenxun.models.group_console import GroupConsole
|
||||
from zhenxun.models.level_user import LevelUser
|
||||
from zhenxun.models.plugin_info import PluginInfo
|
||||
|
||||
@ -34,6 +34,11 @@ async def _(
|
||||
return
|
||||
user_id = session.id1
|
||||
group_id = session.id3 or session.id2
|
||||
if group_id:
|
||||
if user_id in bot.config.superusers:
|
||||
return
|
||||
if await BanConsole.is_ban(None, group_id):
|
||||
raise IgnoredException("群组处于黑名单中...")
|
||||
if user_id:
|
||||
ban_result = Config.get_config("hook", "BAN_RESULT")
|
||||
if user_id in bot.config.superusers:
|
||||
@ -62,4 +67,4 @@ async def _(
|
||||
Text(f"{ban_result}\n在..在 {time_str} 后才会理你喔"),
|
||||
]
|
||||
).send()
|
||||
raise IgnoredException("用户处于黑名单中")
|
||||
raise IgnoredException("用户处于黑名单中...")
|
||||
|
||||
@ -116,7 +116,7 @@ class BanConsole(Model):
|
||||
if await cls.check_ban_time(user_id, group_id):
|
||||
return True
|
||||
else:
|
||||
if await cls.check_ban_time(user_id):
|
||||
if await cls.check_ban_time(user_id, group_id):
|
||||
return True
|
||||
await cls.unban(user_id, group_id)
|
||||
return False
|
||||
@ -140,7 +140,7 @@ class BanConsole(Model):
|
||||
operator: 操作者id
|
||||
"""
|
||||
logger.debug(
|
||||
f"封禁用户,等级:{ban_level},时长: {duration}",
|
||||
f"封禁用户/群组,等级:{ban_level},时长: {duration}",
|
||||
target=f"{group_id}:{user_id}",
|
||||
)
|
||||
user = await cls._get_data(user_id, group_id)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user