mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-07 12:50:03 +08:00
update v0.0.5.0
This commit is contained in:
+44
-26
@@ -1,43 +1,61 @@
|
||||
from nonebot import on_command
|
||||
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, PrivateMessageEvent
|
||||
from nonebot.adapters.cqhttp import (
|
||||
Bot,
|
||||
MessageEvent,
|
||||
)
|
||||
from nonebot.typing import T_State
|
||||
from nonebot.rule import to_me
|
||||
from configs.path_config import DATA_PATH
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from utils.message_builder import image
|
||||
import os
|
||||
from .data_source import create_help_img, create_group_help_img, get_plugin_help
|
||||
from .data_source import create_help_img, get_plugin_help
|
||||
from utils.utils import get_message_text
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
__plugin_name__ = "帮助"
|
||||
__zx_plugin_name__ = "帮助"
|
||||
|
||||
|
||||
if not os.path.exists(DATA_PATH + "group_help/"):
|
||||
os.mkdir(DATA_PATH + "group_help/")
|
||||
create_help_img()
|
||||
for file in os.listdir(DATA_PATH + "group_help/"):
|
||||
os.remove(DATA_PATH + "group_help/" + file)
|
||||
help_image = Path(IMAGE_PATH) / "help.png"
|
||||
simple_help_image = Path(IMAGE_PATH) / "simple_help.png"
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
|
||||
_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
|
||||
_help = on_command("详细功能", rule=to_me(), aliases={"详细帮助"}, priority=1, block=True)
|
||||
simple_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
|
||||
|
||||
|
||||
@_help.handle()
|
||||
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if not msg:
|
||||
if not os.path.exists(DATA_PATH + f"group_help/{event.group_id}.png"):
|
||||
create_group_help_img(event.group_id)
|
||||
await _help.finish(
|
||||
image(abspath=DATA_PATH + f"group_help/{event.group_id}.png")
|
||||
)
|
||||
else:
|
||||
await _help.finish(get_plugin_help(msg))
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
if not help_image.exists():
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
await create_help_img(help_image, simple_help_image)
|
||||
await _help.finish(image("help.png"))
|
||||
|
||||
|
||||
@_help.handle()
|
||||
async def _(bot: Bot, event: PrivateMessageEvent, state: T_State):
|
||||
@simple_help.handle()
|
||||
async def _(bot: Bot, event: MessageEvent, state: T_State):
|
||||
msg = get_message_text(event.json())
|
||||
if not msg:
|
||||
await _help.finish(image("help.png"))
|
||||
is_super = False
|
||||
if msg:
|
||||
if '-super' in msg:
|
||||
if str(event.user_id) in bot.config.superusers:
|
||||
is_super = True
|
||||
msg = msg.replace('-super', '')
|
||||
msg = get_plugin_help(msg, is_super)
|
||||
if msg:
|
||||
await _help.send(image(b64=msg))
|
||||
else:
|
||||
await _help.send("没有此功能的帮助信息...")
|
||||
else:
|
||||
await _help.finish(get_plugin_help(msg))
|
||||
if not simple_help_image.exists():
|
||||
if help_image.exists():
|
||||
help_image.unlink()
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
await create_help_img(help_image, simple_help_image)
|
||||
await _help.finish(image("simple_help.png"))
|
||||
|
||||
Reference in New Issue
Block a user