koishi-plugin-echo-cave 1.19.2 → 1.19.3
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.cjs +34 -14
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -350,6 +350,19 @@ async function convertFileUriToBase64(ctx, element) {
|
|
|
350
350
|
ctx.logger.error(`Failed to convert ${element.type} to base64: ${err}`);
|
|
351
351
|
return element;
|
|
352
352
|
}
|
|
353
|
+
} else if (element.type === "node") {
|
|
354
|
+
const processedContent = await Promise.all(
|
|
355
|
+
element.data.content.map(async (contentElement) => {
|
|
356
|
+
return await convertFileUriToBase64(ctx, contentElement);
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
return {
|
|
360
|
+
...element,
|
|
361
|
+
data: {
|
|
362
|
+
...element.data,
|
|
363
|
+
content: processedContent
|
|
364
|
+
}
|
|
365
|
+
};
|
|
353
366
|
}
|
|
354
367
|
return element;
|
|
355
368
|
}
|
|
@@ -420,23 +433,30 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
|
|
|
420
433
|
}
|
|
421
434
|
}
|
|
422
435
|
async function deleteMediaFilesFromMessage(ctx, content) {
|
|
436
|
+
async function processElement(element) {
|
|
437
|
+
if (element.type === "image" || element.type === "video" || element.type === "file" || element.type === "record") {
|
|
438
|
+
const fileUri = element.data?.file;
|
|
439
|
+
if (fileUri && fileUri.startsWith("file:///")) {
|
|
440
|
+
const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
|
|
441
|
+
try {
|
|
442
|
+
await import_node_fs.promises.access(filePath);
|
|
443
|
+
await import_node_fs.promises.unlink(filePath);
|
|
444
|
+
ctx.logger.info(`Deleted media file: ${filePath}`);
|
|
445
|
+
} catch (err) {
|
|
446
|
+
ctx.logger.warn(`Failed to delete media file: ${filePath}, error: ${err}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
} else if (element.type === "node" && element.data?.content) {
|
|
450
|
+
for (const contentElement of element.data.content) {
|
|
451
|
+
await processElement(contentElement);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
423
455
|
try {
|
|
424
456
|
const elements = JSON.parse(content);
|
|
425
457
|
const mediaElements = Array.isArray(elements) ? elements : [elements];
|
|
426
458
|
for (const element of mediaElements) {
|
|
427
|
-
|
|
428
|
-
const fileUri = element.data?.file;
|
|
429
|
-
if (fileUri && fileUri.startsWith("file:///")) {
|
|
430
|
-
const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
|
|
431
|
-
try {
|
|
432
|
-
await import_node_fs.promises.access(filePath);
|
|
433
|
-
await import_node_fs.promises.unlink(filePath);
|
|
434
|
-
ctx.logger.info(`Deleted media file: ${filePath}`);
|
|
435
|
-
} catch (err) {
|
|
436
|
-
ctx.logger.warn(`Failed to delete media file: ${filePath}, error: ${err}`);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
459
|
+
await processElement(element);
|
|
440
460
|
}
|
|
441
461
|
} catch (err) {
|
|
442
462
|
ctx.logger.error(`Failed to parse message content when deleting media: ${err}`);
|
|
@@ -721,7 +741,7 @@ async function sendCaveMsg(ctx, session, caveMsg, cfg) {
|
|
|
721
741
|
const last = content.at(-1);
|
|
722
742
|
const needsNewline = last?.type === "text";
|
|
723
743
|
content.unshift(createTextMsg(chosenTemplate.prefix + "\n"));
|
|
724
|
-
content.push(createTextMsg(`${needsNewline ? "\n
|
|
744
|
+
content.push(createTextMsg(`${needsNewline ? "\n" : ""}${chosenTemplate.suffix}`));
|
|
725
745
|
await session.onebot.sendGroupMsg(channelId, content);
|
|
726
746
|
}
|
|
727
747
|
function formatDate(date) {
|