zhenxun_bot/plugins/help/data_source.py

188 lines
6.3 KiB
Python
Raw Normal View History

2021-07-30 21:21:51 +08:00
from utils.image_utils import CreateImg
2021-05-20 19:23:32 +08:00
from configs.path_config import IMAGE_PATH, DATA_PATH
import ujson as json
import os
from .config import *
from nonebot import require
2021-07-30 21:21:51 +08:00
from configs.config import (
INITIAL_OPEN_CASE_COUNT,
INITIAL_SETU_PROBABILITY,
ADMIN_DEFAULT_AUTH,
)
2021-06-30 19:50:55 +08:00
from configs.config import plugins2info_dict
2021-06-15 10:57:08 +08:00
import nonebot
2021-05-20 19:23:32 +08:00
export = require("nonebot_plugin_manager")
2021-07-30 21:21:51 +08:00
width = 1600
2021-05-20 19:23:32 +08:00
e_height = 0
2021-06-30 19:50:55 +08:00
u_height = 950
2021-06-04 18:01:33 +08:00
o_height = 1500
2021-05-20 19:23:32 +08:00
# f_height =
def create_help_img():
2021-07-30 21:21:51 +08:00
if os.path.exists(IMAGE_PATH + "help.png"):
os.remove(IMAGE_PATH + "help.png")
h = (
100
+ len(utility_help) * 24
+ len(entertainment_help) * 24
+ len(other_help) * 24
) * 2
2021-05-20 19:23:32 +08:00
A = CreateImg(width, h - 200, font_size=24)
e = CreateImg(width, len(entertainment_help) * 42, font_size=24)
2021-07-30 21:21:51 +08:00
rst = ""
2021-05-20 19:23:32 +08:00
i = 0
for cmd in entertainment_help:
2021-07-30 21:21:51 +08:00
rst += f"{i + 1}.{entertainment_help[cmd]}\n"
2021-05-20 19:23:32 +08:00
i += 1
2021-07-30 21:21:51 +08:00
e.text((10, 10), "娱乐功能:")
2021-05-20 19:23:32 +08:00
e.text((40, 40), rst)
2021-07-30 21:21:51 +08:00
u = CreateImg(width, len(utility_help) * 40 + 50, font_size=24, color="black")
rst = ""
2021-05-20 19:23:32 +08:00
i = 0
for cmd in utility_help:
2021-07-30 21:21:51 +08:00
rst += f"{i + 1}.{utility_help[cmd]}\n"
2021-05-20 19:23:32 +08:00
i += 1
2021-07-30 21:21:51 +08:00
u.text((10, 10), "实用功能:", fill=(255, 255, 255))
2021-05-20 19:23:32 +08:00
u.text((40, 40), rst, fill=(255, 255, 255))
o = CreateImg(width, len(other_help) * 40, font_size=24)
2021-07-30 21:21:51 +08:00
rst = ""
2021-05-20 19:23:32 +08:00
i = 0
for i in range(len(other_help)):
2021-07-30 21:21:51 +08:00
rst += f"{i + 1}.{other_help[i]}\n"
2021-05-20 19:23:32 +08:00
i += 1
2021-07-30 21:21:51 +08:00
o.text((10, 10), "其他功能:")
2021-05-20 19:23:32 +08:00
o.text((40, 40), rst)
A.paste(e, (0, 0))
A.paste(u, (0, u_height))
A.paste(o, (0, o_height))
2021-07-30 21:21:51 +08:00
A.text(
(10, h * 0.68),
"大部分交互功能可以通过输入‘取消’,‘算了’来取消当前交互\n对真寻说 “真寻帮助 指令名” 获取对应详细帮助\n"
"可以通过 “滴滴滴- [消息]” 联系管理员(有趣的想法尽管来吧!<还有Bug和建议>"
"\n[群管理员请看 管理员帮助(群主与管理员自带 5 级权限)]\n\n"
"\t「如果真寻回复了一些不符合人设的话那是因为每日白嫖的图灵次数已用完使用的是备用接口【QAQ】」",
)
2021-06-15 10:57:08 +08:00
2021-07-30 21:21:51 +08:00
A.save(IMAGE_PATH + "help.png")
2021-05-20 19:23:32 +08:00
def create_group_help_img(group_id: int):
group_id = str(group_id)
try:
2021-07-30 21:21:51 +08:00
with open(DATA_PATH + "manager/plugin_list.json", "r", encoding="utf8") as f:
2021-05-20 19:23:32 +08:00
plugin_list = json.load(f)
except (ValueError, FileNotFoundError):
pass
2021-07-30 21:21:51 +08:00
h = (
100
+ len(utility_help) * 24
+ len(entertainment_help) * 24
+ len(other_help) * 24
) * 2
A = CreateImg(width, h - 200, font_size=24)
u = CreateImg(width, len(utility_help) * 40, font_size=24, color="black")
o = CreateImg(width, len(other_help) * 40, font_size=24)
2021-05-20 19:23:32 +08:00
e = CreateImg(width, len(entertainment_help) * 42, font_size=24)
2021-07-30 21:21:51 +08:00
rst = ""
2021-05-20 19:23:32 +08:00
i = 1
for cmd in entertainment_help.keys():
flag, dfg = parse_cmd(cmd, group_id, plugin_list)
if dfg:
cmd = rcmd(dfg)
2021-07-30 21:21:51 +08:00
rst += f"{flag}{i}.{entertainment_help[cmd]}\n"
2021-05-20 19:23:32 +08:00
i += 1
2021-07-30 21:21:51 +08:00
e.text((10, 10), "娱乐功能:")
2021-05-20 19:23:32 +08:00
e.text((40, 40), rst)
2021-07-30 21:21:51 +08:00
rst = ""
2021-05-20 19:23:32 +08:00
i = 1
for cmd in utility_help.keys():
flag, dfg = parse_cmd(cmd, group_id, plugin_list)
2021-07-30 21:21:51 +08:00
rst += f"{flag}{i}.{utility_help[cmd]}\n"
2021-05-20 19:23:32 +08:00
i += 1
2021-07-30 21:21:51 +08:00
u.text((10, 10), "实用功能:", fill=(255, 255, 255))
2021-05-20 19:23:32 +08:00
u.text((40, 40), rst, fill=(255, 255, 255))
2021-07-30 21:21:51 +08:00
rst = ""
2021-05-20 19:23:32 +08:00
for i in range(len(other_help)):
2021-07-30 21:21:51 +08:00
rst += f"{i + 1}.{other_help[i]}\n"
o.text((10, 10), "其他功能:")
2021-05-20 19:23:32 +08:00
o.text((40, 40), rst)
A.paste(e, (0, 0))
A.paste(u, (0, u_height))
A.paste(o, (0, o_height))
# A.text((width, 10), f'总开关【{"√" if data["总开关"] else "×"}】')
2021-07-30 21:21:51 +08:00
A.text(
(10, h * 0.68),
"大部分交互功能可以通过输入‘取消’,‘算了’来取消当前交互\n对真寻说 “真寻帮助 指令名” 获取对应详细帮助\n"
"可以通过 “滴滴滴- [消息]” 联系管理员(有趣的想法尽管来吧!<还有Bug和建议>"
f"\n[群管理员请看 管理员帮助(群主与管理员自带 {ADMIN_DEFAULT_AUTH} 级权限)]",
)
A.text(
(10, h * 0.77),
f"【注】「色图概率:好感度 + {int(INITIAL_SETU_PROBABILITY*100)}%\n"
f"\t\t每 3 点好感度 + 1次开箱初始 {INITIAL_OPEN_CASE_COUNT}\n"
f"\t\t开启/关闭功能只需输入‘开启/关闭 指令名’(每个功能的第一个指令)」\n"
f"\t\t示例:开启签到\n"
f"\t\t可以通过管理员开关自动发送消息(早晚安等)\n"
f"\t\t^请查看管理员帮助^\n\n"
f"\t「如果真寻回复了一些不符合人设的话那是因为每日白嫖的图灵次数已用完使用的是备用接口【QAQ】」",
)
A.save(DATA_PATH + f"group_help/{group_id}.png")
2021-05-20 19:23:32 +08:00
def parse_cmd(cmd, group_id, plugin_list):
2021-07-30 21:21:51 +08:00
flag = ""
2021-05-20 19:23:32 +08:00
dfg = None
2021-07-30 21:21:51 +08:00
if cmd.find("draw_card") != -1:
lst = cmd.split("_")
cmd = lst[0] + "_" + lst[1]
2021-05-26 20:08:13 +08:00
dfg = lst[-1]
2021-07-30 21:21:51 +08:00
elif cmd == "pixiv_r":
cmd = "pixiv"
dfg = "r"
elif cmd == "pixiv_s":
cmd = "pixiv"
dfg = "s"
2021-05-20 19:23:32 +08:00
if group_id in plugin_list[cmd]:
if not plugin_list[cmd][group_id]:
2021-07-30 21:21:51 +08:00
flag = "×"
if cmd in ["bt", "reimu", "nickname"]:
flag = "- "
2021-05-20 19:23:32 +08:00
return flag, dfg
def rcmd(dfg):
2021-07-30 21:21:51 +08:00
if dfg in [
"prts",
"genshin",
"pretty",
"guardian",
"pcr",
"azur",
"onmyoji",
"fgo",
]:
return "draw_card_" + dfg
if dfg == "r":
return "pixiv_r"
if dfg == "s":
return "pixiv_s"
2021-05-20 19:23:32 +08:00
2021-06-15 10:57:08 +08:00
def get_plugin_help(msg: str) -> str:
plugin = None
2021-06-30 19:50:55 +08:00
for p in plugins2info_dict.keys():
2021-07-30 21:21:51 +08:00
if msg in plugins2info_dict[p]["cmd"]:
2021-06-15 10:57:08 +08:00
plugin = nonebot.plugin.get_plugin(p)
break
if plugin:
result = plugin.module.__getattribute__("__plugin_usage__")
return result
else:
2021-07-30 21:21:51 +08:00
return "没有此功能的帮助信息..."