koishi-plugin-echo-cave 1.24.19 → 1.25.1
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/config/config.d.ts +2 -0
- package/lib/index.cjs +102 -3
- package/lib/utils/msg/message-listener.d.ts +2 -0
- package/package.json +1 -1
package/lib/config/config.d.ts
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -92,6 +92,39 @@ function parseUserIds(userIds) {
|
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
// src/utils/msg/message-listener.ts
|
|
96
|
+
async function listenForUserMessage(ctx, session, prompt, timeout, onMessage, onTimeout) {
|
|
97
|
+
const userId = session.userId;
|
|
98
|
+
const channelId = session.channelId;
|
|
99
|
+
const promptMessageId = await session.onebot.sendGroupMsg(channelId, prompt);
|
|
100
|
+
let timeoutId;
|
|
101
|
+
const listener = async (msgSession) => {
|
|
102
|
+
if (msgSession.userId === userId && msgSession.channelId === channelId) {
|
|
103
|
+
clearTimeout(timeoutId);
|
|
104
|
+
const shouldContinue = await onMessage(msgSession.content);
|
|
105
|
+
if (!shouldContinue) {
|
|
106
|
+
ctx.off("message", listener);
|
|
107
|
+
try {
|
|
108
|
+
await session.onebot.deleteMsg(promptMessageId);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
}
|
|
111
|
+
cancelTimeout();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
ctx.on("message", listener);
|
|
116
|
+
const cancelTimeout = ctx.setTimeout(async () => {
|
|
117
|
+
ctx.off("message", listener);
|
|
118
|
+
if (onTimeout) {
|
|
119
|
+
await onTimeout();
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await session.onebot.deleteMsg(promptMessageId);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
}
|
|
125
|
+
}, timeout);
|
|
126
|
+
}
|
|
127
|
+
|
|
95
128
|
// src/utils/media/media-helper.ts
|
|
96
129
|
var import_axios = __toESM(require("axios"), 1);
|
|
97
130
|
var import_node_fs = require("node:fs");
|
|
@@ -377,6 +410,7 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
377
410
|
}
|
|
378
411
|
let content;
|
|
379
412
|
let type;
|
|
413
|
+
let forwardUsers = [];
|
|
380
414
|
if (quote.elements[0].type === "forward") {
|
|
381
415
|
type = "forward";
|
|
382
416
|
const message = await reconstructForwardMsg(
|
|
@@ -386,6 +420,20 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
386
420
|
cfg
|
|
387
421
|
);
|
|
388
422
|
content = JSON.stringify(message);
|
|
423
|
+
const userMap = /* @__PURE__ */ new Map();
|
|
424
|
+
for (const node of message) {
|
|
425
|
+
if (node.type === "node" && node.data) {
|
|
426
|
+
const userId2 = String(node.data.user_id);
|
|
427
|
+
const nickname = node.data.nickname;
|
|
428
|
+
if (userId2 && nickname && !userMap.has(userId2)) {
|
|
429
|
+
userMap.set(userId2, nickname);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
forwardUsers = Array.from(userMap.entries()).map(([userId2, nickname]) => ({
|
|
434
|
+
userId: userId2,
|
|
435
|
+
nickname
|
|
436
|
+
}));
|
|
389
437
|
} else {
|
|
390
438
|
type = "msg";
|
|
391
439
|
const message = (await session.onebot.getMsg(messageId)).message;
|
|
@@ -401,6 +449,50 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
401
449
|
}
|
|
402
450
|
content = JSON.stringify(await processMessageContent(ctx, msgJson, cfg));
|
|
403
451
|
}
|
|
452
|
+
if (type === "forward" && forwardUsers.length > 0 && parsedUserIds.length === 0 && cfg.enableForwardUserSelection) {
|
|
453
|
+
const userSelectionPromise = new Promise((resolve) => {
|
|
454
|
+
let prompt = session.text(".selectRelatedUsers");
|
|
455
|
+
forwardUsers.forEach((user, index) => {
|
|
456
|
+
prompt += `
|
|
457
|
+
${index + 1}: ${user.nickname}`;
|
|
458
|
+
});
|
|
459
|
+
prompt += `
|
|
460
|
+
${session.text(".selectInstruction")}`;
|
|
461
|
+
listenForUserMessage(
|
|
462
|
+
ctx,
|
|
463
|
+
session,
|
|
464
|
+
prompt,
|
|
465
|
+
cfg.forwardSelectTimeout * 1e3,
|
|
466
|
+
// Convert seconds to milliseconds
|
|
467
|
+
async (message) => {
|
|
468
|
+
const trimmedMessage = message.trim();
|
|
469
|
+
let selectedUsers = [];
|
|
470
|
+
if (trimmedMessage.toLowerCase() === "all") {
|
|
471
|
+
selectedUsers = forwardUsers.map((user) => user.userId);
|
|
472
|
+
} else if (trimmedMessage.toLowerCase() === "skip") {
|
|
473
|
+
selectedUsers = [];
|
|
474
|
+
} else {
|
|
475
|
+
const indices = trimmedMessage.split(/\s+/).map((index) => parseInt(index.trim()) - 1);
|
|
476
|
+
const validIndices = indices.filter(
|
|
477
|
+
(index) => index >= 0 && index < forwardUsers.length
|
|
478
|
+
);
|
|
479
|
+
if (validIndices.length > 0) {
|
|
480
|
+
selectedUsers = validIndices.map((index) => forwardUsers[index].userId);
|
|
481
|
+
} else {
|
|
482
|
+
await session.send(session.text(".invalidSelection"));
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
resolve(selectedUsers);
|
|
487
|
+
return false;
|
|
488
|
+
},
|
|
489
|
+
async () => {
|
|
490
|
+
resolve([]);
|
|
491
|
+
}
|
|
492
|
+
);
|
|
493
|
+
});
|
|
494
|
+
parsedUserIds = await userSelectionPromise;
|
|
495
|
+
}
|
|
404
496
|
try {
|
|
405
497
|
const result = await ctx.database.create("echo_cave_v2", {
|
|
406
498
|
channelId,
|
|
@@ -966,7 +1058,10 @@ var zh_CN_default = {
|
|
|
966
1058
|
messages: {
|
|
967
1059
|
noMsgQuoted: "\u{1F4A1} \u8BF7\u5F15\u7528\u4E00\u6761\u6D88\u606F\u540E\u518D\u4F7F\u7528\u6B64\u547D\u4EE4\uFF01",
|
|
968
1060
|
msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{0}",
|
|
969
|
-
msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01"
|
|
1061
|
+
msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01",
|
|
1062
|
+
selectRelatedUsers: "\u8BF7\u9009\u62E9\u8981\u5173\u8054\u7684\u7528\u6237\uFF08\u4EE5\u7A7A\u683C\u5206\u9694\u5E8F\u53F7\uFF0C\u8F93\u5165'all'\u9009\u62E9\u5168\u90E8\uFF09\uFF1A",
|
|
1063
|
+
selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all \u6216 skip",
|
|
1064
|
+
invalidSelection: "\u274C \u65E0\u6548\u7684\u9009\u62E9\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\uFF01"
|
|
970
1065
|
}
|
|
971
1066
|
},
|
|
972
1067
|
"cave.drop": {
|
|
@@ -1056,7 +1151,9 @@ var zh_CN_default2 = {
|
|
|
1056
1151
|
maxRecordSize: "\u6700\u5927\u5F55\u97F3\u5927\u5C0F (MB)",
|
|
1057
1152
|
useBase64ForMedia: "\u662F\u5426\u4F7F\u7528 Base64 \u7F16\u7801\u53D1\u9001\u5A92\u4F53\u6587\u4EF6\uFF0C\u5F00\u542F\u540E\u5C06\u8BFB\u53D6 base64 \u7F16\u7801\u53D1\u9001\u800C\u4E0D\u662F\u4F7F\u7528 file uri",
|
|
1058
1153
|
sendAllAsForwardMsg: "\u662F\u5426\u5C06\u6240\u6709\u6D88\u606F\u4EE5\u8F6C\u53D1\u6D88\u606F\u5F62\u5F0F\u53D1\u9001\uFF0C\u5F00\u542F\u540E\u666E\u901A\u6D88\u606F\u4E5F\u4F1A\u8F6C\u6362\u4E3A\u8F6C\u53D1\u6D88\u606F\u683C\u5F0F",
|
|
1059
|
-
rankingTopCount: "\u6392\u884C\u699C\u663E\u793A\u7684\u7528\u6237\u6570\u91CF"
|
|
1154
|
+
rankingTopCount: "\u6392\u884C\u699C\u663E\u793A\u7684\u7528\u6237\u6570\u91CF",
|
|
1155
|
+
forwardSelectTimeout: "\u5408\u5E76\u8F6C\u53D1\u6D88\u606F\u9009\u62E9\u5173\u8054\u7528\u6237\u7684\u8D85\u65F6\u65F6\u95F4 (\u79D2)",
|
|
1156
|
+
enableForwardUserSelection: "\u662F\u5426\u542F\u7528\u5408\u5E76\u8F6C\u53D1\u6D88\u606F\u7684\u5173\u8054\u7528\u6237\u9009\u62E9\u529F\u80FD"
|
|
1060
1157
|
};
|
|
1061
1158
|
|
|
1062
1159
|
// src/config/config.ts
|
|
@@ -1073,7 +1170,9 @@ var Config = import_koishi2.Schema.object({
|
|
|
1073
1170
|
maxRecordSize: import_koishi2.Schema.number().default(512),
|
|
1074
1171
|
useBase64ForMedia: import_koishi2.Schema.boolean().default(false),
|
|
1075
1172
|
sendAllAsForwardMsg: import_koishi2.Schema.boolean().default(false),
|
|
1076
|
-
rankingTopCount: import_koishi2.Schema.number().default(10)
|
|
1173
|
+
rankingTopCount: import_koishi2.Schema.number().default(10),
|
|
1174
|
+
forwardSelectTimeout: import_koishi2.Schema.number().default(20),
|
|
1175
|
+
enableForwardUserSelection: import_koishi2.Schema.boolean().default(true)
|
|
1077
1176
|
}).i18n({
|
|
1078
1177
|
"zh-CN": zh_CN_default2
|
|
1079
1178
|
});
|