koishi-plugin-best-cave 2.3.11 → 2.3.13

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.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const usage = "\n<div style=\"border-radius: 10px; border: 1px so
7
7
  * @description 存储在数据库中的单个消息元素。
8
8
  */
9
9
  export interface StoredElement {
10
- type: 'text' | 'image' | 'video' | 'audio' | 'file' | 'at' | 'forward';
10
+ type: 'text' | 'image' | 'video' | 'audio' | 'file' | 'at' | 'forward' | 'reply';
11
11
  content?: string;
12
12
  file?: string;
13
13
  }
package/lib/index.js CHANGED
@@ -297,10 +297,16 @@ async function buildCaveMessage(cave, config, fileManager, logger2) {
297
297
  return Promise.all(elements.map(async (el) => {
298
298
  if (el.type === "text") return import_koishi.h.text(el.content);
299
299
  if (el.type === "at") return (0, import_koishi.h)("at", { id: el.content });
300
+ if (el.type === "reply") return (0, import_koishi.h)("reply", { id: el.content });
300
301
  if (el.type === "forward") {
301
302
  try {
302
- const children = JSON.parse(el.content || "[]");
303
- return (0, import_koishi.h)("forward", {}, await transformToH(children));
303
+ const forwardNodes = JSON.parse(el.content || "[]");
304
+ const messageNodes = await Promise.all(forwardNodes.map(async (node) => {
305
+ const author = (0, import_koishi.h)("author", { id: node.userId, name: node.userName });
306
+ const content = await transformToH(node.elements);
307
+ return (0, import_koishi.h)("message", {}, [author, ...content]);
308
+ }));
309
+ return (0, import_koishi.h)("forward", {}, messageNodes);
304
310
  } catch (error) {
305
311
  logger2.warn(`解析回声洞(${cave.id})合并转发内容失败:`, error);
306
312
  return import_koishi.h.text("[合并转发]");
@@ -409,7 +415,7 @@ async function processMessageElements(sourceElements, newId, session, config, lo
409
415
  let mediaIndex = 0;
410
416
  async function transform(elements) {
411
417
  const result = [];
412
- const typeMap = { "img": "image", "image": "image", "video": "video", "audio": "audio", "file": "file", "text": "text", "at": "at", "forward": "forward" };
418
+ const typeMap = { "img": "image", "image": "image", "video": "video", "audio": "audio", "file": "file", "text": "text", "at": "at", "forward": "forward", "reply": "reply" };
413
419
  const defaultExtMap = { "image": ".jpg", "video": ".mp4", "audio": ".mp3", "file": ".dat" };
414
420
  for (const el of elements) {
415
421
  const type = typeMap[el.type];
@@ -420,29 +426,29 @@ async function processMessageElements(sourceElements, newId, session, config, lo
420
426
  if (type === "text" && el.attrs.content?.trim()) {
421
427
  result.push({ type: "text", content: el.attrs.content.trim() });
422
428
  } else if (type === "at" && el.attrs.id) {
423
- if (config.debug) logger2.info(`发现 [at] 元素,ID: "${el.attrs.id}"`);
424
429
  result.push({ type: "at", content: el.attrs.id });
430
+ } else if (type === "reply" && el.attrs.id) {
431
+ result.push({ type: "reply", content: el.attrs.id });
425
432
  } else if (type === "forward" && Array.isArray(el.attrs.content)) {
426
- if (config.debug) logger2.info(`发现 [forward] 元素,开始解析 el.attrs.content...`);
427
- const allChildElements = [];
433
+ const forwardNodes = [];
428
434
  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.raw_message) {
432
- const parsedMessage = import_koishi.h.parse(node.raw_message);
433
- const transformedMessage = await transform(parsedMessage);
434
- allChildElements.push(...transformedMessage);
435
+ if (!node.message || !Array.isArray(node.message)) continue;
436
+ const userId = node.sender?.user_id;
437
+ const userName = node.sender?.nickname;
438
+ const contentElements = await transform(import_koishi.h.normalize(node.message));
439
+ if (contentElements.length > 0) {
440
+ forwardNodes.push({ userId, userName, elements: contentElements });
435
441
  }
436
442
  }
437
- result.push({ type: "forward", content: JSON.stringify(allChildElements) });
443
+ if (forwardNodes.length > 0) {
444
+ result.push({ type: "forward", content: JSON.stringify(forwardNodes) });
445
+ }
438
446
  } else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
439
447
  let fileIdentifier = el.attrs.src;
440
- if (config.debug) logger2.info(`发现 [${type}] 元素,src: "${fileIdentifier}"`);
441
448
  if (fileIdentifier.startsWith("http")) {
442
449
  const ext = path2.extname(el.attrs.file || "") || defaultExtMap[type];
443
450
  const currentMediaIndex = ++mediaIndex;
444
451
  const fileName = `${newId}_${currentMediaIndex}_${session.channelId || session.guildId}_${session.userId}${ext}`;
445
- if (config.debug) logger2.info(`[${type}] 是远程文件,已加入待保存列表。文件名: "${fileName}"`);
446
452
  mediaToSave.push({ sourceUrl: fileIdentifier, fileName });
447
453
  fileIdentifier = fileName;
448
454
  }
@@ -1064,18 +1070,16 @@ function apply(ctx, config) {
1064
1070
  sourceElements = import_koishi3.h.parse(reply);
1065
1071
  }
1066
1072
  if (config.debug) {
1067
- logger.info(`获取到的消息内容 (sourceElements):
1073
+ logger.info(`消息内容:
1068
1074
  ${JSON.stringify(sourceElements, null, 2)}`);
1069
- logger.info(`完整的会话对象 (session):
1075
+ logger.info(`完整会话:
1070
1076
  ${JSON.stringify(session, null, 2)}`);
1071
1077
  }
1072
1078
  const newId = await getNextCaveId(ctx, getScopeQuery(session, config, false), reusableIds);
1073
1079
  const { finalElementsForDb, mediaToSave } = await processMessageElements(sourceElements, newId, session, config, logger);
1074
1080
  if (config.debug) {
1075
- logger.info(`提取后数据库元素(finalElementsForDb):
1081
+ logger.info(`数据库元素:
1076
1082
  ${JSON.stringify(finalElementsForDb, null, 2)}`);
1077
- logger.info(`提取后待存媒体(mediaToSave):
1078
- ${JSON.stringify(mediaToSave, null, 2)}`);
1079
1083
  }
1080
1084
  if (finalElementsForDb.length === 0) return "无可添加内容";
1081
1085
  const textHashesToStore = [];
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.11",
4
+ "version": "2.3.13",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],