mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-04 03:10:01 +08:00
🎨 统一发送格式
This commit is contained in:
@@ -2,7 +2,6 @@ import random
|
||||
from typing import Tuple
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters.onebot.v11 import MessageSegment
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.message import run_postprocessor
|
||||
from nonebot.plugin import PluginMetadata
|
||||
@@ -23,11 +22,11 @@ from zhenxun.configs.utils import PluginCdBlock, PluginExtraData, RegisterConfig
|
||||
from zhenxun.models.sign_user import SignUser
|
||||
from zhenxun.models.user_console import UserConsole
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
from zhenxun.utils.utils import template2forward
|
||||
from zhenxun.utils.withdraw_manage import WithdrawManager
|
||||
|
||||
from ._data_source import Image, SetuManage, base_config
|
||||
from ._data_source import SetuManage, base_config
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="色图",
|
||||
@@ -196,7 +195,7 @@ async def _(
|
||||
if is_r18 and gid:
|
||||
"""群聊中禁止查看r18"""
|
||||
if not base_config.get("ALLOW_GROUP_R18"):
|
||||
await Text(
|
||||
await MessageUtils.build_message(
|
||||
random.choice(
|
||||
[
|
||||
"这种不好意思的东西怎么可能给这么多人看啦",
|
||||
@@ -209,11 +208,11 @@ async def _(
|
||||
"""指定id"""
|
||||
result = await SetuManage.get_setu(local_id=local_id.result)
|
||||
if isinstance(result, str):
|
||||
await Text(result).finish(reply=True)
|
||||
await MessageUtils.build_message(result).finish(reply=True)
|
||||
await result[0].finish()
|
||||
result_list = await SetuManage.get_setu(tags=_tags, num=_num, is_r18=is_r18)
|
||||
if isinstance(result_list, str):
|
||||
await Text(result_list).finish(reply=True)
|
||||
await MessageUtils.build_message(result_list).finish(reply=True)
|
||||
max_once_num2forward = base_config.get("MAX_ONCE_NUM2FORWARD")
|
||||
platform = PlatformUtils.get_platform(bot)
|
||||
if (
|
||||
@@ -223,7 +222,7 @@ async def _(
|
||||
and len(result_list) >= max_once_num2forward
|
||||
):
|
||||
logger.debug("使用合并转发转发色图数据", arparma.header_result, session=session)
|
||||
forward = template2forward(result_list, bot.self_id) # type: ignore
|
||||
forward = MessageUtils.template2forward(result_list, bot.self_id) # type: ignore
|
||||
await bot.send_group_forward_msg(
|
||||
group_id=int(gid),
|
||||
messages=forward, # type: ignore
|
||||
@@ -233,7 +232,7 @@ async def _(
|
||||
logger.info(f"发送色图 {result}", arparma.header_result, session=session)
|
||||
receipt = await result.send()
|
||||
if receipt:
|
||||
message_id = receipt.extract_message_id().message_id # type: ignore
|
||||
message_id = receipt.msg_ids[0]["message_id"]
|
||||
await WithdrawManager.withdraw_message(
|
||||
bot,
|
||||
message_id,
|
||||
|
||||
@@ -3,13 +3,14 @@ import random
|
||||
from pathlib import Path
|
||||
|
||||
from asyncpg import UniqueViolationError
|
||||
from nonebot_plugin_saa import Image, MessageFactory, Text
|
||||
from nonebot_plugin_alconna import UniMessage
|
||||
|
||||
from zhenxun.configs.config import NICKNAME, Config
|
||||
from zhenxun.configs.path_config import IMAGE_PATH, TEMP_PATH
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.http_utils import AsyncHttpx
|
||||
from zhenxun.utils.image_utils import compressed_image
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.utils.utils import change_img_md5, change_pixiv_image_links
|
||||
|
||||
from .._model import Setu
|
||||
@@ -36,7 +37,7 @@ class SetuManage:
|
||||
num: int = 10,
|
||||
tags: list[str] | None = None,
|
||||
is_r18: bool = False,
|
||||
) -> list[MessageFactory] | str:
|
||||
) -> list[UniMessage] | str:
|
||||
"""获取色图
|
||||
|
||||
参数:
|
||||
@@ -82,7 +83,7 @@ class SetuManage:
|
||||
result_list.append(cls.init_image_message(file_path, setu))
|
||||
if flag:
|
||||
result_list.append(
|
||||
MessageFactory([Text("坏了,已经没图了,被榨干了!")])
|
||||
MessageUtils.build_message("坏了,已经没图了,被榨干了!")
|
||||
)
|
||||
return result_list
|
||||
data_list = await cls.search_lolicon(tags, num, is_r18)
|
||||
@@ -101,17 +102,19 @@ class SetuManage:
|
||||
for setu in data_list:
|
||||
file = await cls.get_image(setu)
|
||||
if isinstance(file, str):
|
||||
result_list.append(MessageFactory([Text(file)]))
|
||||
result_list.append(MessageUtils.build_message(file))
|
||||
continue
|
||||
result_list.append(cls.init_image_message(file, setu))
|
||||
if not result_list:
|
||||
return "没找到符合条件的色图..."
|
||||
if flag:
|
||||
result_list.append(MessageFactory([Text("坏了,已经没图了,被榨干了!")]))
|
||||
result_list.append(
|
||||
MessageUtils.build_message("坏了,已经没图了,被榨干了!")
|
||||
)
|
||||
return result_list
|
||||
|
||||
@classmethod
|
||||
def init_image_message(cls, file: Path, setu: Setu) -> MessageFactory:
|
||||
def init_image_message(cls, file: Path, setu: Setu) -> UniMessage:
|
||||
"""初始化图片发送消息
|
||||
|
||||
参数:
|
||||
@@ -119,20 +122,18 @@ class SetuManage:
|
||||
setu: Setu
|
||||
|
||||
返回:
|
||||
MessageFactory: 发送消息内容
|
||||
UniMessage: 发送消息内容
|
||||
"""
|
||||
data_list = []
|
||||
if base_config.get("SHOW_INFO"):
|
||||
data_list.append(
|
||||
Text(
|
||||
f"id:{setu.local_id or ''}\n"
|
||||
f"title:{setu.title}\n"
|
||||
f"author:{setu.author}\n"
|
||||
f"PID:{setu.pid}\n"
|
||||
)
|
||||
f"id:{setu.local_id or ''}\n"
|
||||
f"title:{setu.title}\n"
|
||||
f"author:{setu.author}\n"
|
||||
f"PID:{setu.pid}\n"
|
||||
)
|
||||
data_list.append(Image(file))
|
||||
return MessageFactory(data_list)
|
||||
data_list.append(file)
|
||||
return MessageUtils.build_message(data_list)
|
||||
|
||||
@classmethod
|
||||
async def get_setu_list(
|
||||
@@ -167,7 +168,7 @@ class SetuManage:
|
||||
return image_list
|
||||
|
||||
@classmethod
|
||||
def get_luo(cls, impression: float) -> MessageFactory | None:
|
||||
def get_luo(cls, impression: float) -> UniMessage | None:
|
||||
"""罗翔
|
||||
|
||||
参数:
|
||||
@@ -179,15 +180,13 @@ class SetuManage:
|
||||
if initial_setu_probability := base_config.get("INITIAL_SETU_PROBABILITY"):
|
||||
probability = float(impression) + initial_setu_probability * 100
|
||||
if probability < random.randint(1, 101):
|
||||
return MessageFactory(
|
||||
return MessageUtils.build_message(
|
||||
[
|
||||
Text("我为什么要给你发这个?"),
|
||||
Image(
|
||||
IMAGE_PATH
|
||||
/ "luoxiang"
|
||||
/ random.choice(os.listdir(IMAGE_PATH / "luoxiang"))
|
||||
),
|
||||
Text(f"\n(快向{NICKNAME}签到提升好感度吧!)"),
|
||||
"我为什么要给你发这个?",
|
||||
IMAGE_PATH
|
||||
/ "luoxiang"
|
||||
/ random.choice(os.listdir(IMAGE_PATH / "luoxiang")),
|
||||
f"\n(快向{NICKNAME}签到提升好感度吧!)",
|
||||
]
|
||||
)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user