2024-09-14 05:23:55 +08:00
|
|
|
from collections.abc import Callable
|
2024-08-28 19:08:22 +08:00
|
|
|
|
2025-05-15 23:52:20 +08:00
|
|
|
from nonebot_plugin_uninfo import Uninfo
|
|
|
|
|
|
|
|
|
|
from zhenxun.models.bot_console import BotConsole
|
2024-08-28 19:08:22 +08:00
|
|
|
from zhenxun.models.group_console import GroupConsole
|
2024-12-10 19:49:11 +08:00
|
|
|
from zhenxun.models.plugin_info import PluginInfo
|
|
|
|
|
from zhenxun.utils.enum import PluginType
|
2024-07-31 19:10:31 +08:00
|
|
|
|
|
|
|
|
|
2024-09-14 05:23:55 +08:00
|
|
|
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],
|
2024-11-29 10:01:50 +08:00
|
|
|
is_show=True,
|
2024-09-14 05:23:55 +08:00
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2025-01-10 18:39:23 +08:00
|
|
|
async def classify_plugin(
|
2025-05-15 23:52:20 +08:00
|
|
|
session: Uninfo, group_id: str | None, is_detail: bool, handle: Callable
|
2025-01-10 18:39:23 +08:00
|
|
|
) -> dict[str, list]:
|
2024-09-14 05:23:55 +08:00
|
|
|
"""对插件进行分类并判断状态
|
|
|
|
|
|
|
|
|
|
参数:
|
2025-05-15 23:52:20 +08:00
|
|
|
session: Uninfo对象
|
2024-09-14 05:23:55 +08:00
|
|
|
group_id: 群组id
|
2025-01-10 18:39:23 +08:00
|
|
|
is_detail: 是否详细帮助
|
2025-05-15 23:52:20 +08:00
|
|
|
handle: 回调方法
|
2024-09-14 05:23:55 +08:00
|
|
|
|
|
|
|
|
返回:
|
|
|
|
|
dict[str, list[Item]]: 分类插件数据
|
|
|
|
|
"""
|
|
|
|
|
sort_data = await sort_type()
|
|
|
|
|
classify: dict[str, list] = {}
|
2025-07-14 22:35:29 +08:00
|
|
|
group = await GroupConsole.get_group(group_id=group_id) if group_id else None
|
2025-05-15 23:52:20 +08:00
|
|
|
bot = await BotConsole.get_or_none(bot_id=session.self_id)
|
2024-09-14 05:23:55 +08:00
|
|
|
for menu, value in sort_data.items():
|
|
|
|
|
for plugin in value:
|
|
|
|
|
if not classify.get(menu):
|
|
|
|
|
classify[menu] = []
|
2025-05-15 23:52:20 +08:00
|
|
|
classify[menu].append(handle(bot, plugin, group, is_detail))
|
2025-07-14 22:35:29 +08:00
|
|
|
for value in classify.values():
|
2025-08-15 16:34:37 +08:00
|
|
|
value.sort(key=lambda x: int(x["id"]))
|
2024-09-14 05:23:55 +08:00
|
|
|
return classify
|