From 454d80fc3f33634713a084f0c57385251f470231 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Mon, 14 Jul 2025 17:16:23 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BC=98=E5=8C=96=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=88=86=E7=B1=BB=E9=80=BB=E8=BE=91=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8F=92=E4=BB=B6ID=E6=8E=92=E5=BA=8F=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/help/_utils.py | 2 + zhenxun/builtin_plugins/help/html_help.py | 11 ++-- zhenxun/builtin_plugins/help/zhenxun_help.py | 64 +------------------- 3 files changed, 11 insertions(+), 66 deletions(-) diff --git a/zhenxun/builtin_plugins/help/_utils.py b/zhenxun/builtin_plugins/help/_utils.py index 4d256dc0..d17edcda 100644 --- a/zhenxun/builtin_plugins/help/_utils.py +++ b/zhenxun/builtin_plugins/help/_utils.py @@ -52,4 +52,6 @@ async def classify_plugin( 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: x.id) return classify diff --git a/zhenxun/builtin_plugins/help/html_help.py b/zhenxun/builtin_plugins/help/html_help.py index 7c552a0d..dec0a835 100644 --- a/zhenxun/builtin_plugins/help/html_help.py +++ b/zhenxun/builtin_plugins/help/html_help.py @@ -21,6 +21,8 @@ class Item(BaseModel): """插件名称""" sta: int """插件状态""" + id: int + """插件id""" class PluginList(BaseModel): @@ -80,10 +82,9 @@ def __handle_item( sta = 2 if f"{plugin.module}," in group.block_plugin: sta = 1 - if bot: - if f"{plugin.module}," in bot.block_plugins: - sta = 2 - return Item(plugin_name=plugin.name, sta=sta) + if bot and f"{plugin.module}," in bot.block_plugins: + sta = 2 + return Item(plugin_name=plugin.name, sta=sta, id=plugin.id) def build_plugin_data(classify: dict[str, list[Item]]) -> list[dict[str, str]]: @@ -142,7 +143,7 @@ async def build_html_image( template_name="zhenxun_menu.html", templates={"plugin_list": plugin_list}, pages={ - "viewport": {"width": 1903, "height": 975}, + "viewport": {"width": 1903, "height": 10}, "base_url": f"file://{TEMPLATE_PATH}", }, wait=2, diff --git a/zhenxun/builtin_plugins/help/zhenxun_help.py b/zhenxun/builtin_plugins/help/zhenxun_help.py index afece6bd..ea04bdc0 100644 --- a/zhenxun/builtin_plugins/help/zhenxun_help.py +++ b/zhenxun/builtin_plugins/help/zhenxun_help.py @@ -97,68 +97,10 @@ def build_plugin_data(classify: dict[str, list[Item]]) -> list[dict[str, str]]: } for menu, value in classify.items() ] - plugin_list = build_line_data(plugin_list) - plugin_list.insert( - 0, - build_plugin_line( - menu_key if menu_key not in ["normal", "功能"] else "主要功能", - max_data, - 30, - 100, - True, - ), - ) - return plugin_list - - -def build_plugin_line( - name: str, items: list, left: int, width: int | None = None, is_max: bool = False -) -> dict: - """构造插件行数据 - - 参数: - name: 菜单名称 - items: 插件名称列表 - left: 左边距 - width: 总插件长度. - is_max: 是否为最大长度的插件菜单 - - 返回: - dict: 插件数据 - """ - _plugins = [] - width = width or 50 - if len(items) // 2 > 6 or is_max: - width = 100 - plugin_list1 = [] - plugin_list2 = [] - for i in range(len(items)): - if i % 2: - plugin_list1.append(items[i]) - else: - plugin_list2.append(items[i]) - _plugins = [(30, 50, plugin_list1), (0, 50, plugin_list2)] - else: - _plugins = [(left, 100, items)] - return {"name": name, "items": _plugins, "width": width} - - -def build_line_data(plugin_list: list[dict]) -> list[dict]: - """构造插件数据 - - 参数: - plugin_list: 插件列表 - - 返回: - list[dict]: 插件数据 - """ - left = 30 - data = [] + plugin_list.insert(0, {"name": menu_key, "items": max_data}) for plugin in plugin_list: - data.append(build_plugin_line(plugin["name"], plugin["items"], left)) - if len(plugin["items"]) // 2 <= 6: - left = 15 if left == 30 else 30 - return data + plugin["items"].sort(key=lambda x: x.id) + return plugin_list async def build_zhenxun_image(