🎨 统一发送格式

This commit is contained in:
HibiKier
2024-08-10 02:25:04 +08:00
parent 5e4de123b0
commit e0a3fe526e
61 changed files with 758 additions and 665 deletions
@@ -3,7 +3,6 @@ from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot.rule import to_me
from nonebot_plugin_alconna import UniMsg
from nonebot_plugin_saa import Image, Text
from nonebot_plugin_session import EventSession
from tortoise import Tortoise
@@ -12,6 +11,7 @@ from zhenxun.services.db_context import TestSQL
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.image_utils import ImageTemplate
from zhenxun.utils.message import MessageUtils
__plugin_meta__ = PluginMetadata(
name="数据库操作",
@@ -56,7 +56,7 @@ async def _(session: EventSession, message: UniMsg):
if sql_text.startswith("exec"):
sql_text = sql_text[4:].strip()
if not sql_text:
await Text("需要执行的的SQL语句!").finish()
await MessageUtils.build_message("需要执行的的SQL语句!").finish()
logger.info(f"执行SQL语句: {sql_text}", "exec", session=session)
try:
if not sql_text.lower().startswith("select"):
@@ -77,11 +77,11 @@ async def _(session: EventSession, message: UniMsg):
table = await ImageTemplate.table_page(
"EXEC", f"总共有 {len(data_list)} 条数据捏", list(_column), data_list
)
await Image(table.pic2bytes()).send()
await MessageUtils.build_message(table).send()
except Exception as e:
logger.error("执行 SQL 语句失败...", session=session, e=e)
await Text(f"执行 SQL 语句失败... {type(e)}").finish()
await Text("执行 SQL 语句成功!").finish()
await MessageUtils.build_message(f"执行 SQL 语句失败... {type(e)}").finish()
await MessageUtils.build_message("执行 SQL 语句成功!").finish()
@_table_matcher.handle()
@@ -97,7 +97,7 @@ async def _(session: EventSession):
table = await ImageTemplate.table_page(
"数据库表", f"总共有 {len(data_list)} 张表捏", column_name, data_list
)
await Image(table.pic2bytes()).send()
await MessageUtils.build_message(table).send()
except Exception as e:
logger.error("获取表数据失败...", session=session, e=e)
await Text(f"获取表数据失败... {type(e)}").send()
await MessageUtils.build_message(f"获取表数据失败... {type(e)}").send()
@@ -14,7 +14,6 @@ from nonebot_plugin_alconna import (
on_alconna,
store_true,
)
from nonebot_plugin_saa import Image, Text
from nonebot_plugin_session import EventSession
from zhenxun.configs.path_config import IMAGE_PATH
@@ -24,6 +23,7 @@ from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType, RequestHandleType, RequestType
from zhenxun.utils.exception import NotFoundError
from zhenxun.utils.image_utils import BuildImage
from zhenxun.utils.message import MessageUtils
from zhenxun.utils.utils import get_user_avatar
usage = """
@@ -143,11 +143,13 @@ async def _(
if handle_type == RequestHandleType.IGNORE:
await FgRequest.ignore(id)
except NotFoundError:
await Text("未发现此id的请求...").finish(reply=True)
await MessageUtils.build_message("未发现此id的请求...").finish(reply_to=True)
except Exception:
await Text("其他错误, 可能flag已失效...").finish(reply=True)
await MessageUtils.build_message("其他错误, 可能flag已失效...").finish(
reply_to=True
)
logger.info("处理请求", arparma.header_result, session=session)
await Text("成功处理请求!").finish(reply=True)
await MessageUtils.build_message("成功处理请求!").finish(reply_to=True)
@_read_matcher.handle()
@@ -232,9 +234,9 @@ async def _(
await result_image.text((15, 13), _type_text, fill=(140, 140, 143))
req_image_list.append(result_image)
if not req_image_list:
await Text("没有任何请求喔...").finish(reply=True)
await MessageUtils.build_message("没有任何请求喔...").finish(reply_to=True)
if len(req_image_list) == 1:
await Image(req_image_list[0].pic2bytes()).finish()
await MessageUtils.build_message(req_image_list[0]).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)
@@ -242,8 +244,8 @@ 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.pic2bytes()).finish()
await Text("没有任何请求喔...").finish(reply=True)
await MessageUtils.build_message(background).finish()
await MessageUtils.build_message("没有任何请求喔...").finish(reply_to=True)
@_clear_matcher.handle()
@@ -270,4 +272,4 @@ async def _(
handle_type=RequestHandleType.IGNORE
)
logger.info(f"清空{_type}请求", arparma.header_result, session=session)
await Text(f"已清空{_type}请求!").finish()
await MessageUtils.build_message(f"已清空{_type}请求!").finish()
@@ -1,15 +1,12 @@
import nonebot
from arclet.alconna import Args, Option
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
from nonebot_plugin_alconna.matcher import AlconnaMatcher
from nonebot_plugin_saa import Image, Text
from nonebot_plugin_session import EventSession
from zhenxun.configs.config import Config
from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
from zhenxun.configs.path_config import IMAGE_PATH
from zhenxun.configs.utils import PluginExtraData
from zhenxun.models.plugin_info import PluginInfo
from zhenxun.models.task_info import TaskInfo
from zhenxun.services.log import logger
@@ -21,6 +18,7 @@ from zhenxun.utils.image_utils import (
group_image,
text2image,
)
from zhenxun.utils.message import MessageUtils
from zhenxun.utils.rules import admin_check, ensure_group
__plugin_meta__ = PluginMetadata(
@@ -156,6 +154,6 @@ async def _(
try:
await build_help()
except EmptyError:
await Text("超级用户帮助为空").finish(reply=True)
await Image(SUPERUSER_HELP_IMAGE).send()
await MessageUtils.build_message("超级用户帮助为空").finish(reply_to=True)
await MessageUtils.build_message(SUPERUSER_HELP_IMAGE).send()
logger.info("查看超级用户帮助", arparma.header_result, session=session)