koishi-plugin-echo-cave 1.19.1 → 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.
Files changed (2) hide show
  1. package/lib/index.cjs +34 -20
  2. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -116,7 +116,6 @@ var require_zh_CN2 = __commonJS({
116
116
  description: "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E",
117
117
  messages: {
118
118
  noMsgQuoted: "\u{1F4A1} \u8BF7\u5F15\u7528\u4E00\u6761\u6D88\u606F\u540E\u518D\u4F7F\u7528\u6B64\u547D\u4EE4\uFF01",
119
- existingMsg: "\u267B\uFE0F \u8BE5\u6D88\u606F\u5DF2\u5B58\u5728\u4E8E\u56DE\u58F0\u6D1E\u7A74\u4E2D\uFF01",
120
119
  msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{0}",
121
120
  msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01"
122
121
  }
@@ -351,6 +350,19 @@ async function convertFileUriToBase64(ctx, element) {
351
350
  ctx.logger.error(`Failed to convert ${element.type} to base64: ${err}`);
352
351
  return element;
353
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
+ };
354
366
  }
355
367
  return element;
356
368
  }
@@ -421,23 +433,30 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
421
433
  }
422
434
  }
423
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
+ }
424
455
  try {
425
456
  const elements = JSON.parse(content);
426
457
  const mediaElements = Array.isArray(elements) ? elements : [elements];
427
458
  for (const element of mediaElements) {
428
- if (element.type === "image" || element.type === "video" || element.type === "file" || element.type === "record") {
429
- const fileUri = element.data?.file;
430
- if (fileUri && fileUri.startsWith("file:///")) {
431
- const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
432
- try {
433
- await import_node_fs.promises.access(filePath);
434
- await import_node_fs.promises.unlink(filePath);
435
- ctx.logger.info(`Deleted media file: ${filePath}`);
436
- } catch (err) {
437
- ctx.logger.warn(`Failed to delete media file: ${filePath}, error: ${err}`);
438
- }
439
- }
440
- }
459
+ await processElement(element);
441
460
  }
442
461
  } catch (err) {
443
462
  ctx.logger.error(`Failed to parse message content when deleting media: ${err}`);
@@ -540,11 +559,6 @@ async function addCave(ctx, session, cfg, userIds) {
540
559
  }
541
560
  content = JSON.stringify(await processMessageContent(ctx, msgJson, cfg));
542
561
  }
543
- await ctx.database.get("echo_cave_v2", { content }).then((existing) => {
544
- if (existing) {
545
- return session.text(".existingMsg");
546
- }
547
- });
548
562
  try {
549
563
  const result = await ctx.database.create("echo_cave_v2", {
550
564
  channelId,
@@ -727,7 +741,7 @@ async function sendCaveMsg(ctx, session, caveMsg, cfg) {
727
741
  const last = content.at(-1);
728
742
  const needsNewline = last?.type === "text";
729
743
  content.unshift(createTextMsg(chosenTemplate.prefix + "\n"));
730
- content.push(createTextMsg(`${needsNewline ? "\n\n" : ""}${chosenTemplate.suffix}`));
744
+ content.push(createTextMsg(`${needsNewline ? "\n" : ""}${chosenTemplate.suffix}`));
731
745
  await session.onebot.sendGroupMsg(channelId, content);
732
746
  }
733
747
  function formatDate(date) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.19.1",
4
+ "version": "1.19.3",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",