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.
Files changed (2) hide show
  1. package/lib/index.js +11 -7
  2. 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
- allHashes.push({ cave: cave.id, hash: textHash, type: "simhash" });
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
- const existingTextHashes = await ctx.database.get("cave_hash", { type: "simhash" });
1044
- for (const existing of existingTextHashes) {
1045
- const similarity = hashManager.calculateSimilarity(newSimhash, existing.hash);
1046
- if (similarity >= config.textThreshold) {
1047
- return `文本与回声洞(${existing.cave})的相似度为 ${(similarity * 100).toFixed(2)}%,超过阈值`;
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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞。支持丰富的媒体类型、内容查重、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.2.5",
4
+ "version": "2.2.6",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],