mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
修复HTML帮助私聊无法生成, 修改HTML帮助禁用提示文本错误
This commit is contained in:
parent
9d6f44849a
commit
b3871d550c
@ -296,6 +296,11 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能
|
||||
|
||||
## 更新
|
||||
|
||||
### 2022/12/12
|
||||
|
||||
* 修改HTML帮助禁用提示文本错误
|
||||
* 修复HTML帮助私聊无法生成
|
||||
|
||||
### 2022/12/11
|
||||
|
||||
* 词条问题支持真寻的昵称开头与at真寻开头并优化回复
|
||||
|
||||
@ -10,6 +10,7 @@ from nonebot.rule import to_me
|
||||
from configs.path_config import IMAGE_PATH, DATA_PATH
|
||||
from utils.message_builder import image
|
||||
from ._data_source import create_help_img, get_plugin_help
|
||||
from ._utils import GROUP_HELP_PATH
|
||||
import os
|
||||
|
||||
|
||||
@ -19,14 +20,9 @@ __plugin_configs__ = {
|
||||
"TYPE": {"value": "normal", "help": "帮助图片样式 ['normal', 'HTML']", "default_value": "normal"}
|
||||
}
|
||||
|
||||
group_help_path = DATA_PATH / "group_help"
|
||||
simple_help_image = IMAGE_PATH / "simple_help.png"
|
||||
if simple_help_image.exists():
|
||||
simple_help_image.unlink()
|
||||
group_help_path.mkdir(exist_ok=True, parents=True)
|
||||
for x in os.listdir(group_help_path):
|
||||
group_help_image = group_help_path / x
|
||||
group_help_image.unlink()
|
||||
|
||||
|
||||
simple_help = on_command("功能", rule=to_me(), aliases={"help", "帮助"}, priority=1, block=True)
|
||||
@ -48,13 +44,13 @@ async def _(bot: Bot, event: MessageEvent, arg: Message = CommandArg()):
|
||||
await simple_help.send("没有此功能的帮助信息...")
|
||||
else:
|
||||
if isinstance(event, GroupMessageEvent):
|
||||
_image_path = group_help_path / f"{event.group_id}.png"
|
||||
_image_path = GROUP_HELP_PATH / f"{event.group_id}.png"
|
||||
if not _image_path.exists():
|
||||
await create_help_img(event.group_id, _image_path)
|
||||
await create_help_img(event.group_id)
|
||||
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, simple_help_image)
|
||||
await create_help_img(None)
|
||||
await simple_help.finish(image("simple_help.png"))
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
|
||||
from ._utils import HelpImageBuild
|
||||
from utils.image_utils import BuildImage
|
||||
from configs.path_config import IMAGE_PATH
|
||||
@ -6,7 +7,6 @@ from utils.manager import (
|
||||
admin_manager,
|
||||
)
|
||||
from typing import Optional
|
||||
from pathlib import Path
|
||||
import nonebot
|
||||
|
||||
|
||||
@ -15,22 +15,12 @@ random_bk_path = IMAGE_PATH / "background" / "help" / "simple_help"
|
||||
background = IMAGE_PATH / "background" / "0.png"
|
||||
|
||||
|
||||
async def create_help_img(group_id: Optional[int], help_image: Path):
|
||||
async def create_help_img(group_id: Optional[int]):
|
||||
"""
|
||||
生成帮助图片
|
||||
:param group_id: 群号
|
||||
:param help_image: 图片路径
|
||||
"""
|
||||
return await _create_help_img(group_id, help_image)
|
||||
|
||||
|
||||
async def _create_help_img(group_id: Optional[int], help_image: Path):
|
||||
"""
|
||||
生成帮助图片
|
||||
:param group_id: 群号
|
||||
:param help_image: 图片路径
|
||||
"""
|
||||
await HelpImageBuild().build_image(group_id, help_image)
|
||||
await HelpImageBuild().build_image(group_id)
|
||||
|
||||
|
||||
def get_plugin_help(msg: str, is_super: bool = False) -> Optional[str]:
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
from pathlib import Path
|
||||
from typing import List, Tuple, Dict, Optional
|
||||
from nonebot_plugin_htmlrender import template_to_pic
|
||||
|
||||
from ._config import Item
|
||||
from configs.path_config import IMAGE_PATH, TEMPLATE_PATH
|
||||
from configs.path_config import IMAGE_PATH, TEMPLATE_PATH, DATA_PATH
|
||||
from utils.decorator import Singleton
|
||||
from utils.image_utils import BuildImage
|
||||
from configs.config import Config
|
||||
@ -14,14 +13,20 @@ from utils.manager import plugin_data_manager, group_manager
|
||||
from utils.manager.models import PluginData, PluginType
|
||||
|
||||
|
||||
background_path = IMAGE_PATH / "background" / "help" / "simple_help"
|
||||
GROUP_HELP_PATH = DATA_PATH / "group_help"
|
||||
GROUP_HELP_PATH.mkdir(exist_ok=True, parents=True)
|
||||
for x in os.listdir(GROUP_HELP_PATH):
|
||||
group_help_image = GROUP_HELP_PATH / x
|
||||
group_help_image.unlink()
|
||||
|
||||
logo_path = TEMPLATE_PATH / 'menu' / 'res' / 'logo'
|
||||
BACKGROUND_PATH = IMAGE_PATH / "background" / "help" / "simple_help"
|
||||
|
||||
LOGO_PATH = TEMPLATE_PATH / 'menu' / 'res' / 'logo'
|
||||
|
||||
|
||||
async def build_help_image(image_group: List[List[BuildImage]], h: int):
|
||||
bk = None
|
||||
random_bk = os.listdir(background_path)
|
||||
random_bk = os.listdir(BACKGROUND_PATH)
|
||||
if random_bk:
|
||||
bk = random.choice(random_bk)
|
||||
A = BuildImage(
|
||||
@ -29,7 +34,7 @@ async def build_help_image(image_group: List[List[BuildImage]], h: int):
|
||||
h,
|
||||
font_size=24,
|
||||
color="#FFEFD5",
|
||||
background=(background_path / bk) if bk else None,
|
||||
background=(BACKGROUND_PATH / bk) if bk else None,
|
||||
)
|
||||
A.filter("GaussianBlur", 5)
|
||||
curr_w = 50
|
||||
@ -151,20 +156,11 @@ class HelpImageBuild:
|
||||
self._sort_data[plugin_data.menu_type[0]] = []
|
||||
self._sort_data[plugin_data.menu_type[0]].append(self._data[key])
|
||||
|
||||
async def build_name_image(
|
||||
self,
|
||||
max_width: int,
|
||||
name: str,
|
||||
color: str,
|
||||
text_color: Tuple[int, int, int],
|
||||
pos: Optional[Tuple[int, int, int, int]],
|
||||
) -> BuildImage:
|
||||
image = BuildImage(max_width - 5, 50, color=color, font_size=24)
|
||||
await image.acircle_corner()
|
||||
await image.atext((0, 0), name, text_color, center_type="center")
|
||||
return image
|
||||
|
||||
async def build_image(self, group_id: Optional[int], help_image: Path):
|
||||
async def build_image(self, group_id: Optional[int]):
|
||||
if group_id:
|
||||
help_image = GROUP_HELP_PATH / f"{group_id}.png"
|
||||
else:
|
||||
help_image = IMAGE_PATH / f"simple_help.png"
|
||||
build_type = Config.get_config("help", "TYPE")
|
||||
if build_type == 'HTML':
|
||||
byt = await self.build_html_image(group_id)
|
||||
@ -180,12 +176,14 @@ class HelpImageBuild:
|
||||
for menu in self._sort_data:
|
||||
for plugin in self._sort_data[menu]:
|
||||
sta = 0
|
||||
if not plugin.plugin_status.status and plugin.plugin_status.block_type:
|
||||
if plugin.plugin_status.block_type in ['all', 'group']:
|
||||
if not plugin.plugin_status.status:
|
||||
if group_id and plugin.plugin_status.block_type in ['all', 'group']:
|
||||
sta = 2
|
||||
if not group_manager.get_plugin_super_status(plugin.model, group_id):
|
||||
if not group_id and plugin.plugin_status.block_type in ['all', 'private']:
|
||||
sta = 2
|
||||
if group_id and not group_manager.get_plugin_super_status(plugin.model, group_id):
|
||||
sta = 2
|
||||
if not group_manager.get_plugin_status(plugin.model, group_id):
|
||||
if group_id and not group_manager.get_plugin_status(plugin.model, group_id):
|
||||
sta = 1
|
||||
if classify.get(menu):
|
||||
classify[menu].append(Item(plugin_name=plugin.name, sta=sta))
|
||||
@ -200,7 +198,7 @@ class HelpImageBuild:
|
||||
icon = self.icon2str[plu]
|
||||
else:
|
||||
icon = 'fa fa-pencil-square-o'
|
||||
logo = logo_path / random.choice(os.listdir(logo_path))
|
||||
logo = LOGO_PATH / random.choice(os.listdir(LOGO_PATH))
|
||||
# print(str(logo.absolute()))
|
||||
data = {'name': plu if plu != 'normal' else '功能', 'items': classify[plu], 'icon': icon,
|
||||
'logo': str(logo.absolute())}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user