koishi-plugin-best-cave 2.2.5 → 2.2.6
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 +11 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -697,7 +697,9 @@ var HashManager = class {
|
|
|
697
697
|
const combinedText = cave.elements.filter((el) => el.type === "text" && el.content).map((el) => el.content).join(" ");
|
|
698
698
|
if (combinedText) {
|
|
699
699
|
const textHash = this.generateTextSimhash(combinedText);
|
|
700
|
-
|
|
700
|
+
if (textHash) {
|
|
701
|
+
allHashes.push({ cave: cave.id, hash: textHash, type: "simhash" });
|
|
702
|
+
}
|
|
701
703
|
}
|
|
702
704
|
for (const el of cave.elements.filter((el2) => el2.type === "image" && el2.file)) {
|
|
703
705
|
try {
|
|
@@ -1040,14 +1042,16 @@ function apply(ctx, config) {
|
|
|
1040
1042
|
const combinedText = finalElementsForDb.filter((el) => el.type === "text" && el.content).map((el) => el.content).join(" ");
|
|
1041
1043
|
if (combinedText) {
|
|
1042
1044
|
const newSimhash = hashManager.generateTextSimhash(combinedText);
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1047
|
-
|
|
1045
|
+
if (newSimhash) {
|
|
1046
|
+
const existingTextHashes = await ctx.database.get("cave_hash", { type: "simhash" });
|
|
1047
|
+
for (const existing of existingTextHashes) {
|
|
1048
|
+
const similarity = hashManager.calculateSimilarity(newSimhash, existing.hash);
|
|
1049
|
+
if (similarity >= config.textThreshold) {
|
|
1050
|
+
return `文本与回声洞(${existing.cave})的相似度为 ${(similarity * 100).toFixed(2)}%,超过阈值`;
|
|
1051
|
+
}
|
|
1048
1052
|
}
|
|
1053
|
+
textHashesToStore.push({ hash: newSimhash, type: "simhash" });
|
|
1049
1054
|
}
|
|
1050
|
-
textHashesToStore.push({ hash: newSimhash, type: "simhash" });
|
|
1051
1055
|
}
|
|
1052
1056
|
}
|
|
1053
1057
|
const userName = (config.enableProfile ? await profileManager.getNickname(session.userId) : null) || session.username;
|