fix🐛: 修改图片bytes发送

This commit is contained in:
HibiKier 2024-02-28 00:38:54 +08:00
parent 9f17a525f1
commit aa68553539
12 changed files with 64 additions and 51 deletions

View File

@ -145,7 +145,7 @@ async def _(
_user_id = user_id.result if user_id.available else None
_group_id = group_id.result if group_id.available else None
if image := await BanManage.build_ban_image(filter_type):
await Image(image.pic2bs4()).finish(reply=True)
await Image(image.pic2bytes()).finish(reply=True)
else:
await Text("数据为空捏...").finish(reply=True)

View File

@ -66,7 +66,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma):
if session.id1 in bot.config.superusers:
image = await build_plugin()
if image:
await Image(image.pic2bs4()).send(reply=True)
await Image(image.pic2bytes()).send(reply=True)
logger.info(
f"查看功能列表",
arparma.header_result,
@ -78,7 +78,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma):
async def _(bot: Bot, session: EventSession, arparma: Arparma):
image = None
if image := await build_task(session.id3 or session.id2):
await Image(image.pic2bs4()).send(reply=True)
await Image(image.pic2bytes()).send(reply=True)
logger.info(
f"查看被动列表",
arparma.header_result,

View File

@ -119,7 +119,7 @@ async def _(
logger.info(
f"查看消息排行 数量={count.result}", arparma.header_result, session=session
)
await Image(A.pic2bs4()).finish(reply=True)
await Image(A.pic2bytes()).finish(reply=True)
await Text("群组消息记录为空...").finish()

View File

@ -1,3 +1,5 @@
from pathlib import Path
from nonebot.plugin import PluginMetadata
from nonebot.rule import to_me
from nonebot_plugin_alconna import Alconna, Args, Match, on_alconna
@ -57,7 +59,7 @@ async def _(
if name.available:
if result := await get_plugin_help(name.result):
if isinstance(result, BuildImage):
await Image(result.pic2bs4()).send(reply=True)
await Image(result.pic2bytes()).send(reply=True)
else:
await Text(result).send(reply=True)
else:

View File

@ -171,39 +171,38 @@ class HelpImageBuild:
color="white" if not idx % 2 else "black",
)
curr_h = 10
if group := await GroupConsole.get_or_none(group_id=group_id):
for i, plugin in enumerate(plugin_list):
text_color = (255, 255, 255) if idx % 2 else (0, 0, 0)
if f"{plugin.module}," in group.block_plugin:
text_color = (252, 75, 13)
pos = None
# 禁用状态划线
if (
plugin.block_type in [BlockType.ALL, BlockType.GROUP]
or f"{plugin.module}:super," in group.block_plugin
):
w = curr_h + int(B.getsize(plugin.name)[1] / 2) + 2
pos = (
7,
w,
B.getsize(plugin.name)[0] + 35,
w,
)
if build_type == "VV":
name_image = await self.build_name_image( # type: ignore
max_width,
plugin.name,
"black" if not idx % 2 else "white",
text_color,
pos,
)
await B.paste(name_image, (0, curr_h), center_type="width")
curr_h += name_image.h + 5
else:
await B.text((10, curr_h), f"{i + 1}.{plugin.name}", text_color)
if pos:
await B.line(pos, (236, 66, 7), 3)
curr_h += font_size + 5
group = await GroupConsole.get_or_none(group_id=group_id)
for i, 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(B.getsize(plugin.name)[1] / 2) + 2
pos = (
7,
w,
B.getsize(plugin.name)[0] + 35,
w,
)
if build_type == "VV":
name_image = await self.build_name_image( # type: ignore
max_width,
plugin.name,
"black" if not idx % 2 else "white",
text_color,
pos,
)
await B.paste(name_image, (0, curr_h), center_type="width")
curr_h += name_image.h + 5
else:
await B.text((10, curr_h), f"{i + 1}.{plugin.name}", text_color)
if pos:
await B.line(pos, (236, 66, 7), 3)
curr_h += font_size + 5
if menu_type == "normal":
menu_type = "功能"
await bk.text((0, 14), menu_type, center_type="width")

View File

@ -34,7 +34,7 @@ __plugin_meta__ = PluginMetadata(
author="HibiKier",
version="0.1",
plugin_type=PluginType.NORMAL,
menu_type="商店",
menu_type="其他",
configs=[
RegisterConfig(
key="BLACK_WORD",

View File

@ -20,7 +20,6 @@ __plugin_meta__ = PluginMetadata(
我的道具
使用道具 [名称/Id]
购买道具 [名称/Id]
* 修改商品只需添加需要值即可 *
""".strip(),
extra=PluginExtraData(
author="HibiKier",
@ -77,7 +76,7 @@ _matcher.shortcut(
async def _(session: EventSession, arparma: Arparma):
image = await ShopManage.build_shop_image()
logger.info("查看商店", arparma.header_result, session=session)
await Image(image.pic2bs4()).send()
await Image(image.pic2bytes()).send()
@_matcher.assign("my-cost")
@ -101,7 +100,7 @@ async def _(
user_info.user_displayname or user_info.user_name,
session.platform,
):
await Image(image.pic2bs4()).finish(reply=True)
await Image(image.pic2bytes()).finish(reply=True)
return await Text(f"你的道具为空捏...").send(reply=True)
else:
await Text(f"用户id为空...").send(reply=True)

View File

@ -145,7 +145,7 @@ async def _(
if session.id1:
if image := await SignManage.rank(session.id1, num):
logger.info("查看签到排行", arparma.header_result, session=session)
await Image(image.pic2bs4()).finish()
await Image(image.pic2bytes()).finish()
return Text("用户id为空...").send()

View File

@ -79,7 +79,7 @@ async def _(session: EventSession):
data_list.append([table["name"], table["desc"]])
logger.info("查看数据库所有表", "查看所有表", session=session)
table = await ImageTemplate.table_page("数据库表", "", column_name, data_list)
await Image(table.pic2bs4()).send()
await Image(table.pic2bytes()).send()
except Exception as e:
logger.error("获取表数据失败...", session=session, e=e)
await Text(f"获取表数据失败... {type(e)}").send()

View File

@ -227,7 +227,7 @@ async def _(
if not req_image_list:
await Text("没有任何请求喔...").finish(reply=True)
if len(req_image_list) == 1:
await Image(req_image_list[0].pic2bs4()).finish()
await Image(req_image_list[0].pic2bytes()).finish()
width = sum([img.width for img in req_image_list])
height = max([img.height for img in req_image_list])
background = BuildImage(width, height)
@ -235,7 +235,7 @@ async def _(
await req_image_list[1].line((0, 10, 1, req_image_list[1].height - 10), width=1)
await background.paste(req_image_list[1], (req_image_list[1].width, 0))
logger.info("查看请求", arparma.header_result, session=session)
await Image(background.pic2bs4()).finish()
await Image(background.pic2bytes()).finish()
await Text("没有任何请求喔...").finish(reply=True)

View File

@ -463,13 +463,15 @@ class BuildImage:
base64_str = base64.b64encode(buf.getvalue()).decode()
return "base64://" + base64_str
def pic2io(self) -> BytesIO:
"""图片转 BytesIO
def pic2bytes(self) -> bytes:
"""获取bytes
返回:
BytesIO: BytesIO
bytes: bytes
"""
return BytesIO(self.tobytes())
buf = BytesIO()
self.markImg.save(buf, format="PNG")
return buf.getvalue()
def convert(self, type_: ModeType) -> Self:
"""

View File

@ -35,6 +35,17 @@ class ImageTemplate:
row_space: int = 10,
padding: int = 30,
) -> BuildImage:
"""列文档 (如插件帮助)
参数:
head_text: 头标签文本
items: 列内容
row_space: 列间距.
padding: 间距.
返回:
BuildImage: 图片
"""
font = BuildImage.load_font("HYWenHei-85W.ttf", 20)
width, height = BuildImage.get_text_size(head_text, font)
for title, item in items.items():
@ -47,7 +58,7 @@ class ImageTemplate:
A = BuildImage(width + padding * 2, height + padding * 2, color="#FAF9FE")
top_head = BuildImage(width, 100, color="#FFFFFF", font_size=40)
await top_head.line((0, 1, width, 1), "#C2CEFE", 2)
await top_head.text((15, 20), "签到", "#9FA3B2", "center")
await top_head.text((15, 20), head_text, "#9FA3B2", "center")
await top_head.circle_corner()
await A.paste(top_head, (0, 20), "width")
_min_width = top_head.width - 60