koishi-plugin-best-cave 2.3.6 → 2.3.7
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 +15 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -409,14 +409,14 @@ __name(updateCooldownTimestamp, "updateCooldownTimestamp");
|
|
|
409
409
|
async function processMessageElements(sourceElements, newId, session) {
|
|
410
410
|
const mediaToSave = [];
|
|
411
411
|
let mediaIndex = 0;
|
|
412
|
-
async function transform(elements) {
|
|
412
|
+
async function transform(elements, logger2 = new import_koishi.Logger("best-cave:transform")) {
|
|
413
413
|
const result = [];
|
|
414
414
|
const typeMap = { "img": "image", "image": "image", "video": "video", "audio": "audio", "file": "file", "text": "text", "at": "at", "forward": "forward" };
|
|
415
415
|
const defaultExtMap = { "image": ".jpg", "video": ".mp4", "audio": ".mp3", "file": ".dat" };
|
|
416
416
|
for (const el of elements) {
|
|
417
417
|
const type = typeMap[el.type];
|
|
418
418
|
if (!type) {
|
|
419
|
-
if (el.children) result.push(...await transform(el.children));
|
|
419
|
+
if (el.children) result.push(...await transform(el.children, logger2));
|
|
420
420
|
continue;
|
|
421
421
|
}
|
|
422
422
|
if (type === "text" && el.attrs.content?.trim()) {
|
|
@@ -425,15 +425,22 @@ async function processMessageElements(sourceElements, newId, session) {
|
|
|
425
425
|
result.push({ type: "at", content: el.attrs.id });
|
|
426
426
|
} else if (type === "forward") {
|
|
427
427
|
const childrenToProcess = [...el.children || []];
|
|
428
|
-
if (Array.isArray(el.attrs.content)) {
|
|
429
|
-
for (const
|
|
430
|
-
if (
|
|
431
|
-
|
|
428
|
+
if (childrenToProcess.length === 0 && Array.isArray(el.attrs.content)) {
|
|
429
|
+
for (const node of el.attrs.content) {
|
|
430
|
+
if (!node) continue;
|
|
431
|
+
const contentToNormalize = node.message;
|
|
432
|
+
if (contentToNormalize) {
|
|
433
|
+
try {
|
|
434
|
+
childrenToProcess.push(...import_koishi.h.normalize(contentToNormalize));
|
|
435
|
+
} catch (error) {
|
|
436
|
+
logger2.warn(`跳过无法解析的转发节点内容: ${error}`);
|
|
437
|
+
childrenToProcess.push(import_koishi.h.text("[内容解析失败]"));
|
|
438
|
+
}
|
|
432
439
|
}
|
|
433
440
|
}
|
|
434
441
|
}
|
|
435
442
|
if (childrenToProcess.length > 0) {
|
|
436
|
-
const transformedChildren = await transform(childrenToProcess);
|
|
443
|
+
const transformedChildren = await transform(childrenToProcess, logger2);
|
|
437
444
|
if (transformedChildren.length > 0) {
|
|
438
445
|
result.push({ type: "forward", content: JSON.stringify(transformedChildren) });
|
|
439
446
|
}
|
|
@@ -449,7 +456,7 @@ async function processMessageElements(sourceElements, newId, session) {
|
|
|
449
456
|
}
|
|
450
457
|
result.push({ type, file: fileIdentifier });
|
|
451
458
|
} else if (el.children) {
|
|
452
|
-
result.push(...await transform(el.children));
|
|
459
|
+
result.push(...await transform(el.children, logger2));
|
|
453
460
|
}
|
|
454
461
|
}
|
|
455
462
|
return result;
|