koishi-plugin-echo-cave 1.25.0 → 1.25.2

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 CHANGED
@@ -93,46 +93,31 @@ function parseUserIds(userIds) {
93
93
  }
94
94
 
95
95
  // src/utils/msg/message-listener.ts
96
- async function listenForUserMessage(options) {
97
- const { ctx, session, prompt, timeout, onTimeout, onMessage } = options;
98
- const userId = session.userId;
99
- const channelId = session.channelId;
100
- const promptMessage = await session.send(prompt);
101
- let promptMessageId = "";
102
- try {
103
- const msgObj = promptMessage;
104
- if (msgObj && typeof msgObj === "object" && msgObj.messageId) {
105
- promptMessageId = String(msgObj.messageId);
106
- }
107
- } catch (error) {
108
- }
109
- let timeoutId;
96
+ async function listenForUserMessage(ctx, session, prompt, timeout, onMessage, onTimeout) {
97
+ const { userId, channelId } = session;
98
+ const promptMessageId = await session.onebot.sendGroupMsg(channelId, prompt);
110
99
  const listener = async (msgSession) => {
111
100
  if (msgSession.userId === userId && msgSession.channelId === channelId) {
112
- clearTimeout(timeoutId);
113
101
  const shouldContinue = await onMessage(msgSession.content);
114
102
  if (!shouldContinue) {
115
- ctx.off("message", listener);
116
- if (promptMessageId) {
117
- try {
118
- await session.onebot.deleteMsg(promptMessageId);
119
- } catch (error) {
120
- }
103
+ cancelListener();
104
+ try {
105
+ await session.onebot.deleteMsg(promptMessageId);
106
+ } catch (error) {
121
107
  }
108
+ cancelTimeout();
122
109
  }
123
110
  }
124
111
  };
125
- ctx.on("message", listener);
126
- timeoutId = setTimeout(async () => {
127
- ctx.off("message", listener);
112
+ const cancelListener = ctx.on("message", listener);
113
+ const cancelTimeout = ctx.setTimeout(async () => {
114
+ cancelListener();
128
115
  if (onTimeout) {
129
116
  await onTimeout();
130
117
  }
131
- if (promptMessageId) {
132
- try {
133
- await session.onebot.deleteMsg(promptMessageId);
134
- } catch (error) {
135
- }
118
+ try {
119
+ await session.onebot.deleteMsg(promptMessageId);
120
+ } catch (error) {
136
121
  }
137
122
  }, timeout);
138
123
  }
@@ -470,16 +455,13 @@ ${index + 1}: ${user.nickname}`;
470
455
  });
471
456
  prompt += `
472
457
  ${session.text(".selectInstruction")}`;
473
- listenForUserMessage({
458
+ listenForUserMessage(
474
459
  ctx,
475
460
  session,
476
461
  prompt,
477
- timeout: (cfg.forwardSelectTimeout || 20) * 1e3,
462
+ cfg.forwardSelectTimeout * 1e3,
478
463
  // Convert seconds to milliseconds
479
- onTimeout: async () => {
480
- resolve([]);
481
- },
482
- onMessage: async (message) => {
464
+ async (message) => {
483
465
  const trimmedMessage = message.trim();
484
466
  let selectedUsers = [];
485
467
  if (trimmedMessage.toLowerCase() === "all") {
@@ -500,8 +482,11 @@ ${session.text(".selectInstruction")}`;
500
482
  }
501
483
  resolve(selectedUsers);
502
484
  return false;
485
+ },
486
+ async () => {
487
+ resolve([]);
503
488
  }
504
- });
489
+ );
505
490
  });
506
491
  parsedUserIds = await userSelectionPromise;
507
492
  }
@@ -1072,7 +1057,7 @@ var zh_CN_default = {
1072
1057
  msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{0}",
1073
1058
  msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01",
1074
1059
  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",
1075
- selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all",
1060
+ selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all \u6216 skip",
1076
1061
  invalidSelection: "\u274C \u65E0\u6548\u7684\u9009\u62E9\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\uFF01"
1077
1062
  }
1078
1063
  },
@@ -1,10 +1,2 @@
1
1
  import { Context, Session } from 'koishi';
2
- export interface MessageListenerOptions {
3
- ctx: Context;
4
- session: Session;
5
- prompt: string;
6
- timeout: number;
7
- onTimeout?: () => Promise<void>;
8
- onMessage: (message: string) => Promise<boolean>;
9
- }
10
- export declare function listenForUserMessage(options: MessageListenerOptions): Promise<void>;
2
+ export declare function listenForUserMessage(ctx: Context, session: Session, prompt: string, timeout: number, onMessage: (message: string) => Promise<boolean>, onTimeout?: () => Promise<void>): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.25.0",
4
+ "version": "1.25.2",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",