zhenxun_bot/basic_plugins/help/__init__.py

65 lines
2.1 KiB
Python
Raw Normal View History

2023-03-19 21:05:34 +08:00
import os
2021-11-23 21:44:59 +08:00
from nonebot import on_command
2023-03-19 21:05:34 +08:00
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, Message, MessageEvent
2022-02-19 18:20:19 +08:00
from nonebot.params import CommandArg
2021-11-23 21:44:59 +08:00
from nonebot.rule import to_me
2023-03-19 21:05:34 +08:00
from configs.path_config import DATA_PATH, IMAGE_PATH
from services.log import logger
2021-11-23 21:44:59 +08:00
from utils.message_builder import image
2023-03-19 21:05:34 +08:00
from ._data_source import create_help_img, get_plugin_help
from ._utils import GROUP_HELP_PATH
2021-11-23 21:44:59 +08:00
__zx_plugin_name__ = "帮助"
__plugin_configs__ = {
2023-03-19 21:05:34 +08:00
"TYPE": {
"value": "normal",
"help": "帮助图片样式 ['normal', 'HTML']",
"default_value": "normal",
"type": str,
}
}
2022-02-19 18:20:19 +08:00
simple_help_image = IMAGE_PATH / "simple_help.png"
2021-11-23 21:44:59 +08:00
if simple_help_image.exists():
simple_help_image.unlink()
2023-03-19 21:05:34 +08:00
simple_help = on_command(
"功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True
)
2021-11-23 21:44:59 +08:00
@simple_help.handle()
2022-07-31 17:30:29 +08:00
async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
2022-02-19 18:20:19 +08:00
msg = arg.extract_plain_text().strip()
2021-11-23 21:44:59 +08:00
is_super = False
if msg:
2023-03-19 21:05:34 +08:00
if "-super" in msg:
2021-11-23 21:44:59 +08:00
if str(event.user_id) in bot.config.superusers:
is_super = True
2023-03-19 21:05:34 +08:00
msg = msg.replace("-super", "").strip()
img_msg = get_plugin_help(msg, is_super)
if img_msg:
await simple_help.send(image(b64=img_msg))
2021-11-23 21:44:59 +08:00
else:
await simple_help.send("没有此功能的帮助信息...")
2023-03-19 21:05:34 +08:00
logger.info(
f"查看帮助详情: {msg}", "帮助", event.user_id, getattr(event, "group_id", None)
)
2021-11-23 21:44:59 +08:00
else:
if isinstance(event, GroupMessageEvent):
_image_path = GROUP_HELP_PATH / f"{event.group_id}.png"
2021-11-23 21:44:59 +08:00
if not _image_path.exists():
await create_help_img(event.group_id)
2021-11-23 21:44:59 +08:00
await simple_help.send(image(_image_path))
else:
if not simple_help_image.exists():
if simple_help_image.exists():
simple_help_image.unlink()
await create_help_img(None)
await simple_help.finish(image("simple_help.png"))