koishi-plugin-best-cave 1.5.1 → 1.5.2

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 +19 -29
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1345,7 +1345,7 @@ async function apply(ctx, config) {
1345
1345
  const inputContent = content.length > 0 ? content.join("\n") : await (async () => {
1346
1346
  await sendMessage(session, "commands.cave.add.noContent", [], true, 6e4);
1347
1347
  const reply = await session.prompt({ timeout: 6e4 });
1348
- if (!reply) throw new Error(session.text("commands.cave.add.operationTimeout"));
1348
+ if (!reply) sendMessage(session, "commands.cave.add.operationTimeout", [], true);
1349
1349
  return reply;
1350
1350
  })();
1351
1351
  caveId = await idManager.getNextId();
@@ -1430,34 +1430,24 @@ async function apply(ctx, config) {
1430
1430
  elements: cleanElementsForSave(newCave.elements, false)
1431
1431
  });
1432
1432
  if (config2.enableImageDuplicate || config2.enableTextDuplicate) {
1433
- try {
1434
- const duplicateResults = await contentHashManager.findDuplicates({
1435
- images: config2.enableImageDuplicate ? imageBuffers : void 0,
1436
- texts: config2.enableTextDuplicate ? textParts.filter((p) => p.type === "text").map((p) => p.content) : void 0
1437
- }, {
1438
- image: config2.imageDuplicateThreshold,
1439
- text: config2.textDuplicateThreshold
1440
- });
1441
- for (const result of duplicateResults) {
1442
- if (!result) continue;
1443
- const originalCave = data.find((item) => item.cave_id === result.caveId);
1444
- if (!originalCave) continue;
1445
- await idManager.markDeleted(caveId);
1446
- const duplicateMessage = session.text(
1447
- "commands.cave.error.similarDuplicateFound",
1448
- [(result.similarity * 100).toFixed(1)]
1449
- );
1450
- await session.send(duplicateMessage + await buildMessage(originalCave, resourceDir, session));
1451
- throw new Error("duplicate_found");
1452
- }
1453
- } catch (error) {
1454
- if (error.message !== "duplicate_found") {
1455
- await idManager.markDeleted(caveId);
1456
- }
1457
- if (error.message === "duplicate_found") {
1458
- return "";
1459
- }
1460
- return sendMessage(session, "commands.cave.error.addFailed", [], true);
1433
+ const duplicateResults = await contentHashManager.findDuplicates({
1434
+ images: config2.enableImageDuplicate ? imageBuffers : void 0,
1435
+ texts: config2.enableTextDuplicate ? textParts.filter((p) => p.type === "text").map((p) => p.content) : void 0
1436
+ }, {
1437
+ image: config2.imageDuplicateThreshold,
1438
+ text: config2.textDuplicateThreshold
1439
+ });
1440
+ for (const result of duplicateResults) {
1441
+ if (!result) continue;
1442
+ const originalCave = data.find((item) => item.cave_id === result.caveId);
1443
+ if (!originalCave) continue;
1444
+ await idManager.markDeleted(caveId);
1445
+ const duplicateMessage = session.text(
1446
+ "commands.cave.error.similarDuplicateFound",
1447
+ [(result.similarity * 100).toFixed(1)]
1448
+ );
1449
+ await session.send(duplicateMessage + await buildMessage(originalCave, resourceDir, session));
1450
+ throw new Error("duplicate_found");
1461
1451
  }
1462
1452
  }
1463
1453
  await Promise.all([
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "最好的 cave 插件,可开关的审核系统,可引用添加,支持图文混合内容,可查阅投稿列表,完美复刻你的 .cave 体验!",
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],