koishi-plugin-game-mini 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-game-mini",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "一款简单的猜数字小游戏,支持Bot 参与猜数",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
package/src/index.ts CHANGED
@@ -50,7 +50,8 @@ export function apply(ctx: Context, config: Config) {
50
50
  state.started = false;
51
51
  guessNumberStates.set(key, state);
52
52
  reply = session.text('guessNumber.correct', [state.target]);
53
- return session.send(reply);
53
+ await session.send(reply);
54
+ return;
54
55
  }
55
56
 
56
57
  guessNumberStates.set(key, state);
@@ -78,15 +79,16 @@ export function apply(ctx: Context, config: Config) {
78
79
  reply += '\n' + session.text('guessNumber.botGuessTooBig', [botGuess, state.currentMin, state.currentMax]);
79
80
  }
80
81
  }
81
- return session.send(reply);
82
+ await session.send(reply);
83
+ return;
82
84
  }
83
85
  }
84
86
  return next();
85
87
  });
86
88
 
87
89
  ctx.command('guess <action:string>')
88
- .action(({ session }, action) => {
89
- if (!session) return;
90
+ .action(async ({ session }, action) => {
91
+ if (!session) return '';
90
92
  const key = getSessionKey(session);
91
93
  let state = guessNumberStates.get(key) || {
92
94
  target: 0,
@@ -105,24 +107,32 @@ export function apply(ctx: Context, config: Config) {
105
107
  state.started = true;
106
108
  state.botGuess = [];
107
109
  guessNumberStates.set(key, state);
108
- let reply = session.text('guessNumber.start', [0, 100]);
110
+ // 修复:手动拼接范围字符串,避免模板解析异常
111
+ const startText = `猜数字游戏开始!初始范围是 ${state.currentMin}-${state.currentMax},快来猜猜看~`;
112
+ let reply = startText;
109
113
  const isPrivate = !session.channelId;
110
114
  const botShouldParticipate = isPrivate || true;
111
115
  if (botShouldParticipate && state.started) {
112
116
  const botFirstGuess = Random.int(state.currentMin, state.currentMax);
113
117
  state.botGuess.push(botFirstGuess);
114
118
  guessNumberStates.set(key, state);
115
- reply += '\n' + session.text('guessNumber.botFirstGuess', [botFirstGuess]);
119
+ reply += '\n' + `我先来猜一个:${botFirstGuess},该你啦~`;
116
120
  }
117
- return reply;
121
+ // 修复:使用 send 方法而非直接返回,避免附带无关数字
122
+ await session.send(reply);
123
+ return '';
118
124
  }
119
125
 
120
126
  if (action === 'stop') {
121
127
  state.started = false;
122
128
  guessNumberStates.set(key, state);
123
- return session.text('guessNumber.stop', [state.target]);
129
+ const stopText = `猜数字游戏已停止,正确数字是 ${state.target}`;
130
+ await session.send(stopText);
131
+ return '';
124
132
  }
125
133
 
126
- return session.text('guessNumber.usage');
134
+ const usageText = session.text('guessNumber.usage');
135
+ await session.send(usageText);
136
+ return '';
127
137
  });
128
138
  }