From f6bc6f3481dc91d2f9b67ceafc1d7b07b93f8cb8 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Tue, 27 Feb 2024 16:13:06 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8:=20=E6=B7=BB=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E6=8F=92=E4=BB=B6=E5=B8=AE=E5=8A=A9=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/help/__init__.py | 13 +++++++------ zhenxun/builtin_plugins/help/_data_source.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/zhenxun/builtin_plugins/help/__init__.py b/zhenxun/builtin_plugins/help/__init__.py index 41c190b2..4f2c87a1 100644 --- a/zhenxun/builtin_plugins/help/__init__.py +++ b/zhenxun/builtin_plugins/help/__init__.py @@ -8,6 +8,7 @@ from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH from zhenxun.configs.utils import PluginExtraData, RegisterConfig from zhenxun.services.log import logger from zhenxun.utils.enum import PluginType +from zhenxun.utils.image_utils import BuildImage from ._data_source import create_help_img, get_plugin_help from ._utils import GROUP_HELP_PATH @@ -47,20 +48,20 @@ _matcher = on_alconna( block=True, ) -# TODO: 插件使用详情 图片形式的帮助回复 - @_matcher.handle() async def _( name: Match[str], session: EventSession, ): - if name.available: - if text := await get_plugin_help(name.result): - await Text(text).send(reply=True) + if result := await get_plugin_help(name.result): + if isinstance(result, BuildImage): + await Image(result.pic2bs4()).send(reply=True) + else: + await Text(result).send(reply=True) else: - await Text("没有此功能的帮助信息...").send() + await Text("没有此功能的帮助信息...").send(reply=True) logger.info( f"查看帮助详情: {name.result}", "帮助", diff --git a/zhenxun/builtin_plugins/help/_data_source.py b/zhenxun/builtin_plugins/help/_data_source.py index 75d8b66e..0f6a010f 100644 --- a/zhenxun/builtin_plugins/help/_data_source.py +++ b/zhenxun/builtin_plugins/help/_data_source.py @@ -2,7 +2,7 @@ import nonebot from zhenxun.configs.path_config import IMAGE_PATH from zhenxun.models.plugin_info import PluginInfo -from zhenxun.utils.image_utils import BuildImage +from zhenxun.utils.image_utils import BuildImage, ImageTemplate from ._utils import HelpImageBuild @@ -11,7 +11,7 @@ random_bk_path = IMAGE_PATH / "background" / "help" / "simple_help" background = IMAGE_PATH / "background" / "0.png" -async def create_help_img(group_id: int | None): +async def create_help_img(group_id: str | None): """ 说明: 生成帮助图片 @@ -21,7 +21,7 @@ async def create_help_img(group_id: int | None): await HelpImageBuild().build_image(group_id) -async def get_plugin_help(name: str) -> str: +async def get_plugin_help(name: str) -> str | BuildImage: """获取功能的帮助信息 参数: @@ -30,6 +30,10 @@ async def get_plugin_help(name: str) -> str: if plugin := await PluginInfo.get_or_none(name=name): _plugin = nonebot.get_plugin_by_module_name(plugin.module_path) if _plugin and _plugin.metadata: - return _plugin.metadata.usage + items = { + "简介": _plugin.metadata.description, + "用法": _plugin.metadata.usage, + } + return await ImageTemplate.hl_page(name, items) return "糟糕! 该功能没有帮助喔..." return "没有查找到这个功能噢..."