koishi-plugin-best-cave 2.3.13 → 2.3.15
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 +9 -1
- package/lib/index.js +21 -4
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ import { CaveHashObject } from './HashManager';
|
|
|
3
3
|
export declare const name = "best-cave";
|
|
4
4
|
export declare const inject: string[];
|
|
5
5
|
export declare const usage = "\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #4a6ee0;\">\uD83D\uDCCC \u63D2\u4EF6\u8BF4\u660E</h2>\n <p>\uD83D\uDCD6 <strong>\u4F7F\u7528\u6587\u6863</strong>\uFF1A\u8BF7\u70B9\u51FB\u5DE6\u4E0A\u89D2\u7684 <strong>\u63D2\u4EF6\u4E3B\u9875</strong> \u67E5\u770B\u63D2\u4EF6\u4F7F\u7528\u6587\u6863</p>\n <p>\uD83D\uDD0D <strong>\u66F4\u591A\u63D2\u4EF6</strong>\uFF1A\u53EF\u8BBF\u95EE <a href=\"https://github.com/YisRime\" style=\"color:#4a6ee0;text-decoration:none;\">\u82E1\u6DDE\u7684 GitHub</a> \u67E5\u770B\u672C\u4EBA\u7684\u6240\u6709\u63D2\u4EF6</p>\n</div>\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #e0574a;\">\u2764\uFE0F \u652F\u6301\u4E0E\u53CD\u9988</h2>\n <p>\uD83C\uDF1F \u559C\u6B22\u8FD9\u4E2A\u63D2\u4EF6\uFF1F\u8BF7\u5728 <a href=\"https://github.com/YisRime\" style=\"color:#e0574a;text-decoration:none;\">GitHub</a> \u4E0A\u7ED9\u6211\u4E00\u4E2A Star\uFF01</p>\n <p>\uD83D\uDC1B \u9047\u5230\u95EE\u9898\uFF1F\u8BF7\u901A\u8FC7 <strong>Issues</strong> \u63D0\u4EA4\u53CD\u9988\uFF0C\u6216\u52A0\u5165 QQ \u7FA4 <a href=\"https://qm.qq.com/q/PdLMx9Jowq\" style=\"color:#e0574a;text-decoration:none;\"><strong>855571375</strong></a> \u8FDB\u884C\u4EA4\u6D41</p>\n</div>\n";
|
|
6
|
+
/**
|
|
7
|
+
* @description 存储在合并转发中的单个节点的数据结构。
|
|
8
|
+
*/
|
|
9
|
+
export interface ForwardNode {
|
|
10
|
+
userId: string;
|
|
11
|
+
userName: string;
|
|
12
|
+
elements: StoredElement[];
|
|
13
|
+
}
|
|
6
14
|
/**
|
|
7
15
|
* @description 存储在数据库中的单个消息元素。
|
|
8
16
|
*/
|
|
9
17
|
export interface StoredElement {
|
|
10
18
|
type: 'text' | 'image' | 'video' | 'audio' | 'file' | 'at' | 'forward' | 'reply';
|
|
11
|
-
content?: string;
|
|
19
|
+
content?: string | ForwardNode[];
|
|
12
20
|
file?: string;
|
|
13
21
|
}
|
|
14
22
|
/**
|
package/lib/index.js
CHANGED
|
@@ -300,7 +300,7 @@ async function buildCaveMessage(cave, config, fileManager, logger2) {
|
|
|
300
300
|
if (el.type === "reply") return (0, import_koishi.h)("reply", { id: el.content });
|
|
301
301
|
if (el.type === "forward") {
|
|
302
302
|
try {
|
|
303
|
-
const forwardNodes =
|
|
303
|
+
const forwardNodes = Array.isArray(el.content) ? el.content : [];
|
|
304
304
|
const messageNodes = await Promise.all(forwardNodes.map(async (node) => {
|
|
305
305
|
const author = (0, import_koishi.h)("author", { id: node.userId, name: node.userName });
|
|
306
306
|
const content = await transformToH(node.elements);
|
|
@@ -435,13 +435,30 @@ async function processMessageElements(sourceElements, newId, session, config, lo
|
|
|
435
435
|
if (!node.message || !Array.isArray(node.message)) continue;
|
|
436
436
|
const userId = node.sender?.user_id;
|
|
437
437
|
const userName = node.sender?.nickname;
|
|
438
|
-
const
|
|
438
|
+
const elementsToProcess = node.message.map((segment) => {
|
|
439
|
+
const { type: type2, data } = segment;
|
|
440
|
+
const attrs = { ...data };
|
|
441
|
+
if (type2 === "text" && typeof data.text !== "undefined") {
|
|
442
|
+
attrs.content = data.text;
|
|
443
|
+
delete attrs.text;
|
|
444
|
+
}
|
|
445
|
+
if (type2 === "at" && typeof data.qq !== "undefined") {
|
|
446
|
+
attrs.id = data.qq;
|
|
447
|
+
delete attrs.qq;
|
|
448
|
+
}
|
|
449
|
+
if (["image", "video", "audio"].includes(type2) && typeof data.url !== "undefined") {
|
|
450
|
+
attrs.src = data.url;
|
|
451
|
+
delete attrs.url;
|
|
452
|
+
}
|
|
453
|
+
return (0, import_koishi.h)(type2, attrs);
|
|
454
|
+
});
|
|
455
|
+
const contentElements = await transform(elementsToProcess);
|
|
439
456
|
if (contentElements.length > 0) {
|
|
440
457
|
forwardNodes.push({ userId, userName, elements: contentElements });
|
|
441
458
|
}
|
|
442
459
|
}
|
|
443
460
|
if (forwardNodes.length > 0) {
|
|
444
|
-
result.push({ type: "forward", content:
|
|
461
|
+
result.push({ type: "forward", content: forwardNodes });
|
|
445
462
|
}
|
|
446
463
|
} else if (["image", "video", "audio", "file"].includes(type) && el.attrs.src) {
|
|
447
464
|
let fileIdentifier = el.attrs.src;
|
|
@@ -1084,7 +1101,7 @@ ${JSON.stringify(finalElementsForDb, null, 2)}`);
|
|
|
1084
1101
|
if (finalElementsForDb.length === 0) return "无可添加内容";
|
|
1085
1102
|
const textHashesToStore = [];
|
|
1086
1103
|
if (hashManager) {
|
|
1087
|
-
const combinedText = finalElementsForDb.filter((el) => el.type === "text" && el.content).map((el) => el.content).join(" ");
|
|
1104
|
+
const combinedText = finalElementsForDb.filter((el) => el.type === "text" && typeof el.content === "string").map((el) => el.content).join(" ");
|
|
1088
1105
|
if (combinedText) {
|
|
1089
1106
|
const newSimhash = hashManager.generateTextSimhash(combinedText);
|
|
1090
1107
|
if (newSimhash) {
|