1.增加对b站dynamic参数模式的识别;2.解析包含的图片可选不折叠,默认值折叠。

This commit is contained in:
devil233 2025-09-03 21:02:43 +08:00 committed by GitHub
parent f8f9d77376
commit 3da24e3fa2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,7 +149,7 @@ export class tools extends plugin {
permission: 'master', permission: 'master',
}, },
{ {
reg: "(bilibili.com|b23.tv|bili2233.cn|t.bilibili.com|^BV[1-9a-zA-Z]{10}$)", reg: "(bilibili.com|b23.tv|bili2233.cn|m.bilibili.com|t.bilibili.com|^BV[1-9a-zA-Z]{10}$)",
fnc: "bili", fnc: "bili",
}, },
{ {
@ -316,6 +316,8 @@ export class tools extends plugin {
this.aiModel = this.toolsConfig.aiModel; this.aiModel = this.toolsConfig.aiModel;
// 强制使用海外服务器 // 强制使用海外服务器
this.forceOverseasServer = this.toolsConfig.forceOverseasServer; this.forceOverseasServer = this.toolsConfig.forceOverseasServer;
// 解析图片是否合并转发
this.globalImageLimit = this.toolsConfig.globalImageLimit;
} }
// 翻译插件 // 翻译插件
@ -921,7 +923,7 @@ export class tools extends plugin {
return true; return true;
} }
// 动态处理 // 动态处理
if (url.includes("t.bilibili.com") || url.includes("bilibili.com\/opus")) { if (url.includes("t.bilibili.com") || url.includes("bilibili.com\/opus") || url.includes("bilibili.com\/dynamic")){
if (_.isEmpty(this.biliSessData)) { if (_.isEmpty(this.biliSessData)) {
e.reply("检测到没有填写biliSessData无法解析动态"); e.reply("检测到没有填写biliSessData无法解析动态");
return true; return true;
@ -1243,7 +1245,14 @@ export class tools extends plugin {
const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0]; const dynamicId = /[^/]+(?!.*\/)/.exec(url)[0];
getDynamic(dynamicId, session).then(async resp => { getDynamic(dynamicId, session).then(async resp => {
if (resp.dynamicSrc.length > 0 || resp.dynamicDesc) { if (resp.dynamicSrc.length > 0 || resp.dynamicDesc) {
// 先发送动态描述文本
if (resp.dynamicDesc) {
e.reply(`${this.identifyPrefix}识别:哔哩哔哩动态\n${resp.dynamicDesc}`); e.reply(`${this.identifyPrefix}识别:哔哩哔哩动态\n${resp.dynamicDesc}`);
}
// 处理图片消息
if (resp.dynamicSrc.length > 0) {
if (resp.dynamicSrc.length > this.globalImageLimit) {
let dynamicSrcMsg = []; let dynamicSrcMsg = [];
resp.dynamicSrc.forEach(item => { resp.dynamicSrc.forEach(item => {
dynamicSrcMsg.push({ dynamicSrcMsg.push({
@ -1254,7 +1263,12 @@ export class tools extends plugin {
}); });
await e.reply(await Bot.makeForwardMsg(dynamicSrcMsg)); await e.reply(await Bot.makeForwardMsg(dynamicSrcMsg));
} else { } else {
e.reply(`识别:哔哩哔哩动态, 但是失败!`); const images = resp.dynamicSrc.map(item => segment.image(item));
await e.reply(images);
}
}
} else {
await e.reply(`${this.identifyPrefix}识别:哔哩哔哩动态, 但是失败!`);
} }
}); });
return url; return url;
@ -1629,6 +1643,8 @@ export class tools extends plugin {
// 等待所有图片下载完成 // 等待所有图片下载完成
const paths = await Promise.all(imagePromises); const paths = await Promise.all(imagePromises);
if (paths.length > this.globalImageLimit) {
// 直接构造 imagesData 数组 // 直接构造 imagesData 数组
const imagesData = await Promise.all(paths.map(async (item) => { const imagesData = await Promise.all(paths.map(async (item) => {
return { return {
@ -1640,6 +1656,11 @@ export class tools extends plugin {
// 回复带有转发消息的图片数据 // 回复带有转发消息的图片数据
e.reply(await Bot.makeForwardMsg(imagesData)); e.reply(await Bot.makeForwardMsg(imagesData));
} else {
// 如果图片数量小于限制,直接发送图片
const images = await Promise.all(paths.map(async (item) => segment.image(await fs.promises.readFile(item))));
e.reply(images);
}
// 批量删除下载的文件 // 批量删除下载的文件
await Promise.all(paths.map(item => fs.promises.rm(item, { force: true }))); await Promise.all(paths.map(item => fs.promises.rm(item, { force: true })));
@ -2176,8 +2197,11 @@ export class tools extends plugin {
// 等待所有图片处理完 // 等待所有图片处理完
const images = await Promise.all(imagesPromise); const images = await Promise.all(imagesPromise);
// 回复合并的消息 // 大于判定数量则回复合并的消息
if (images.length > this.globalImageLimit)
await e.reply(await Bot.makeForwardMsg(images)); await e.reply(await Bot.makeForwardMsg(images));
else
await e.reply(images.map(item => item.message));
// 并行删除文件 // 并行删除文件
await Promise.all(images.map(({ filePath }) => checkAndRemoveFile(filePath))); await Promise.all(images.map(({ filePath }) => checkAndRemoveFile(filePath)));
@ -2393,7 +2417,8 @@ export class tools extends plugin {
const replyMsg = cover ? [segment.image(cover), normalMsg] : normalMsg; const replyMsg = cover ? [segment.image(cover), normalMsg] : normalMsg;
e.reply(replyMsg); e.reply(replyMsg);
// 图片 // 图片
if (images && images.length > 1) { if (images) {
if (images.length > this.globalImageLimit) {
const replyImages = images.map(item => { const replyImages = images.map(item => {
return { return {
message: segment.image(item), message: segment.image(item),
@ -2402,6 +2427,10 @@ export class tools extends plugin {
}; };
}); });
e.reply(Bot.makeForwardMsg(replyImages)); e.reply(Bot.makeForwardMsg(replyImages));
} else {
const imageSegments = images.map(item => segment.image(item));
e.reply(imageSegments);
}
} }
// 视频 // 视频
let vod_list = respJson.data.post?.vod_list; let vod_list = respJson.data.post?.vod_list;