mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 08:39:59 +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>
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
from collections.abc import Callable
|
|
|
|
from nonebot_plugin_uninfo import Uninfo
|
|
|
|
from zhenxun.models.bot_console import BotConsole
|
|
from zhenxun.models.group_console import GroupConsole
|
|
from zhenxun.models.plugin_info import PluginInfo
|
|
from zhenxun.utils.enum import PluginType
|
|
|
|
|
|
async def sort_type() -> dict[str, list[PluginInfo]]:
|
|
"""
|
|
对插件按照菜单类型分类
|
|
"""
|
|
data = await PluginInfo.filter(
|
|
menu_type__not="",
|
|
load_status=True,
|
|
plugin_type__in=[PluginType.NORMAL, PluginType.DEPENDANT],
|
|
is_show=True,
|
|
)
|
|
sort_data = {}
|
|
for plugin in data:
|
|
menu_type = plugin.menu_type or "normal"
|
|
if menu_type == "normal":
|
|
menu_type = "功能"
|
|
if not sort_data.get(menu_type):
|
|
sort_data[menu_type] = []
|
|
sort_data[menu_type].append(plugin)
|
|
return sort_data
|
|
|
|
|
|
async def classify_plugin(
|
|
session: Uninfo, group_id: str | None, is_detail: bool, handle: Callable
|
|
) -> dict[str, list]:
|
|
"""对插件进行分类并判断状态
|
|
|
|
参数:
|
|
session: Uninfo对象
|
|
group_id: 群组id
|
|
is_detail: 是否详细帮助
|
|
handle: 回调方法
|
|
|
|
返回:
|
|
dict[str, list[Item]]: 分类插件数据
|
|
"""
|
|
sort_data = await sort_type()
|
|
classify: dict[str, list] = {}
|
|
group = await GroupConsole.get_group(group_id=group_id) if group_id else None
|
|
bot = await BotConsole.get_or_none(bot_id=session.self_id)
|
|
for menu, value in sort_data.items():
|
|
for plugin in value:
|
|
if not classify.get(menu):
|
|
classify[menu] = []
|
|
classify[menu].append(handle(bot, plugin, group, is_detail))
|
|
for value in classify.values():
|
|
value.sort(key=lambda x: int(x["id"]))
|
|
return classify
|