mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-30 01:00:02 +08:00
* ♻️ refactor(plugin_switch): 重构功能开关与帮助系统并优化 UI 报表渲染 - 引入策略模式 (Strategy Pattern) 统一插件与被动任务的开关逻辑 - 新增超级用户强制管控功能,支持系统级禁用且群管无法自行开启 - 新增全服群组活跃状态报表与功能全局覆盖率可视化统计图表 - 优化指令解析系统,支持多功能批量开关及更智能的快捷词映射 - 重构帮助系统,支持在帮助页区分展示管理员与超级用户指令 - 细化插件列表状态显示,区分群控、系统管控与全局禁用状态 - UI 组件 UserInfoBlock 新增 extra 扩展插槽支持 - 更新 resources.spec 资源版本要求至 1.1.1 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
135 lines
3.8 KiB
Python
135 lines
3.8 KiB
Python
from nonebot.rule import to_me
|
|
from nonebot_plugin_alconna import (
|
|
Alconna,
|
|
Args,
|
|
MultiVar,
|
|
Option,
|
|
Subcommand,
|
|
on_alconna,
|
|
store_true,
|
|
)
|
|
|
|
from zhenxun.utils.rules import admin_check
|
|
|
|
_status_matcher = on_alconna(
|
|
Alconna(
|
|
"switch",
|
|
Option("--task", action=store_true, help_text="被动技能"),
|
|
Option("-df|--default", action=store_true, help_text="进群默认开关"),
|
|
Option("--all-plugins", action=store_true, help_text="所有插件/功能"),
|
|
Option("--all", action=store_true, help_text="所有群组 (超级用户专用)"),
|
|
Option("-g|--group", Args["groups", MultiVar(str)], help_text="指定群组"),
|
|
Option("-t|--tag", Args["tag", str], help_text="指定标签"),
|
|
Option("-o|--only", action=store_true, help_text="白名单模式(仅在目标群开启)"),
|
|
Option("-s|--su", action=store_true, help_text="操作超级用户专用字段"),
|
|
Subcommand(
|
|
"check",
|
|
Args["plugin_name", [str, int]],
|
|
),
|
|
Subcommand(
|
|
"open",
|
|
Args["plugin_names?", MultiVar(str)],
|
|
Option(
|
|
"--type",
|
|
Args["block_type?", ["all", "a", "private", "p", "group", "g"]],
|
|
help_text="全局禁用范围",
|
|
),
|
|
),
|
|
Subcommand(
|
|
"close",
|
|
Args["plugin_names?", MultiVar(str)],
|
|
Option(
|
|
"--type",
|
|
Args["block_type?", ["all", "a", "private", "p", "group", "g"]],
|
|
help_text="全局禁用范围",
|
|
),
|
|
),
|
|
),
|
|
rule=admin_check("plugin_switch", "CHANGE_GROUP_SWITCH_LEVEL"),
|
|
priority=5,
|
|
block=True,
|
|
)
|
|
|
|
_group_status_matcher = on_alconna(
|
|
Alconna(
|
|
"group-status",
|
|
Args["status", ["sleep", "wake", "check"]],
|
|
Option("-g|--group", Args["groups", MultiVar(str)], help_text="指定群组"),
|
|
Option("-t|--tag", Args["tag", str], help_text="指定标签"),
|
|
Option("--all", action=store_true, help_text="所有群组"),
|
|
Option("-o|--only", action=store_true, help_text="白名单模式(仅在目标群醒来)"),
|
|
),
|
|
rule=admin_check("plugin_switch", "CHANGE_GROUP_SWITCH_LEVEL") & to_me(),
|
|
priority=5,
|
|
block=True,
|
|
)
|
|
|
|
_status_matcher.shortcut(
|
|
r"插件列表",
|
|
command="switch",
|
|
arguments=[],
|
|
prefix=True,
|
|
)
|
|
|
|
_status_matcher.shortcut(
|
|
r"查看(功能|插件)?状态",
|
|
command="switch check {*}",
|
|
prefix=True,
|
|
)
|
|
|
|
_status_matcher.shortcut(
|
|
r"查看(群)?被动状态",
|
|
command="switch check {*} --task",
|
|
prefix=True,
|
|
)
|
|
|
|
_status_matcher.shortcut(
|
|
r"(群)?被动状态",
|
|
command="switch",
|
|
arguments=["--task"],
|
|
prefix=True,
|
|
)
|
|
|
|
|
|
def _switch_wrapper(slot: str, content: str | None, context: dict) -> str:
|
|
"""动态映射转换函数"""
|
|
if slot == "action":
|
|
return "open" if content == "开启" else "close"
|
|
if slot == "all" and content:
|
|
return "--all-plugins"
|
|
if slot == "default" and content:
|
|
return "-df"
|
|
if slot == "type" and content:
|
|
return "--task" if "被动" in content else ""
|
|
return ""
|
|
|
|
|
|
_status_matcher.shortcut(
|
|
r"^(?P<action>开启|关闭)\s*(?P<all>所有|全部)?\s*(?P<default>默认)?\s*(?P<type>群被动|被动|插件|功能)?\s*",
|
|
command="switch {all} {default} {type} {action} {* }",
|
|
wrapper=_switch_wrapper, # type: ignore
|
|
prefix=True,
|
|
)
|
|
|
|
|
|
_group_status_matcher.shortcut(
|
|
r"醒来",
|
|
command="group-status",
|
|
arguments=["wake"],
|
|
prefix=True,
|
|
)
|
|
|
|
_group_status_matcher.shortcut(
|
|
r"休息(吧)?",
|
|
command="group-status",
|
|
arguments=["sleep"],
|
|
prefix=True,
|
|
)
|
|
|
|
_group_status_matcher.shortcut(
|
|
r"查看群(状态|信息)",
|
|
command="group-status",
|
|
arguments=["check"],
|
|
prefix=True,
|
|
)
|