mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 08:39:59 +08:00
♻️ refactor(plugin_switch): 重构功能开关与帮助系统并优化 UI 报表渲染 (#2111)
* ♻️ 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>
This commit is contained in:
co-authored by
webjoin111
pre-commit-ci[bot]
parent
ce94f63d9a
commit
0f91ce03e4
@@ -2,31 +2,46 @@ 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, ensure_group
|
||||
from zhenxun.utils.rules import admin_check
|
||||
|
||||
_status_matcher = on_alconna(
|
||||
Alconna(
|
||||
"switch",
|
||||
Option("-t|--task", action=store_true, help_text="被动技能"),
|
||||
Option("--task", action=store_true, help_text="被动技能"),
|
||||
Option("-df|--default", action=store_true, help_text="进群默认开关"),
|
||||
Option("--all", action=store_true, help_text="全部插件/被动"),
|
||||
Option("-g|--group", Args["group?", str], 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_name?", [str, int]],
|
||||
Args["plugin_names?", MultiVar(str)],
|
||||
Option(
|
||||
"--type",
|
||||
Args["block_type?", ["all", "a", "private", "p", "group", "g"]],
|
||||
help_text="全局禁用范围",
|
||||
),
|
||||
),
|
||||
Subcommand(
|
||||
"close",
|
||||
Args["plugin_name?", [str, int]],
|
||||
Args["plugin_names?", MultiVar(str)],
|
||||
Option(
|
||||
"-t|--type",
|
||||
"--type",
|
||||
Args["block_type?", ["all", "a", "private", "p", "group", "g"]],
|
||||
help_text="全局禁用范围",
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -36,10 +51,15 @@ _status_matcher = on_alconna(
|
||||
)
|
||||
|
||||
_group_status_matcher = on_alconna(
|
||||
Alconna("group-status", Args["status", ["sleep", "wake"]]),
|
||||
rule=admin_check("plugin_switch", "CHANGE_GROUP_SWITCH_LEVEL")
|
||||
& ensure_group
|
||||
& to_me(),
|
||||
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,
|
||||
)
|
||||
@@ -52,124 +72,42 @@ _status_matcher.shortcut(
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"群被动状态",
|
||||
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,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启(所有|全部)默认群被动",
|
||||
command="switch",
|
||||
arguments=["open", "--task", "--all", "-df"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭(所有|全部)默认群被动",
|
||||
command="switch",
|
||||
arguments=["close", "--task", "--all", "-df"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启群被动\s*(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["open", "{name}", "--task"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭群被动\s*(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["close", "{name}", "--task"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启默认群被动\s*(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["open", "{name}", "--task", "-df"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭默认群被动\s*(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["close", "{name}", "--task", "-df"],
|
||||
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"开启(所有|全部)群被动",
|
||||
command="switch",
|
||||
arguments=["open", "--task", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭(所有|全部)群被动",
|
||||
command="switch",
|
||||
arguments=["close", "--task", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启所有(插件|功能)",
|
||||
command="switch",
|
||||
arguments=["open", "s", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启所有(插件|功能)df",
|
||||
command="switch",
|
||||
arguments=["open", "s", "-df", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启(插件|功能)df(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["open", "{name}", "-df"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"开启(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["open", "{name}"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭所有(插件|功能)",
|
||||
command="switch",
|
||||
arguments=["close", "s", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭所有(插件|功能)df",
|
||||
command="switch",
|
||||
arguments=["close", "s", "-df", "--all"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭(插件|功能)df(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["close", "{name}", "-df"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_status_matcher.shortcut(
|
||||
r"关闭(?P<name>.+)",
|
||||
command="switch",
|
||||
arguments=["close", "{name}"],
|
||||
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,
|
||||
)
|
||||
|
||||
@@ -182,8 +120,15 @@ _group_status_matcher.shortcut(
|
||||
)
|
||||
|
||||
_group_status_matcher.shortcut(
|
||||
r"休息吧",
|
||||
r"休息(吧)?",
|
||||
command="group-status",
|
||||
arguments=["sleep"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
_group_status_matcher.shortcut(
|
||||
r"查看群(状态|信息)",
|
||||
command="group-status",
|
||||
arguments=["check"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user