koishi-plugin-best-cave 2.3.9 → 2.3.10

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.
@@ -1,6 +1,5 @@
1
1
  import { Context, Logger } from 'koishi';
2
2
  import { FileManager } from './FileManager';
3
- import { HashManager } from './HashManager';
4
3
  import { Config } from './index';
5
4
  /**
6
5
  * @class DataManager
@@ -11,16 +10,14 @@ export declare class DataManager {
11
10
  private config;
12
11
  private fileManager;
13
12
  private logger;
14
- private hashManager;
15
13
  /**
16
14
  * @constructor
17
15
  * @param ctx Koishi 上下文,用于数据库操作。
18
16
  * @param config 插件配置。
19
17
  * @param fileManager 文件管理器实例。
20
18
  * @param logger 日志记录器实例。
21
- * @param hashManager 哈希管理器实例,用于增量更新哈希。
22
19
  */
23
- constructor(ctx: Context, config: Config, fileManager: FileManager, logger: Logger, hashManager: HashManager | null);
20
+ constructor(ctx: Context, config: Config, fileManager: FileManager, logger: Logger);
24
21
  /**
25
22
  * @description 注册 `.export` 和 `.import` 子命令。
26
23
  * @param cave - 主 `cave` 命令实例。
package/lib/index.js CHANGED
@@ -216,14 +216,12 @@ var DataManager = class {
216
216
  * @param config 插件配置。
217
217
  * @param fileManager 文件管理器实例。
218
218
  * @param logger 日志记录器实例。
219
- * @param hashManager 哈希管理器实例,用于增量更新哈希。
220
219
  */
221
- constructor(ctx, config, fileManager, logger2, hashManager) {
220
+ constructor(ctx, config, fileManager, logger2) {
222
221
  this.ctx = ctx;
223
222
  this.config = config;
224
223
  this.fileManager = fileManager;
225
224
  this.logger = logger2;
226
- this.hashManager = hashManager;
227
225
  }
228
226
  static {
229
227
  __name(this, "DataManager");
@@ -415,37 +413,40 @@ async function processMessageElements(sourceElements, newId, session, config, lo
415
413
  const defaultExtMap = { "image": ".jpg", "video": ".mp4", "audio": ".mp3", "file": ".dat" };
416
414
  for (const el of elements) {
417
415
  const type = typeMap[el.type];
418
- if (config.debug) logger2.info(`正在处理元素 <${el.type}>, 映射类型: ${type || "无"}`);
419
416
  if (!type) {
420
417
  if (el.children) result.push(...await transform(el.children));
421
418
  continue;
422
419
  }
423
420
  if (type === "text" && el.attrs.content?.trim()) {
424
- const content = el.attrs.content.trim();
425
- if (config.debug) logger2.info(`发现 [text] 元素,内容: "${content}"`);
426
- result.push({ type: "text", content });
421
+ result.push({ type: "text", content: el.attrs.content.trim() });
427
422
  } else if (type === "at" && el.attrs.id) {
428
423
  if (config.debug) logger2.info(`发现 [at] 元素,ID: "${el.attrs.id}"`);
429
424
  result.push({ type: "at", content: el.attrs.id });
430
- } else if (type === "forward" && el.children?.length) {
431
- if (config.debug) logger2.info(`发现 [forward] 元素,开始递归解析子元素...`);
432
- const transformedChildren = await transform(el.children);
433
- result.push({ type: "forward", content: JSON.stringify(transformedChildren) });
425
+ } else if (type === "forward" && Array.isArray(el.attrs.content)) {
426
+ if (config.debug) logger2.info(`发现 [forward] 元素,开始解析 el.attrs.content...`);
427
+ const allChildElements = [];
428
+ for (const node of el.attrs.content) {
429
+ const senderInfo = `${node.sender?.nickname || node.sender?.user_id}:`;
430
+ allChildElements.push({ type: "text", content: senderInfo });
431
+ if (node.message) {
432
+ const parsedMessage = import_koishi.h.parse(node.message);
433
+ const transformedMessage = await transform(parsedMessage);
434
+ allChildElements.push(...transformedMessage);
435
+ }
436
+ }
437
+ result.push({ type: "forward", content: JSON.stringify(allChildElements) });
434
438
  } else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
435
439
  let fileIdentifier = el.attrs.src;
436
440
  if (config.debug) logger2.info(`发现 [${type}] 元素,src: "${fileIdentifier}"`);
437
441
  if (fileIdentifier.startsWith("http")) {
438
442
  const ext = path2.extname(el.attrs.file || "") || defaultExtMap[type];
439
443
  const currentMediaIndex = ++mediaIndex;
440
- const fileName = `${newId}_${currentMediaIndex}_${session.channelId || "private"}_${session.userId}${ext}`;
441
- if (config.debug) logger2.info(`[${type}] 是远程文件,文件名: "${fileName}"`);
444
+ const fileName = `${newId}_${currentMediaIndex}_${session.channelId || session.guildId}_${session.userId}${ext}`;
445
+ if (config.debug) logger2.info(`[${type}] 是远程文件,已加入待保存列表。文件名: "${fileName}"`);
442
446
  mediaToSave.push({ sourceUrl: fileIdentifier, fileName });
443
447
  fileIdentifier = fileName;
444
448
  }
445
449
  result.push({ type, file: fileIdentifier });
446
- } else if (el.children) {
447
- if (config.debug) logger2.info(`元素 <${el.type}> 无直接内容,递归其子元素...`);
448
- result.push(...await transform(el.children));
449
450
  }
450
451
  }
451
452
  return result;
@@ -1026,7 +1027,7 @@ function apply(ctx, config) {
1026
1027
  const profileManager = config.enableName ? new NameManager(ctx) : null;
1027
1028
  const reviewManager = config.enablePend ? new PendManager(ctx, config, fileManager, logger, reusableIds) : null;
1028
1029
  const hashManager = config.enableSimilarity ? new HashManager(ctx, config, logger, fileManager) : null;
1029
- const dataManager = config.enableIO ? new DataManager(ctx, config, fileManager, logger, hashManager) : null;
1030
+ const dataManager = config.enableIO ? new DataManager(ctx, config, fileManager, logger) : null;
1030
1031
  const cave = ctx.command("cave", "回声洞").option("add", "-a <content:text> 添加回声洞").option("view", "-g <id:posint> 查看指定回声洞").option("delete", "-r <id:posint> 删除指定回声洞").option("list", "-l 查询投稿统计").usage("随机抽取一条已添加的回声洞。").action(async ({ session, options }) => {
1031
1032
  if (options.add) return session.execute(`cave.add ${options.add}`);
1032
1033
  if (options.view) return session.execute(`cave.view ${options.view}`);
@@ -1052,22 +1053,17 @@ function apply(ctx, config) {
1052
1053
  cave.subcommand(".add [content:text]", "添加回声洞").usage("添加一条回声洞。可直接发送内容,也可回复或引用消息。").action(async ({ session }, content) => {
1053
1054
  try {
1054
1055
  let sourceElements;
1055
- let sourceOrigin = "";
1056
1056
  if (session.quote?.elements) {
1057
1057
  sourceElements = session.quote.elements;
1058
- sourceOrigin = "引用(quote)";
1059
1058
  } else if (content?.trim()) {
1060
1059
  sourceElements = import_koishi3.h.parse(content);
1061
- sourceOrigin = `指令参数(content)`;
1062
1060
  } else {
1063
1061
  await session.send("请在一分钟内发送你要添加的内容");
1064
1062
  const reply = await session.prompt(6e4);
1065
1063
  if (!reply) return "等待操作超时";
1066
1064
  sourceElements = import_koishi3.h.parse(reply);
1067
- sourceOrigin = `用户回复(prompt)`;
1068
1065
  }
1069
1066
  if (config.debug) {
1070
- logger.info(`内容来源: ${sourceOrigin}`);
1071
1067
  logger.info(`获取到的消息内容 (sourceElements):
1072
1068
  ${JSON.stringify(sourceElements, null, 2)}`);
1073
1069
  logger.info(`完整的会话对象 (session):
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.9",
4
+ "version": "2.3.10",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],