mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 22:00:01 +08:00
feat✨: 画廊操作
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from pathlib import Path
|
||||
from nonebot.adapters import Bot
|
||||
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import Alconna, Args, Match, on_alconna
|
||||
from nonebot_plugin_alconna import Alconna, AlconnaQuery, Args, Match, Option, Query, on_alconna, store_true
|
||||
from nonebot_plugin_saa import Image, Text
|
||||
from nonebot_plugin_session import EventSession
|
||||
|
||||
@@ -43,6 +44,7 @@ _matcher = on_alconna(
|
||||
Alconna(
|
||||
"功能",
|
||||
Args["name?", str],
|
||||
Option("-s|--superuser", action=store_true, help_text="超级用户帮助")
|
||||
),
|
||||
aliases={"help", "帮助"},
|
||||
rule=to_me(),
|
||||
@@ -53,11 +55,18 @@ _matcher = on_alconna(
|
||||
|
||||
@_matcher.handle()
|
||||
async def _(
|
||||
bot: Bot,
|
||||
name: Match[str],
|
||||
session: EventSession,
|
||||
is_superuser: Query[bool] = AlconnaQuery("superuser.value", False)
|
||||
):
|
||||
_is_superuser = False
|
||||
if is_superuser.available:
|
||||
_is_superuser = is_superuser.result
|
||||
if name.available:
|
||||
if result := await get_plugin_help(name.result):
|
||||
if _is_superuser and session.id1 not in bot.config.superusers:
|
||||
_is_superuser = False
|
||||
if result := await get_plugin_help(name.result, _is_superuser):
|
||||
if isinstance(result, BuildImage):
|
||||
await Image(result.pic2bytes()).send(reply=True)
|
||||
else:
|
||||
|
||||
@@ -21,19 +21,30 @@ async def create_help_img(group_id: str | None):
|
||||
await HelpImageBuild().build_image(group_id)
|
||||
|
||||
|
||||
async def get_plugin_help(name: str) -> str | BuildImage:
|
||||
async def get_plugin_help(name: str, is_superuser: bool) -> str | BuildImage:
|
||||
"""获取功能的帮助信息
|
||||
|
||||
参数:
|
||||
name: 插件名称
|
||||
is_superuser: 是否为超级用户
|
||||
"""
|
||||
if plugin := await PluginInfo.get_or_none(name=name):
|
||||
if plugin := await PluginInfo.get_or_none(name__iexact=name):
|
||||
_plugin = nonebot.get_plugin_by_module_name(plugin.module_path)
|
||||
if _plugin and _plugin.metadata:
|
||||
items = {
|
||||
"简介": _plugin.metadata.description,
|
||||
"用法": _plugin.metadata.usage,
|
||||
}
|
||||
return await ImageTemplate.hl_page(name, items)
|
||||
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:
|
||||
return await ImageTemplate.hl_page(name, items)
|
||||
return "糟糕! 该功能没有帮助喔..."
|
||||
return "没有查找到这个功能噢..."
|
||||
|
||||
Reference in New Issue
Block a user