koishi-plugin-best-cave 2.3.11 → 2.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +17 -20
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -299,8 +299,13 @@ async function buildCaveMessage(cave, config, fileManager, logger2) {
|
|
|
299
299
|
if (el.type === "at") return (0, import_koishi.h)("at", { id: el.content });
|
|
300
300
|
if (el.type === "forward") {
|
|
301
301
|
try {
|
|
302
|
-
const
|
|
303
|
-
|
|
302
|
+
const forwardNodes = JSON.parse(el.content || "[]");
|
|
303
|
+
const messageNodes = await Promise.all(forwardNodes.map(async (node) => {
|
|
304
|
+
const author = (0, import_koishi.h)("author", { id: node.userId, name: node.userName });
|
|
305
|
+
const content = await transformToH(node.elements);
|
|
306
|
+
return (0, import_koishi.h)("message", {}, [author, ...content]);
|
|
307
|
+
}));
|
|
308
|
+
return (0, import_koishi.h)("forward", {}, messageNodes);
|
|
304
309
|
} catch (error) {
|
|
305
310
|
logger2.warn(`解析回声洞(${cave.id})合并转发内容失败:`, error);
|
|
306
311
|
return import_koishi.h.text("[合并转发]");
|
|
@@ -420,29 +425,23 @@ async function processMessageElements(sourceElements, newId, session, config, lo
|
|
|
420
425
|
if (type === "text" && el.attrs.content?.trim()) {
|
|
421
426
|
result.push({ type: "text", content: el.attrs.content.trim() });
|
|
422
427
|
} else if (type === "at" && el.attrs.id) {
|
|
423
|
-
if (config.debug) logger2.info(`发现 [at] 元素,ID: "${el.attrs.id}"`);
|
|
424
428
|
result.push({ type: "at", content: el.attrs.id });
|
|
425
429
|
} else if (type === "forward" && Array.isArray(el.attrs.content)) {
|
|
426
|
-
|
|
427
|
-
const allChildElements = [];
|
|
430
|
+
const forwardNodes = [];
|
|
428
431
|
for (const node of el.attrs.content) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
allChildElements.push(...transformedMessage);
|
|
435
|
-
}
|
|
432
|
+
if (!node.message) continue;
|
|
433
|
+
const userId = node.sender?.user_id;
|
|
434
|
+
const userName = node.sender?.nickname;
|
|
435
|
+
const contentElements = await transform(import_koishi.h.normalize(node.message));
|
|
436
|
+
forwardNodes.push({ userId, userName, elements: contentElements });
|
|
436
437
|
}
|
|
437
|
-
result.push({ type: "forward", content: JSON.stringify(
|
|
438
|
+
result.push({ type: "forward", content: JSON.stringify(forwardNodes) });
|
|
438
439
|
} else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
|
|
439
440
|
let fileIdentifier = el.attrs.src;
|
|
440
|
-
if (config.debug) logger2.info(`发现 [${type}] 元素,src: "${fileIdentifier}"`);
|
|
441
441
|
if (fileIdentifier.startsWith("http")) {
|
|
442
442
|
const ext = path2.extname(el.attrs.file || "") || defaultExtMap[type];
|
|
443
443
|
const currentMediaIndex = ++mediaIndex;
|
|
444
444
|
const fileName = `${newId}_${currentMediaIndex}_${session.channelId || session.guildId}_${session.userId}${ext}`;
|
|
445
|
-
if (config.debug) logger2.info(`[${type}] 是远程文件,已加入待保存列表。文件名: "${fileName}"`);
|
|
446
445
|
mediaToSave.push({ sourceUrl: fileIdentifier, fileName });
|
|
447
446
|
fileIdentifier = fileName;
|
|
448
447
|
}
|
|
@@ -1064,18 +1063,16 @@ function apply(ctx, config) {
|
|
|
1064
1063
|
sourceElements = import_koishi3.h.parse(reply);
|
|
1065
1064
|
}
|
|
1066
1065
|
if (config.debug) {
|
|
1067
|
-
logger.info(
|
|
1066
|
+
logger.info(`消息内容:
|
|
1068
1067
|
${JSON.stringify(sourceElements, null, 2)}`);
|
|
1069
|
-
logger.info(
|
|
1068
|
+
logger.info(`完整会话:
|
|
1070
1069
|
${JSON.stringify(session, null, 2)}`);
|
|
1071
1070
|
}
|
|
1072
1071
|
const newId = await getNextCaveId(ctx, getScopeQuery(session, config, false), reusableIds);
|
|
1073
1072
|
const { finalElementsForDb, mediaToSave } = await processMessageElements(sourceElements, newId, session, config, logger);
|
|
1074
1073
|
if (config.debug) {
|
|
1075
|
-
logger.info(
|
|
1074
|
+
logger.info(`数据库元素:
|
|
1076
1075
|
${JSON.stringify(finalElementsForDb, null, 2)}`);
|
|
1077
|
-
logger.info(`提取后待存媒体(mediaToSave):
|
|
1078
|
-
${JSON.stringify(mediaToSave, null, 2)}`);
|
|
1079
1076
|
}
|
|
1080
1077
|
if (finalElementsForDb.length === 0) return "无可添加内容";
|
|
1081
1078
|
const textHashesToStore = [];
|