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.
- package/lib/index.js +19 -29
- 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)
|
|
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
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
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([
|