mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
feat✨: 新增功能ID搜索及修复相关错误
This commit is contained in:
parent
714f5564d0
commit
2a49d86d9f
@ -25,10 +25,14 @@ async def get_plugin_help(name: str, is_superuser: bool) -> str | BuildImage:
|
|||||||
"""获取功能的帮助信息
|
"""获取功能的帮助信息
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
name: 插件名称
|
name: 插件名称或id
|
||||||
is_superuser: 是否为超级用户
|
is_superuser: 是否为超级用户
|
||||||
"""
|
"""
|
||||||
if plugin := await PluginInfo.get_or_none(name__iexact=name):
|
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:
|
||||||
_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:
|
||||||
items = None
|
items = None
|
||||||
@ -45,6 +49,6 @@ async def get_plugin_help(name: str, is_superuser: bool) -> str | BuildImage:
|
|||||||
"用法": _plugin.metadata.usage,
|
"用法": _plugin.metadata.usage,
|
||||||
}
|
}
|
||||||
if items:
|
if items:
|
||||||
return await ImageTemplate.hl_page(name, items)
|
return await ImageTemplate.hl_page(plugin.name, items)
|
||||||
return "糟糕! 该功能没有帮助喔..."
|
return "糟糕! 该功能没有帮助喔..."
|
||||||
return "没有查找到这个功能噢..."
|
return "没有查找到这个功能噢..."
|
||||||
|
|||||||
@ -46,7 +46,9 @@ class HelpImageBuild:
|
|||||||
对插件按照菜单类型分类
|
对插件按照菜单类型分类
|
||||||
"""
|
"""
|
||||||
if not self._data:
|
if not self._data:
|
||||||
self._data = await PluginInfo.filter(plugin_type=PluginType.NORMAL)
|
self._data = await PluginInfo.filter(
|
||||||
|
plugin_type=PluginType.NORMAL, load_status=True
|
||||||
|
)
|
||||||
if not self._sort_data:
|
if not self._sort_data:
|
||||||
for plugin in self._data:
|
for plugin in self._data:
|
||||||
menu_type = plugin.menu_type or "normal"
|
menu_type = plugin.menu_type or "normal"
|
||||||
@ -143,18 +145,19 @@ class HelpImageBuild:
|
|||||||
await self.sort_type()
|
await self.sort_type()
|
||||||
font_size = 24
|
font_size = 24
|
||||||
build_type = Config.get_config("help", "TYPE")
|
build_type = Config.get_config("help", "TYPE")
|
||||||
_image = BuildImage.build_text_image("1", size=font_size)
|
|
||||||
font = BuildImage.load_font("HYWenHei-85W.ttf", 20)
|
font = BuildImage.load_font("HYWenHei-85W.ttf", 20)
|
||||||
for idx, menu_type in enumerate(self._sort_data.keys()):
|
for idx, menu_type in enumerate(self._sort_data.keys()):
|
||||||
plugin_list = self._sort_data[menu_type]
|
plugin_list = self._sort_data[menu_type]
|
||||||
wh_list = [BuildImage.get_text_size(x.name, font) for x in plugin_list]
|
wh_list = [
|
||||||
|
BuildImage.get_text_size(f"{x.id}.{x.name}", font) for x in plugin_list
|
||||||
|
]
|
||||||
wh_list.append(BuildImage.get_text_size(menu_type, font))
|
wh_list.append(BuildImage.get_text_size(menu_type, font))
|
||||||
# sum_height = sum([x[1] for x in wh_list])
|
# sum_height = sum([x[1] for x in wh_list])
|
||||||
if build_type == "VV":
|
if build_type == "VV":
|
||||||
sum_height = 50 * len(plugin_list) + 10
|
sum_height = 50 * len(plugin_list) + 10
|
||||||
else:
|
else:
|
||||||
sum_height = (font_size + 6) * len(plugin_list) + 10
|
sum_height = (font_size + 6) * len(plugin_list) + 10
|
||||||
max_width = max([x[0] for x in wh_list]) + 20
|
max_width = max([x[0] for x in wh_list]) + 30
|
||||||
bk = BuildImage(
|
bk = BuildImage(
|
||||||
max_width + 40,
|
max_width + 40,
|
||||||
sum_height + 50,
|
sum_height + 50,
|
||||||
@ -199,7 +202,7 @@ class HelpImageBuild:
|
|||||||
await B.paste(name_image, (0, curr_h), center_type="width")
|
await B.paste(name_image, (0, curr_h), center_type="width")
|
||||||
curr_h += name_image.h + 5
|
curr_h += name_image.h + 5
|
||||||
else:
|
else:
|
||||||
await B.text((10, curr_h), f"{i + 1}.{plugin.name}", text_color)
|
await B.text((10, curr_h), f"{plugin.id}.{plugin.name}", text_color)
|
||||||
if pos:
|
if pos:
|
||||||
await B.line(pos, (236, 66, 7), 3)
|
await B.line(pos, (236, 66, 7), 3)
|
||||||
curr_h += font_size + 5
|
curr_h += font_size + 5
|
||||||
@ -221,7 +224,7 @@ class HelpImageBuild:
|
|||||||
h = 10
|
h = 10
|
||||||
for msg in [
|
for msg in [
|
||||||
"目前支持的功能列表:",
|
"目前支持的功能列表:",
|
||||||
"可以通过 ‘帮助[功能名称]’ 来获取对应功能的使用方法",
|
"可以通过 ‘帮助 [功能名称或功能Id]’ 来获取对应功能的使用方法",
|
||||||
]:
|
]:
|
||||||
text = await BuildImage.build_text_image(msg, "HYWenHei-85W.ttf", 24)
|
text = await BuildImage.build_text_image(msg, "HYWenHei-85W.ttf", 24)
|
||||||
await B.paste(text, (w, h))
|
await B.paste(text, (w, h))
|
||||||
|
|||||||
@ -101,9 +101,11 @@ async def _():
|
|||||||
limit_list: list[PluginLimit] = []
|
limit_list: list[PluginLimit] = []
|
||||||
task_list: list[TaskInfo] = []
|
task_list: list[TaskInfo] = []
|
||||||
module2id = {}
|
module2id = {}
|
||||||
|
load_plugin = []
|
||||||
if module_list := await PluginInfo.all().values("id", "module_path"):
|
if module_list := await PluginInfo.all().values("id", "module_path"):
|
||||||
module2id = {m["module_path"]: m["id"] for m in module_list}
|
module2id = {m["module_path"]: m["id"] for m in module_list}
|
||||||
for plugin in get_loaded_plugins():
|
for plugin in get_loaded_plugins():
|
||||||
|
load_plugin.append(plugin.name)
|
||||||
if plugin.metadata:
|
if plugin.metadata:
|
||||||
await _handle_setting(plugin, plugin_list, limit_list, task_list)
|
await _handle_setting(plugin, plugin_list, limit_list, task_list)
|
||||||
create_list = []
|
create_list = []
|
||||||
@ -160,6 +162,7 @@ async def _():
|
|||||||
10,
|
10,
|
||||||
)
|
)
|
||||||
await data_migration()
|
await data_migration()
|
||||||
|
await PluginInfo.filter(module__not_in=load_plugin).update(load_status=False)
|
||||||
|
|
||||||
|
|
||||||
async def data_migration():
|
async def data_migration():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user