2022-12-24 00:16:17 +08:00
|
|
|
|
import nonebot
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from configs.path_config import IMAGE_PATH
|
|
|
|
|
|
from nonebot import Driver
|
2022-12-24 00:16:17 +08:00
|
|
|
|
from services.log import logger
|
|
|
|
|
|
from utils.image_template import help_template
|
|
|
|
|
|
from utils.image_utils import (BuildImage, build_sort_image, group_image,
|
|
|
|
|
|
text2image)
|
|
|
|
|
|
from utils.manager import group_manager, plugin_data_manager
|
|
|
|
|
|
from utils.manager.models import PluginType
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
driver: Driver = nonebot.get_driver()
|
|
|
|
|
|
|
2022-02-19 18:20:19 +08:00
|
|
|
|
background = IMAGE_PATH / "background" / "0.png"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
2022-12-24 00:16:17 +08:00
|
|
|
|
ADMIN_HELP_IMAGE = IMAGE_PATH / "admin_help_img.png"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@driver.on_bot_connect
|
2022-11-21 20:43:41 +08:00
|
|
|
|
async def init_task():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
if not group_manager.get_task_data():
|
2022-11-21 20:43:41 +08:00
|
|
|
|
group_manager.load_task()
|
2022-12-24 00:16:17 +08:00
|
|
|
|
logger.info(f"已成功加载 {len(group_manager.get_task_data())} 个被动技能.")
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def create_help_image():
|
|
|
|
|
|
"""
|
|
|
|
|
|
创建管理员帮助图片
|
|
|
|
|
|
"""
|
2022-04-26 14:45:04 +08:00
|
|
|
|
await _create_help_image()
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
2022-04-26 14:45:04 +08:00
|
|
|
|
async def _create_help_image():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
"""
|
|
|
|
|
|
创建管理员帮助图片
|
|
|
|
|
|
"""
|
2022-12-24 00:16:17 +08:00
|
|
|
|
if ADMIN_HELP_IMAGE.exists():
|
|
|
|
|
|
return
|
|
|
|
|
|
plugin_data_ = plugin_data_manager.get_data()
|
|
|
|
|
|
image_list = []
|
|
|
|
|
|
task_list = []
|
|
|
|
|
|
for plugin_data in [plugin_data_[x] for x in plugin_data_]:
|
2021-11-23 21:44:59 +08:00
|
|
|
|
try:
|
2022-12-24 00:16:17 +08:00
|
|
|
|
usage = None
|
|
|
|
|
|
if plugin_data.plugin_type == PluginType.ADMIN and plugin_data.usage:
|
|
|
|
|
|
usage = await text2image(
|
|
|
|
|
|
plugin_data.usage, padding=5, color=(204, 196, 151)
|
|
|
|
|
|
)
|
|
|
|
|
|
if usage:
|
|
|
|
|
|
await usage.acircle_corner()
|
|
|
|
|
|
level = 5
|
|
|
|
|
|
if plugin_data.plugin_setting:
|
|
|
|
|
|
level = plugin_data.plugin_setting.level or level
|
|
|
|
|
|
image = await help_template(plugin_data.name + f"[{level}]", usage)
|
|
|
|
|
|
image_list.append(image)
|
|
|
|
|
|
if plugin_data.task:
|
|
|
|
|
|
for x in plugin_data.task.keys():
|
|
|
|
|
|
task_list.append(plugin_data.task[x])
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.warning(
|
|
|
|
|
|
f"获取群管理员插件 {plugin_data.model}: {plugin_data.name} 设置失败... {type(e)}:{e}"
|
|
|
|
|
|
)
|
|
|
|
|
|
task_str = "\n".join(task_list)
|
|
|
|
|
|
task_str = "通过 开启/关闭 来控制群被动\n----------\n" + task_str
|
|
|
|
|
|
task_image = await text2image(task_str, padding=5, color=(204, 196, 151))
|
|
|
|
|
|
task_image = await help_template("被动任务", task_image)
|
|
|
|
|
|
image_list.append(task_image)
|
|
|
|
|
|
image_group, _ = group_image(image_list)
|
|
|
|
|
|
A = await build_sort_image(image_group, color="#f9f6f2", padding_top=180)
|
|
|
|
|
|
await A.apaste(
|
|
|
|
|
|
BuildImage(0, 0, font="CJGaoDeGuo.otf", plain_text="群管理员帮助", font_size=50),
|
|
|
|
|
|
(50, 30),
|
|
|
|
|
|
True,
|
|
|
|
|
|
)
|
|
|
|
|
|
await A.apaste(
|
|
|
|
|
|
BuildImage(
|
|
|
|
|
|
0,
|
|
|
|
|
|
0,
|
|
|
|
|
|
font="CJGaoDeGuo.otf",
|
|
|
|
|
|
plain_text="注: ‘*’ 代表可有多个相同参数 ‘?’ 代表可省略该参数",
|
|
|
|
|
|
font_size=30,
|
|
|
|
|
|
font_color="red",
|
|
|
|
|
|
),
|
|
|
|
|
|
(50, 90),
|
|
|
|
|
|
True,
|
|
|
|
|
|
)
|
|
|
|
|
|
await A.asave(ADMIN_HELP_IMAGE)
|
|
|
|
|
|
logger.info(f"已成功加载 {len(image_list)} 条管理员命令")
|