mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
feat✨: 添加单个插件帮助图片
This commit is contained in:
parent
993ff81130
commit
f6bc6f3481
@ -8,6 +8,7 @@ from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH
|
|||||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils.enum import PluginType
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.image_utils import BuildImage
|
||||||
|
|
||||||
from ._data_source import create_help_img, get_plugin_help
|
from ._data_source import create_help_img, get_plugin_help
|
||||||
from ._utils import GROUP_HELP_PATH
|
from ._utils import GROUP_HELP_PATH
|
||||||
@ -47,20 +48,20 @@ _matcher = on_alconna(
|
|||||||
block=True,
|
block=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: 插件使用详情 图片形式的帮助回复
|
|
||||||
|
|
||||||
|
|
||||||
@_matcher.handle()
|
@_matcher.handle()
|
||||||
async def _(
|
async def _(
|
||||||
name: Match[str],
|
name: Match[str],
|
||||||
session: EventSession,
|
session: EventSession,
|
||||||
):
|
):
|
||||||
|
|
||||||
if name.available:
|
if name.available:
|
||||||
if text := await get_plugin_help(name.result):
|
if result := await get_plugin_help(name.result):
|
||||||
await Text(text).send(reply=True)
|
if isinstance(result, BuildImage):
|
||||||
|
await Image(result.pic2bs4()).send(reply=True)
|
||||||
|
else:
|
||||||
|
await Text(result).send(reply=True)
|
||||||
else:
|
else:
|
||||||
await Text("没有此功能的帮助信息...").send()
|
await Text("没有此功能的帮助信息...").send(reply=True)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"查看帮助详情: {name.result}",
|
f"查看帮助详情: {name.result}",
|
||||||
"帮助",
|
"帮助",
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import nonebot
|
|||||||
|
|
||||||
from zhenxun.configs.path_config import IMAGE_PATH
|
from zhenxun.configs.path_config import IMAGE_PATH
|
||||||
from zhenxun.models.plugin_info import PluginInfo
|
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
|
from ._utils import HelpImageBuild
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ random_bk_path = IMAGE_PATH / "background" / "help" / "simple_help"
|
|||||||
background = IMAGE_PATH / "background" / "0.png"
|
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)
|
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):
|
if plugin := await PluginInfo.get_or_none(name=name):
|
||||||
_plugin = nonebot.get_plugin_by_module_name(plugin.module_path)
|
_plugin = nonebot.get_plugin_by_module_name(plugin.module_path)
|
||||||
if _plugin and _plugin.metadata:
|
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 "糟糕! 该功能没有帮助喔..."
|
||||||
return "没有查找到这个功能噢..."
|
return "没有查找到这个功能噢..."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user