2024-02-25 03:18:34 +08:00
|
|
|
import nonebot
|
|
|
|
|
|
|
|
|
|
from zhenxun.models.plugin_info import PluginInfo
|
2024-08-28 19:08:22 +08:00
|
|
|
from zhenxun.configs.path_config import IMAGE_PATH
|
2024-02-27 16:13:06 +08:00
|
|
|
from zhenxun.utils.image_utils import BuildImage, ImageTemplate
|
2024-02-25 03:18:34 +08:00
|
|
|
|
|
|
|
|
from ._utils import HelpImageBuild
|
|
|
|
|
|
|
|
|
|
random_bk_path = IMAGE_PATH / "background" / "help" / "simple_help"
|
|
|
|
|
|
|
|
|
|
background = IMAGE_PATH / "background" / "0.png"
|
|
|
|
|
|
|
|
|
|
|
2024-08-28 19:08:22 +08:00
|
|
|
async def create_help_img(bot_id: str, group_id: str | None):
|
|
|
|
|
"""生成帮助图片
|
|
|
|
|
|
2024-02-25 03:18:34 +08:00
|
|
|
参数:
|
2024-08-28 19:08:22 +08:00
|
|
|
bot_id: bot id
|
|
|
|
|
group_id: 群号
|
2024-02-25 03:18:34 +08:00
|
|
|
"""
|
2024-08-28 19:08:22 +08:00
|
|
|
await HelpImageBuild().build_image(bot_id, group_id)
|
2024-02-25 03:18:34 +08:00
|
|
|
|
|
|
|
|
|
2024-05-15 23:24:35 +08:00
|
|
|
async def get_plugin_help(name: str, is_superuser: bool) -> str | BuildImage:
|
2024-02-25 03:18:34 +08:00
|
|
|
"""获取功能的帮助信息
|
|
|
|
|
|
|
|
|
|
参数:
|
2024-07-31 18:34:22 +08:00
|
|
|
name: 插件名称或id
|
2024-05-15 23:24:35 +08:00
|
|
|
is_superuser: 是否为超级用户
|
2024-02-25 03:18:34 +08:00
|
|
|
"""
|
2024-07-31 18:34:22 +08:00
|
|
|
if name.isdigit():
|
|
|
|
|
plugin = await PluginInfo.get_or_none(id=int(name), load_status=True)
|
|
|
|
|
else:
|
|
|
|
|
plugin = await PluginInfo.get_or_none(name__iexact=name, load_status=True)
|
|
|
|
|
if plugin:
|
2024-02-25 03:18:34 +08:00
|
|
|
_plugin = nonebot.get_plugin_by_module_name(plugin.module_path)
|
|
|
|
|
if _plugin and _plugin.metadata:
|
2024-05-15 23:24:35 +08:00
|
|
|
items = None
|
|
|
|
|
if is_superuser:
|
|
|
|
|
extra = _plugin.metadata.extra
|
|
|
|
|
if usage := extra.get("superuser_help"):
|
|
|
|
|
items = {
|
|
|
|
|
"简介": _plugin.metadata.description,
|
|
|
|
|
"用法": usage,
|
|
|
|
|
}
|
|
|
|
|
else:
|
|
|
|
|
items = {
|
|
|
|
|
"简介": _plugin.metadata.description,
|
|
|
|
|
"用法": _plugin.metadata.usage,
|
|
|
|
|
}
|
|
|
|
|
if items:
|
2024-07-31 18:34:22 +08:00
|
|
|
return await ImageTemplate.hl_page(plugin.name, items)
|
2024-02-25 03:18:34 +08:00
|
|
|
return "糟糕! 该功能没有帮助喔..."
|
|
|
|
|
return "没有查找到这个功能噢..."
|