koishi-plugin-echo-cave 1.25.2 → 1.26.0
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.cjs +45 -40
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -405,6 +405,7 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
+
let selectedUsersWithNames = [];
|
|
408
409
|
let content;
|
|
409
410
|
let type;
|
|
410
411
|
let forwardUsers = [];
|
|
@@ -447,49 +448,53 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
447
448
|
content = JSON.stringify(await processMessageContent(ctx, msgJson, cfg));
|
|
448
449
|
}
|
|
449
450
|
if (type === "forward" && forwardUsers.length > 0 && parsedUserIds.length === 0 && cfg.enableForwardUserSelection) {
|
|
450
|
-
const userSelectionPromise = new Promise(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
451
|
+
const userSelectionPromise = new Promise(
|
|
452
|
+
(resolve) => {
|
|
453
|
+
let prompt = session.text(".selectRelatedUsers");
|
|
454
|
+
forwardUsers.forEach((user, index) => {
|
|
455
|
+
prompt += `
|
|
454
456
|
${index + 1}: ${user.nickname}`;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
+
});
|
|
458
|
+
prompt += `
|
|
457
459
|
${session.text(".selectInstruction")}`;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
} else {
|
|
472
|
-
const indices = trimmedMessage.split(/\s+/).map((index) => parseInt(index.trim()) - 1);
|
|
473
|
-
const validIndices = indices.filter(
|
|
474
|
-
(index) => index >= 0 && index < forwardUsers.length
|
|
475
|
-
);
|
|
476
|
-
if (validIndices.length > 0) {
|
|
477
|
-
selectedUsers = validIndices.map((index) => forwardUsers[index].userId);
|
|
460
|
+
listenForUserMessage(
|
|
461
|
+
ctx,
|
|
462
|
+
session,
|
|
463
|
+
prompt,
|
|
464
|
+
cfg.forwardSelectTimeout * 1e3,
|
|
465
|
+
// Convert seconds to milliseconds
|
|
466
|
+
async (message) => {
|
|
467
|
+
const trimmedMessage = message.trim();
|
|
468
|
+
let selectedUsers = [];
|
|
469
|
+
if (trimmedMessage.toLowerCase() === "all") {
|
|
470
|
+
selectedUsers = [...forwardUsers];
|
|
471
|
+
} else if (trimmedMessage.toLowerCase() === "skip") {
|
|
472
|
+
selectedUsers = [];
|
|
478
473
|
} else {
|
|
479
|
-
|
|
480
|
-
|
|
474
|
+
const indices = trimmedMessage.split(/\s+/).map((index) => parseInt(index.trim()) - 1);
|
|
475
|
+
const validIndices = indices.filter(
|
|
476
|
+
(index) => index >= 0 && index < forwardUsers.length
|
|
477
|
+
);
|
|
478
|
+
if (validIndices.length > 0) {
|
|
479
|
+
selectedUsers = validIndices.map((index) => forwardUsers[index]);
|
|
480
|
+
} else {
|
|
481
|
+
await session.send(session.text(".invalidSelection"));
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
481
484
|
}
|
|
485
|
+
resolve(selectedUsers);
|
|
486
|
+
return false;
|
|
487
|
+
},
|
|
488
|
+
async () => {
|
|
489
|
+
resolve([]);
|
|
482
490
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
resolve([]);
|
|
488
|
-
}
|
|
489
|
-
);
|
|
490
|
-
});
|
|
491
|
-
parsedUserIds = await userSelectionPromise;
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
selectedUsersWithNames = await userSelectionPromise;
|
|
492
495
|
}
|
|
496
|
+
const finalParsedUserIds = selectedUsersWithNames.map((user) => user.userId);
|
|
497
|
+
const relatedUsersFormatted = selectedUsersWithNames.map((user) => user.nickname).join(", ");
|
|
493
498
|
try {
|
|
494
499
|
const result = await ctx.database.create("echo_cave_v2", {
|
|
495
500
|
channelId,
|
|
@@ -498,9 +503,9 @@ ${session.text(".selectInstruction")}`;
|
|
|
498
503
|
originUserId: quote.user.id,
|
|
499
504
|
type,
|
|
500
505
|
content,
|
|
501
|
-
relatedUsers:
|
|
506
|
+
relatedUsers: finalParsedUserIds
|
|
502
507
|
});
|
|
503
|
-
return session.text(".msgSaved",
|
|
508
|
+
return session.text(".msgSaved", { id: result.id, relatedUsers: relatedUsersFormatted });
|
|
504
509
|
} catch (error) {
|
|
505
510
|
return session.text(".msgFailedToSave");
|
|
506
511
|
}
|
|
@@ -1054,7 +1059,7 @@ var zh_CN_default = {
|
|
|
1054
1059
|
description: "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E",
|
|
1055
1060
|
messages: {
|
|
1056
1061
|
noMsgQuoted: "\u{1F4A1} \u8BF7\u5F15\u7528\u4E00\u6761\u6D88\u606F\u540E\u518D\u4F7F\u7528\u6B64\u547D\u4EE4\uFF01",
|
|
1057
|
-
msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{
|
|
1062
|
+
msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{id}",
|
|
1058
1063
|
msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01",
|
|
1059
1064
|
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",
|
|
1060
1065
|
selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all \u6216 skip",
|