koishi-plugin-best-cave 2.3.7 → 2.3.8

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.js +6 -36
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -409,42 +409,23 @@ __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, logger2 = new import_koishi.Logger("best-cave:transform")) {
412
+ async function transform(elements) {
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, logger2));
419
+ if (el.children) result.push(...await transform(el.children));
420
420
  continue;
421
421
  }
422
422
  if (type === "text" && el.attrs.content?.trim()) {
423
423
  result.push({ type: "text", content: el.attrs.content.trim() });
424
424
  } else if (type === "at" && el.attrs.id) {
425
425
  result.push({ type: "at", content: el.attrs.id });
426
- } else if (type === "forward") {
427
- const childrenToProcess = [...el.children || []];
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
- }
439
- }
440
- }
441
- }
442
- if (childrenToProcess.length > 0) {
443
- const transformedChildren = await transform(childrenToProcess, logger2);
444
- if (transformedChildren.length > 0) {
445
- result.push({ type: "forward", content: JSON.stringify(transformedChildren) });
446
- }
447
- }
426
+ } else if (type === "forward" && el.children?.length) {
427
+ const transformedChildren = await transform(el.children);
428
+ result.push({ type: "forward", content: JSON.stringify(transformedChildren) });
448
429
  } else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
449
430
  let fileIdentifier = el.attrs.src;
450
431
  if (fileIdentifier.startsWith("http")) {
@@ -456,7 +437,7 @@ async function processMessageElements(sourceElements, newId, session) {
456
437
  }
457
438
  result.push({ type, file: fileIdentifier });
458
439
  } else if (el.children) {
459
- result.push(...await transform(el.children, logger2));
440
+ result.push(...await transform(el.children));
460
441
  }
461
442
  }
462
443
  return result;
@@ -472,7 +453,6 @@ async function handleFileUploads(ctx, config, fileManager, logger2, reviewManage
472
453
  const imageHashesToStore = [];
473
454
  const allExistingImageHashes = hashManager ? await ctx.database.get("cave_hash", { type: { $ne: "simhash" } }) : [];
474
455
  const existingGlobalHashes = allExistingImageHashes.filter((h4) => h4.type === "phash_g");
475
- const existingQuadrantHashes = allExistingImageHashes.filter((h4) => h4.type.startsWith("phash_q"));
476
456
  for (const media of mediaToToSave) {
477
457
  const buffer = Buffer.from(await ctx.http.get(media.sourceUrl, { responseType: "arraybuffer", timeout: 3e4 }));
478
458
  downloadedMedia.push({ fileName: media.fileName, buffer });
@@ -487,16 +467,6 @@ async function handleFileUploads(ctx, config, fileManager, logger2, reviewManage
487
467
  return;
488
468
  }
489
469
  }
490
- const notifiedPartialCaves = /* @__PURE__ */ new Set();
491
- for (const newSubHash of Object.values(quadrantHashes)) {
492
- for (const existing of existingQuadrantHashes) {
493
- if (notifiedPartialCaves.has(existing.cave)) continue;
494
- if (newSubHash === existing.hash) {
495
- await session.send(`图片与回声洞(${existing.cave})局部相同`);
496
- notifiedPartialCaves.add(existing.cave);
497
- }
498
- }
499
- }
500
470
  imageHashesToStore.push({ hash: globalHash, type: "phash_g" });
501
471
  imageHashesToStore.push({ hash: quadrantHashes.q1, type: "phash_q1" });
502
472
  imageHashesToStore.push({ hash: quadrantHashes.q2, type: "phash_q2" });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞。支持丰富的媒体类型、内容查重、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.3.7",
4
+ "version": "2.3.8",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],