mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 13:42:56 +08:00
* 添加全局cache * ✨ 构建缓存,hook使用缓存 * ✨ 新增数据库Model方法监控 * ✨ 数据库添加semaphore锁 * 🩹 优化webapi返回数据 * ✨ 添加增量缓存与缓存过期 * 🎨 优化检测代码结构 * ⚡ 优化hook权限检测性能 * 🐛 添加新异常判断跳过权限检测 * ✨ 添加插件limit缓存 * 🎨 代码格式优化 * 🐛 修复代码导入 * 🐛 修复刷新时检查 * 👽 Rename exception for missing database URL in initialization * ♿ Update default database URL to SQLite in configuration * 🔧 Update tortoise-orm and aiocache dependencies restrictions; add optional redis and asyncpg support * 🐛 修复ban检测 * 🐛 修复所有插件关闭时缓存更新 * 🐛 尝试迁移至aiocache * 🐛 完善aiocache缓存 * ⚡ 代码性能优化 * 🐛 移除获取封禁缓存时的日志记录 * 🐛 修复缓存类型声明,优化封禁用户处理逻辑 * 🐛 优化LevelUser权限更新逻辑及数据库迁移 * ✨ cache支持redis连接 * 🚨 auto fix by pre-commit hooks * ⚡ :增强获取群组的安全性和准确性。同时,优化了缓存管理中的相关逻辑,确保缓存操作的一致性。 * ✨ feat(auth_limit): 将插件初始化逻辑的启动装饰器更改为优先级管理器 * 🔧 修复日志记录级别 * 🔧 更新数据库连接字符串 * 🔧 更新数据库连接字符串为内存数据库,并优化权限检查逻辑 * ✨ feat(cache): 增加缓存功能配置项,并新增数据访问层以支持缓存逻辑 * ♻️ 重构cache * ✨ feat(cache): 增强缓存管理,新增缓存字典和缓存列表功能,支持过期时间管理 * 🔧 修复Notebook类中的viewport高度设置,将其从1000调整为10 * ✨ 更新插件管理逻辑,替换缓存服务为CacheRoot并优化缓存失效处理 * ✨ 更新RegisterConfig类中的type字段 * ✨ 修复清理重复记录逻辑,确保检查记录的id属性有效性 * ⚡ 超级无敌大优化,解决延迟与卡死问题 * ✨ 更新封禁功能,增加封禁时长参数和描述,优化插件信息返回结构 * ✨ 更新zhenxun_help.py中的viewport高度,将其从453调整为10,以优化页面显示效果 * ✨ 优化插件分类逻辑,增加插件ID排序,并更新插件信息返回结构 --------- Co-authored-by: BalconyJH <balconyjh@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
101 lines
3.6 KiB
Python
101 lines
3.6 KiB
Python
from zhenxun.configs.path_config import IMAGE_PATH
|
|
from zhenxun.models.group_console import GroupConsole
|
|
from zhenxun.utils._build_image import BuildImage
|
|
from zhenxun.utils.enum import BlockType
|
|
from zhenxun.utils.image_utils import build_sort_image, group_image
|
|
|
|
from ._utils import sort_type
|
|
|
|
BACKGROUND_PATH = IMAGE_PATH / "background" / "help" / "simple_help"
|
|
|
|
|
|
async def build_normal_image(group_id: str | None, is_detail: bool) -> BuildImage:
|
|
"""构造PIL帮助图片
|
|
|
|
参数:
|
|
group_id: 群号
|
|
is_detail: 详细帮助
|
|
"""
|
|
image_list = []
|
|
font_size = 24
|
|
font = BuildImage.load_font("HYWenHei-85W.ttf", 20)
|
|
sort_data = await sort_type()
|
|
for idx, menu_type in enumerate(sort_data):
|
|
plugin_list = sort_data[menu_type]
|
|
"""拿到最大宽度和结算高度"""
|
|
wh_list = [
|
|
BuildImage.get_text_size(f"{x.id}.{x.name}", font) for x in plugin_list
|
|
]
|
|
wh_list.append(BuildImage.get_text_size(menu_type, font))
|
|
sum_height = (font_size + 6) * len(plugin_list) + 10
|
|
max_width = max(x[0] for x in wh_list) + 30
|
|
bk = BuildImage(
|
|
max_width + 40,
|
|
sum_height + 50,
|
|
font_size=30,
|
|
color="#a7d1fc",
|
|
font="CJGaoDeGuo.otf",
|
|
)
|
|
title_size = bk.getsize(menu_type)
|
|
max_width = max_width if max_width > title_size[0] else title_size[0]
|
|
row = BuildImage(
|
|
max_width + 40,
|
|
sum_height,
|
|
font_size=font_size,
|
|
color="black" if idx % 2 else "white",
|
|
)
|
|
curr_h = 10
|
|
group = await GroupConsole.get_group(group_id=group_id) if group_id else None
|
|
for _, plugin in enumerate(plugin_list):
|
|
text_color = (255, 255, 255) if idx % 2 else (0, 0, 0)
|
|
if group and f"{plugin.module}," in group.block_plugin:
|
|
text_color = (252, 75, 13)
|
|
pos = None
|
|
# 禁用状态划线
|
|
if plugin.block_type in [BlockType.ALL, BlockType.GROUP] or (
|
|
group and f"super:{plugin.module}," in group.block_plugin
|
|
):
|
|
w = curr_h + int(row.getsize(plugin.name)[1] / 2) + 2
|
|
line_width = row.getsize(plugin.name)[0] + 35
|
|
pos = (7, w, line_width, w)
|
|
await row.text((10, curr_h), f"{plugin.id}.{plugin.name}", text_color)
|
|
if pos:
|
|
await row.line(pos, (236, 66, 7), 3)
|
|
curr_h += font_size + 5
|
|
await bk.text((0, 14), menu_type, center_type="width")
|
|
await bk.paste(row, (0, 50))
|
|
await bk.transparent(2)
|
|
image_list.append(bk)
|
|
image_group, h = group_image(image_list)
|
|
|
|
async def _a(image: BuildImage):
|
|
await image.filter("GaussianBlur", 5)
|
|
|
|
result = await build_sort_image(
|
|
image_group,
|
|
h,
|
|
background_path=BACKGROUND_PATH,
|
|
background_handle=_a,
|
|
)
|
|
width, height = 10, 10
|
|
for s in [
|
|
"目前支持的功能列表:",
|
|
"可以通过 '帮助 [功能名称或功能Id]' 来获取对应功能的使用方法",
|
|
]:
|
|
text = await BuildImage.build_text_image(s, "HYWenHei-85W.ttf", 24)
|
|
await result.paste(text, (width, height))
|
|
height += 50
|
|
if s == "目前支持的功能列表:":
|
|
width += 50
|
|
text = await BuildImage.build_text_image(
|
|
"注: 红字代表功能被群管理员禁用,红线代表功能正在维护",
|
|
"HYWenHei-85W.ttf",
|
|
24,
|
|
(231, 74, 57),
|
|
)
|
|
await result.paste(
|
|
text,
|
|
(300, 10),
|
|
)
|
|
return result
|