🎨 统一发送格式

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
+2 -2
View File
@@ -192,7 +192,7 @@ async def search_image(
return pid_count, pic_count
async def get_image(img_url: str, user_id: str) -> str | Path | None:
async def get_image(img_url: str, user_id: str) -> Path | None:
"""下载图片
参数:
@@ -200,7 +200,7 @@ async def get_image(img_url: str, user_id: str) -> str | Path | None:
user_id: 用户id
返回:
str | Path | None: 图片名称
Path | None: 图片名称
"""
if "https://www.pixiv.net/artworks" in img_url:
pid = img_url.rsplit("/", maxsplit=1)[-1]
+22 -20
View File
@@ -11,12 +11,12 @@ from nonebot_plugin_alconna import (
on_alconna,
store_true,
)
from nonebot_plugin_saa import Image, MessageFactory, Text
from nonebot_plugin_session import EventSession
from zhenxun.configs.config import Config
from zhenxun.configs.utils import BaseBlock, PluginExtraData, RegisterConfig
from zhenxun.services.log import logger
from zhenxun.utils.message import MessageUtils
from zhenxun.utils.platform import PlatformUtils
from zhenxun.utils.withdraw_manage import WithdrawManager
@@ -96,7 +96,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
global PIX_RATIO, OMEGA_RATIO
gid = session.id3 or session.id2
if not session.id1:
await Text("用户id为空...").finish()
await MessageUtils.build_message("用户id为空...").finish()
if PIX_RATIO is None:
pix_omega_pixiv_ratio = Config.get_config("pix", "PIX_OMEGA_PIXIV_RATIO")
PIX_RATIO = pix_omega_pixiv_ratio[0] / (
@@ -117,7 +117,9 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
if (nsfw_tag == 1 and not Config.get_config("pix", "ALLOW_GROUP_SETU")) or (
nsfw_tag == 2 and not Config.get_config("pix", "ALLOW_GROUP_R18")
):
await Text("你不能看这些噢,这些都是是留给管理员看的...").finish()
await MessageUtils.build_message(
"你不能看这些噢,这些都是是留给管理员看的..."
).finish()
if (n := len(spt)) == 1:
if str(spt[0]).isdigit() and int(spt[0]) < 100:
num = int(spt[0])
@@ -132,7 +134,9 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
session.id1 in bot.config.superusers and num > 30
):
num = random.randint(1, 10)
await Text(f"太贪心了,就给你发 {num}张 好了").send()
await MessageUtils.build_message(
f"太贪心了,就给你发 {num}张 好了"
).send()
spt = spt[:-1]
keyword = " ".join(spt)
pix_num = int(num * PIX_RATIO) + 15 if PIX_RATIO != 0 else 0
@@ -149,7 +153,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
elif keyword.lower().startswith("pid"):
pid = keyword.replace("pid", "").replace(":", "").replace(":", "")
if not str(pid).isdigit():
await Text("PID必须是数字...").finish(reply=True)
await MessageUtils.build_message("PID必须是数字...").finish(reply_to=True)
all_image = await Pixiv.query_images(
pid=int(pid), r18=1 if nsfw_tag == 2 else 0
)
@@ -169,15 +173,15 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
all_image.append(x)
tmp_.append(x.pid)
if not all_image:
await Text(f"未在图库中找到与 {keyword} 相关Tag/UID/PID的图片...").finish(
reply=True
)
await MessageUtils.build_message(
f"未在图库中找到与 {keyword} 相关Tag/UID/PID的图片..."
).finish(reply_to=True)
msg_list = []
for _ in range(num):
img_url = None
author = None
if not all_image:
await Text("坏了...发完了,没图了...").finish()
await MessageUtils.build_message("坏了...发完了,没图了...").finish()
img = random.choice(all_image)
all_image.remove(img) # type: ignore
if isinstance(img, OmegaPixivIllusts):
@@ -194,24 +198,22 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
if _img:
if Config.get_config("pix", "SHOW_INFO"):
msg_list.append(
MessageFactory(
MessageUtils.build_message(
[
Text(
f"title:{title}\n"
f"author:{author}\n"
f"PID:{pid}\nUID:{uid}\n"
),
Image(_img),
f"title:{title}\n"
f"author:{author}\n"
f"PID:{pid}\nUID:{uid}\n",
_img,
]
)
)
else:
msg_list.append(Image(_img))
msg_list.append(_img)
logger.info(
f" 查看PIX图库PID: {pid}", arparma.header_result, session=session
)
else:
msg_list.append(Text("这张图似乎下载失败了"))
msg_list.append(MessageUtils.build_message("这张图似乎下载失败了"))
logger.info(
f" 查看PIX图库PID: {pid},下载图片出错",
arparma.header_result,
@@ -225,7 +227,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
for msg in msg_list:
receipt = await msg.send()
if receipt:
message_id = receipt.extract_message_id().message_id
message_id = receipt.msg_ids[0]["message_id"]
await WithdrawManager.withdraw_message(
bot,
str(message_id),
@@ -236,7 +238,7 @@ async def _(bot: Bot, session: EventSession, arparma: Arparma, tags: Match[str])
for msg in msg_list:
receipt = await msg.send()
if receipt:
message_id = receipt.extract_message_id().message_id
message_id = receipt.msg_ids[0]["message_id"]
await WithdrawManager.withdraw_message(
bot,
message_id,
+11 -7
View File
@@ -1,11 +1,11 @@
from nonebot.adapters import Bot
from nonebot.plugin import PluginMetadata
from nonebot_plugin_alconna import Alconna, Args, Arparma, Match, on_alconna
from nonebot_plugin_saa import Image, Text
from nonebot_plugin_session import EventSession
from zhenxun.configs.utils import PluginExtraData
from zhenxun.services.log import logger
from zhenxun.utils.message import MessageUtils
from ._data_source import gen_keyword_pic, get_keyword_num
from ._model.pixiv_keyword_user import PixivKeywordUser
@@ -40,8 +40,10 @@ async def _(arparma: Arparma, session: EventSession):
"keyword", flat=True
)
if not data:
await Text("您目前没有提供任何Pixiv搜图关键字...").finish(reply=True)
await Text(f"您目前提供的如下关键字:\n\t" + ",".join(data)).send() # type: ignore
await MessageUtils.build_message("您目前没有提供任何Pixiv搜图关键字...").finish(
reply_to=True
)
await MessageUtils.build_message(f"您目前提供的如下关键字:\n\t" + ",".join(data)).send() # type: ignore
logger.info("查看我的pix关键词", arparma.header_result, session=session)
@@ -52,12 +54,14 @@ async def _(bot: Bot, arparma: Arparma, session: EventSession):
image = await gen_keyword_pic(
_pass_keyword, not_pass_keyword, session.id1 in bot.config.superusers
)
await Image(image.pic2bytes()).send() # type: ignore
await MessageUtils.build_message(image).send() # type: ignore
else:
if session.id1 in bot.config.superusers:
await Text(f"目前没有已收录或待收录的搜索关键词...").send()
await MessageUtils.build_message(
f"目前没有已收录或待收录的搜索关键词..."
).send()
else:
await Text(f"目前没有已收录的搜索关键词...").send()
await MessageUtils.build_message(f"目前没有已收录的搜索关键词...").send()
@_pix_matcher.handle()
@@ -66,7 +70,7 @@ async def _(bot: Bot, arparma: Arparma, session: EventSession, keyword: Match[st
if keyword.available:
_keyword = keyword.result
count, r18_count, count_, setu_count, r18_count_ = await get_keyword_num(_keyword)
await Text(
await MessageUtils.build_message(
f"PIX图库:{_keyword}\n"
f"总数:{count + r18_count}\n"
f"美图:{count}\n"