koishi-plugin-echo-cave 1.25.0 → 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/index.cjs CHANGED
@@ -93,19 +93,10 @@ 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;
96
+ async function listenForUserMessage(ctx, session, prompt, timeout, onMessage, onTimeout) {
98
97
  const userId = session.userId;
99
98
  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
- }
99
+ const promptMessageId = await session.onebot.sendGroupMsg(channelId, prompt);
109
100
  let timeoutId;
110
101
  const listener = async (msgSession) => {
111
102
  if (msgSession.userId === userId && msgSession.channelId === channelId) {
@@ -113,26 +104,23 @@ async function listenForUserMessage(options) {
113
104
  const shouldContinue = await onMessage(msgSession.content);
114
105
  if (!shouldContinue) {
115
106
  ctx.off("message", listener);
116
- if (promptMessageId) {
117
- try {
118
- await session.onebot.deleteMsg(promptMessageId);
119
- } catch (error) {
120
- }
107
+ try {
108
+ await session.onebot.deleteMsg(promptMessageId);
109
+ } catch (error) {
121
110
  }
111
+ cancelTimeout();
122
112
  }
123
113
  }
124
114
  };
125
115
  ctx.on("message", listener);
126
- timeoutId = setTimeout(async () => {
116
+ const cancelTimeout = ctx.setTimeout(async () => {
127
117
  ctx.off("message", listener);
128
118
  if (onTimeout) {
129
119
  await onTimeout();
130
120
  }
131
- if (promptMessageId) {
132
- try {
133
- await session.onebot.deleteMsg(promptMessageId);
134
- } catch (error) {
135
- }
121
+ try {
122
+ await session.onebot.deleteMsg(promptMessageId);
123
+ } catch (error) {
136
124
  }
137
125
  }, timeout);
138
126
  }
@@ -470,16 +458,13 @@ ${index + 1}: ${user.nickname}`;
470
458
  });
471
459
  prompt += `
472
460
  ${session.text(".selectInstruction")}`;
473
- listenForUserMessage({
461
+ listenForUserMessage(
474
462
  ctx,
475
463
  session,
476
464
  prompt,
477
- timeout: (cfg.forwardSelectTimeout || 20) * 1e3,
465
+ cfg.forwardSelectTimeout * 1e3,
478
466
  // Convert seconds to milliseconds
479
- onTimeout: async () => {
480
- resolve([]);
481
- },
482
- onMessage: async (message) => {
467
+ async (message) => {
483
468
  const trimmedMessage = message.trim();
484
469
  let selectedUsers = [];
485
470
  if (trimmedMessage.toLowerCase() === "all") {
@@ -500,8 +485,11 @@ ${session.text(".selectInstruction")}`;
500
485
  }
501
486
  resolve(selectedUsers);
502
487
  return false;
488
+ },
489
+ async () => {
490
+ resolve([]);
503
491
  }
504
- });
492
+ );
505
493
  });
506
494
  parsedUserIds = await userSelectionPromise;
507
495
  }
@@ -1072,7 +1060,7 @@ var zh_CN_default = {
1072
1060
  msgSaved: "\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A{0}",
1073
1061
  msgFailedToSave: "\u274C \u56DE\u58F0\u6D1E\u4FDD\u5B58\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01",
1074
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",
1075
- selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all",
1063
+ selectInstruction: "\u8F93\u5165\u793A\u4F8B\uFF1A1 3 \u6216 all \u6216 skip",
1076
1064
  invalidSelection: "\u274C \u65E0\u6548\u7684\u9009\u62E9\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165\uFF01"
1077
1065
  }
1078
1066
  },
@@ -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.1",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",