koishi-plugin-game-mini 0.1.6 → 0.1.8

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.d.ts CHANGED
@@ -12,9 +12,19 @@ export interface Config {
12
12
  max: number;
13
13
  botParticipateInGroup: boolean;
14
14
  };
15
+ wzHero: {
16
+ botParticipateInGroup: boolean;
17
+ };
18
+ chengyuImage: {
19
+ botParticipateInGroup: boolean;
20
+ };
21
+ chengyuJielong: {
22
+ botParticipateInGroup: boolean;
23
+ };
15
24
  apiConfig: {
25
+ wzHeroUserId: string;
26
+ cyjlUserId: string;
16
27
  timeout: number;
17
- botParticipateInGroup: boolean;
18
28
  };
19
29
  }
20
30
  export declare const Config: Schema<Config>;
package/lib/index.js CHANGED
@@ -23,9 +23,19 @@ exports.Config = koishi_1.Schema.object({
23
23
  max: koishi_1.Schema.number().min(1).default(100).description('猜数字最大值'),
24
24
  botParticipateInGroup: koishi_1.Schema.boolean().default(true).description('群聊中Bot是否参与猜数字(私聊强制参与)')
25
25
  }).description('猜数字游戏配置'),
26
+ wzHero: koishi_1.Schema.object({
27
+ botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与王者英雄猜谜(私聊强制参与)')
28
+ }).description('王者英雄猜谜配置'),
29
+ chengyuImage: koishi_1.Schema.object({
30
+ botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与看图猜成语(私聊强制参与)')
31
+ }).description('看图猜成语配置'),
32
+ chengyuJielong: koishi_1.Schema.object({
33
+ botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与成语接龙(私聊强制参与)')
34
+ }).description('成语接龙配置'),
26
35
  apiConfig: koishi_1.Schema.object({
27
- timeout: koishi_1.Schema.number().default(5000).description('API请求超时时间(毫秒)'),
28
- botParticipateInGroup: koishi_1.Schema.boolean().default(true).description('群聊中Bot是否参与其他游戏(私聊强制参与)')
36
+ wzHeroUserId: koishi_1.Schema.string().default('1828222534').description('王者英雄猜谜API的用户区分ID(建议填写Bot的QQ号/原生账号)'),
37
+ cyjlUserId: koishi_1.Schema.string().default('1828222534').description('成语接龙API的用户区分ID(建议填写Bot的QQ号/原生账号)'),
38
+ timeout: koishi_1.Schema.number().default(5000).description('第三方API请求超时时间(毫秒)')
29
39
  }).description('游戏API配置')
30
40
  }).i18n({
31
41
  'zh-CN': {
@@ -43,10 +53,23 @@ exports.Config = koishi_1.Schema.object({
43
53
  'guessNumber.max.description': '设置猜数字游戏的最大值,需大于0',
44
54
  'guessNumber.botParticipateInGroup': '群聊Bot参与猜数字开关',
45
55
  'guessNumber.botParticipateInGroup.description': '控制Bot是否在群聊中参与猜数字,私聊场景下Bot强制参与',
56
+ 'guessNumber': '猜数字游戏配置',
57
+ 'wzHero.botParticipateInGroup': '群聊Bot参与王者英雄猜谜开关',
58
+ 'wzHero.botParticipateInGroup.description': '控制Bot是否在群聊中参与王者英雄猜谜,私聊场景下Bot强制参与',
59
+ 'wzHero': '王者英雄猜谜配置',
60
+ 'chengyuImage.botParticipateInGroup': '群聊Bot参与看图猜成语开关',
61
+ 'chengyuImage.botParticipateInGroup.description': '控制Bot是否在群聊中参与看图猜成语,私聊场景下Bot强制参与',
62
+ 'chengyuImage': '看图猜成语配置',
63
+ 'chengyuJielong.botParticipateInGroup': '群聊Bot参与成语接龙开关',
64
+ 'chengyuJielong.botParticipateInGroup.description': '控制Bot是否在群聊中参与成语接龙,私聊场景下Bot强制参与',
65
+ 'chengyuJielong': '成语接龙配置',
66
+ 'apiConfig.wzHeroUserId': '王者英雄猜谜API用户ID',
67
+ 'apiConfig.wzHeroUserId.description': '用于区分Bot参与的ID,建议填写Bot的QQ号/原生账号',
68
+ 'apiConfig.cyjlUserId': '成语接龙API用户ID',
69
+ 'apiConfig.cyjlUserId.description': '用于区分Bot参与的ID,建议填写Bot的QQ号/原生账号',
46
70
  'apiConfig.timeout': 'API超时时间',
47
71
  'apiConfig.timeout.description': '第三方API请求的超时时间,单位为毫秒',
48
- 'apiConfig.botParticipateInGroup': '群聊Bot参与其他游戏开关',
49
- 'apiConfig.botParticipateInGroup.description': '控制Bot是否在群聊中参与王者英雄/猜成语/成语接龙,私聊强制参与'
72
+ 'apiConfig': '游戏API配置'
50
73
  }
51
74
  });
52
75
  const logger = new koishi_1.Logger('game-mini');
@@ -56,6 +79,20 @@ const commandDescriptions = {
56
79
  chengyuImage: '看图猜成语小游戏指令',
57
80
  chengyuJielong: '成语接龙小游戏指令'
58
81
  };
82
+ const getUserRealId = (session) => {
83
+ return session.userId || `${session.platform}_${session.selfId}`;
84
+ };
85
+ const checkGameRunning = (state, excludeType) => {
86
+ if (excludeType !== 'guessNumber' && state.guessNumber.started)
87
+ return true;
88
+ if (excludeType !== 'wzHero' && state.wzHero.started)
89
+ return true;
90
+ if (excludeType !== 'chengyuImage' && state.chengyuImage.started)
91
+ return true;
92
+ if (excludeType !== 'chengyuJielong' && state.chengyuJielong.started)
93
+ return true;
94
+ return false;
95
+ };
59
96
  function apply(ctx, config) {
60
97
  const defaultI18n = {
61
98
  guessNumber: {
@@ -72,9 +109,9 @@ function apply(ctx, config) {
72
109
  disabled: '猜数字游戏功能已关闭,请联系管理员开启',
73
110
  },
74
111
  wzHero: {
75
- startUsage: '用法错误!正确用法:wzhero start <难度>,难度可选:简单/中等/困难',
112
+ startUsage: '用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难',
76
113
  stop: '王者英雄猜谜游戏已停止',
77
- notStarted: '王者英雄猜谜游戏尚未开始,请输入 wzhero start <难度> 开始游戏',
114
+ notStarted: '王者英雄猜谜游戏尚未开始,请输入 wzhero start [难度] 开始游戏',
78
115
  hint: '提示',
79
116
  apiError: 'API请求失败,请稍后再试',
80
117
  botGuess: '让我猜猜~我觉得是:{0}',
@@ -90,9 +127,8 @@ function apply(ctx, config) {
90
127
  next: '下一题来啦!',
91
128
  hintUsage: '提示等级可选1-5,用法:提示 <等级>,如 提示 2',
92
129
  apiError: 'API请求失败,请稍后再试',
93
- botGuess: '我来试试!我猜是:{0}',
94
- botWrong: '猜错了😭,换个试试!',
95
- botRight: '太棒了!我猜对了~就是{0} 🎊',
130
+ hintSuccess: '提示(等级{0}):{1}',
131
+ hintFail: '获取提示失败,请稍后再试',
96
132
  disabled: '看图猜成语功能已关闭,请联系管理员开启',
97
133
  },
98
134
  chengyuJielong: {
@@ -104,6 +140,9 @@ function apply(ctx, config) {
104
140
  botTurn: '该我了!我接:{0}({1})\n释义:{2}',
105
141
  botWin: '哈哈我接不上了,你赢啦~',
106
142
  disabled: '成语接龙功能已关闭,请联系管理员开启',
143
+ },
144
+ common: {
145
+ gameRunning: '当前已有游戏在运行中,请先结束当前游戏后再开始新游戏!'
107
146
  }
108
147
  };
109
148
  try {
@@ -122,9 +161,22 @@ function apply(ctx, config) {
122
161
  }
123
162
  const gameStates = new Map();
124
163
  const getSessionKey = (session) => session.channelId ? `group:${session.channelId}` : `private:${session.userId}`;
125
- const getBotParticipate = (session) => {
164
+ const getBotParticipate = (session, gameType) => {
126
165
  const isPrivate = !session.channelId;
127
- return isPrivate || (session.channelId ? config.apiConfig.botParticipateInGroup : true);
166
+ if (isPrivate)
167
+ return false;
168
+ switch (gameType) {
169
+ case 'guessNumber':
170
+ return config.guessNumber.botParticipateInGroup;
171
+ case 'wzHero':
172
+ return config.wzHero.botParticipateInGroup;
173
+ case 'chengyuImage':
174
+ return config.chengyuImage.botParticipateInGroup;
175
+ case 'chengyuJielong':
176
+ return config.chengyuJielong.botParticipateInGroup;
177
+ default:
178
+ return false;
179
+ }
128
180
  };
129
181
  const initSessionState = (key) => {
130
182
  const state = {
@@ -186,8 +238,7 @@ function apply(ctx, config) {
186
238
  return;
187
239
  }
188
240
  gameStates.set(key, state);
189
- const isPrivate = !session.channelId;
190
- const botPlay = isPrivate || config.guessNumber.botParticipateInGroup;
241
+ const botPlay = getBotParticipate(session, 'guessNumber');
191
242
  if (botPlay && gnState.started && gnState.currentMin <= gnState.currentMax) {
192
243
  let botGuess;
193
244
  let safe = 0;
@@ -220,7 +271,7 @@ function apply(ctx, config) {
220
271
  try {
221
272
  const response = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
222
273
  params: {
223
- id: session.userId,
274
+ id: getUserRealId(session),
224
275
  msg: content
225
276
  },
226
277
  timeout: config.apiConfig.timeout
@@ -228,37 +279,18 @@ function apply(ctx, config) {
228
279
  const data = response.data;
229
280
  let reply = '';
230
281
  if (data.status === 'success') {
231
- reply = `${data.message || ''}\n${data.hint || ''}\n剩余提示次数:${data.remaining_hints}\n${data.guide || ''}`;
232
- wzState.lastHint = data.hint || '';
282
+ if (data.message.includes('用完了所有提示') || data.remaining_hints === 0) {
283
+ reply = '很遗憾,你用完了所有提示!难度太大?可以向我发送“wzhero start 简单”以降低猜测英雄难度。游戏开始!当前难度:简单\n请看题,下面是一首描写该英雄的诗词。\n胡笳琴韵愈伤痕\n弹弹连控摄敌魂\n加血提速护友紧\n奶妈之名天下闻\n请输入你猜测的英雄名称,或输入"提示"获取下一条线索';
284
+ }
285
+ else {
286
+ reply = `${data.message || ''}\n${data.hint || ''}\n剩余提示次数:${data.remaining_hints}\n${data.guide || ''}`;
287
+ wzState.lastHint = data.hint || '';
288
+ }
233
289
  }
234
290
  else {
235
291
  reply = data.message || '游戏出错了,请稍后再试';
236
292
  }
237
293
  await session.send(reply);
238
- if (getBotParticipate(session) && !wzState.botAnswered) {
239
- setTimeout(async () => {
240
- const heroList = ['李白', '韩信', '貂蝉', '诸葛亮', '妲己', '亚瑟', '鲁班七号', '孙尚香', '孙悟空', '安琪拉'];
241
- const randomHero = heroList[Math.floor(Math.random() * heroList.length)];
242
- const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
243
- params: {
244
- id: session.selfId,
245
- msg: randomHero
246
- },
247
- timeout: config.apiConfig.timeout
248
- });
249
- let botReply = session.text('wzHero.botGuess', [randomHero]);
250
- if (botResponse.data.status !== 'success' || botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
251
- botReply += '\n' + session.text('wzHero.botWrong');
252
- }
253
- else {
254
- botReply += '\n' + session.text('wzHero.botRight', [randomHero]);
255
- wzState.started = false;
256
- }
257
- wzState.botAnswered = true;
258
- gameStates.set(key, state);
259
- await session.send(botReply);
260
- }, 3000);
261
- }
262
294
  }
263
295
  catch (error) {
264
296
  logger.error('王者英雄猜谜API请求失败:', error);
@@ -285,7 +317,12 @@ function apply(ctx, config) {
285
317
  timeout: config.apiConfig.timeout
286
318
  });
287
319
  const data = response.data;
288
- reply = data.success ? data.message : '获取提示失败,请稍后再试';
320
+ if (data.success && data.message) {
321
+ reply = session.text('chengyuImage.hintSuccess', [validLevel, data.message]);
322
+ }
323
+ else {
324
+ reply = session.text('chengyuImage.hintFail');
325
+ }
289
326
  }
290
327
  else if (content === '下一题') {
291
328
  const response = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
@@ -296,13 +333,12 @@ function apply(ctx, config) {
296
333
  timeout: config.apiConfig.timeout
297
334
  });
298
335
  const data = response.data;
299
- if (data.success) {
336
+ if (data.success && data.data?.question) {
300
337
  cyImageState.currentId = data.data.question.id;
301
338
  cyImageState.currentPage = data.data.question.page;
302
339
  cyImageState.options = data.data.question.options;
303
- cyImageState.botGuessed = false;
304
340
  gameStates.set(key, state);
305
- reply = `${session.text('chengyuImage.next')}\n${data.data.message}\n选项:${data.data.question.options.join('、')}\n图片链接:${data.data.question.image_url}`;
341
+ reply = `${session.text('chengyuImage.next')}\n${data.data.message || '请从选项中选择4个字组成成语'}\n选项:${data.data.question.options.join('、')}\n[CQ:image,file=${data.data.question.image_url}]`;
306
342
  }
307
343
  else {
308
344
  reply = '获取下一题失败,请稍后再试';
@@ -318,39 +354,17 @@ function apply(ctx, config) {
318
354
  timeout: config.apiConfig.timeout
319
355
  });
320
356
  const data = response.data;
321
- reply = data.message || '提交答案失败,请稍后再试';
322
- }
323
- await session.send(reply);
324
- if (getBotParticipate(session) && !cyImageState.botGuessed && cyImageState.options.length > 0) {
325
- setTimeout(async () => {
326
- const randomWords = [];
327
- for (let i = 0; i < 4; i++) {
328
- if (cyImageState.options.length > i) {
329
- randomWords.push(cyImageState.options[Math.floor(Math.random() * cyImageState.options.length)]);
330
- }
331
- }
332
- const randomIdiom = randomWords.join('');
333
- const botResponse = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
334
- params: {
335
- action: 'submit_answer',
336
- id: currentId,
337
- answer: randomIdiom
338
- },
339
- timeout: config.apiConfig.timeout
340
- });
341
- let botReply = session.text('chengyuImage.botGuess', [randomIdiom]);
342
- if (botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
343
- botReply += '\n' + session.text('chengyuImage.botWrong');
344
- }
345
- else {
346
- botReply += '\n' + session.text('chengyuImage.botRight', [randomIdiom]);
347
- cyImageState.started = false;
357
+ if (data.success) {
358
+ reply = data.message;
359
+ if (data.message.includes('正确') || data.message.includes('答对')) {
360
+ state.chengyuImage.started = false;
348
361
  }
349
- cyImageState.botGuessed = true;
350
- gameStates.set(key, state);
351
- await session.send(botReply);
352
- }, 3000);
362
+ }
363
+ else {
364
+ reply = '提交答案失败,请稍后再试';
365
+ }
353
366
  }
367
+ await session.send(reply);
354
368
  }
355
369
  catch (error) {
356
370
  logger.error('看图猜成语API请求失败:', error);
@@ -373,7 +387,7 @@ function apply(ctx, config) {
373
387
  try {
374
388
  const response = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
375
389
  params: {
376
- id: session.userId,
390
+ id: getUserRealId(session),
377
391
  msg: `我接${idiom}`
378
392
  },
379
393
  timeout: config.apiConfig.timeout
@@ -395,27 +409,6 @@ function apply(ctx, config) {
395
409
  reply = data.msg || '接龙失败,请换个成语试试';
396
410
  }
397
411
  await session.send(reply);
398
- if (getBotParticipate(session) && cyJlState.lastChar) {
399
- setTimeout(async () => {
400
- const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
401
- params: {
402
- id: session.selfId,
403
- msg: `开始成语接龙`
404
- },
405
- timeout: config.apiConfig.timeout
406
- });
407
- if (botResponse.data.code === 200 && botResponse.data.data.system) {
408
- const botIdiom = botResponse.data.data.system.idiom;
409
- const botPinyin = botResponse.data.data.system.pinyin;
410
- const botMeaning = botResponse.data.data.system.meaning;
411
- const botChar = botResponse.data.data.current_char;
412
- const botReply = session.text('chengyuJielong.botTurn', [botIdiom, botPinyin, botMeaning]);
413
- cyJlState.lastChar = botChar;
414
- gameStates.set(key, state);
415
- await session.send(botReply);
416
- }
417
- }, 2000);
418
- }
419
412
  }
420
413
  catch (error) {
421
414
  logger.error('成语接龙API请求失败:', error);
@@ -436,6 +429,10 @@ function apply(ctx, config) {
436
429
  const key = getSessionKey(session);
437
430
  const state = gameStates.get(key) || initSessionState(key);
438
431
  if (action === 'start') {
432
+ if (checkGameRunning(state, 'guessNumber')) {
433
+ await session.send(session.text('common.gameRunning'));
434
+ return '';
435
+ }
439
436
  state.guessNumber.target = koishi_1.Random.int(config.guessNumber.min, config.guessNumber.max);
440
437
  state.guessNumber.currentMin = config.guessNumber.min;
441
438
  state.guessNumber.currentMax = config.guessNumber.max;
@@ -443,8 +440,7 @@ function apply(ctx, config) {
443
440
  state.guessNumber.botGuess = [];
444
441
  gameStates.set(key, state);
445
442
  await session.send(session.text('guessNumber.start', [config.guessNumber.min, config.guessNumber.max]));
446
- const isPrivate = !session.channelId;
447
- const botPlay = isPrivate || config.guessNumber.botParticipateInGroup;
443
+ const botPlay = getBotParticipate(session, 'guessNumber');
448
444
  if (botPlay) {
449
445
  setTimeout(async () => {
450
446
  const botGuess = koishi_1.Random.int(config.guessNumber.min, config.guessNumber.max);
@@ -481,28 +477,34 @@ function apply(ctx, config) {
481
477
  }
482
478
  if (config.enableWzHero) {
483
479
  ctx.command('wzhero <action:string> [difficulty:string]', commandDescriptions.wzHero)
480
+ .usage('用法:wzhero start [难度],难度可选:简单/中等/困难,默认中等')
484
481
  .action(async (argv, action, difficulty) => {
485
482
  const session = argv.session;
486
483
  if (!session || !action) {
487
- await session?.send(session.text('wzHero.startUsage'));
484
+ await session?.send('用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难');
488
485
  return '';
489
486
  }
490
487
  const key = getSessionKey(session);
491
488
  const state = gameStates.get(key) || initSessionState(key);
492
489
  if (action === 'start') {
493
- if (!difficulty || !['简单', '中等', '困难'].includes(difficulty)) {
494
- await session.send(session.text('wzHero.startUsage'));
490
+ if (checkGameRunning(state, 'wzHero')) {
491
+ await session.send(session.text('common.gameRunning'));
492
+ return '';
493
+ }
494
+ const finalDifficulty = difficulty || '中等';
495
+ if (!['简单', '中等', '困难'].includes(finalDifficulty)) {
496
+ await session.send('用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难');
495
497
  return '';
496
498
  }
497
499
  state.wzHero.started = true;
498
- state.wzHero.difficulty = difficulty;
500
+ state.wzHero.difficulty = finalDifficulty;
499
501
  state.wzHero.botAnswered = false;
500
502
  gameStates.set(key, state);
501
503
  try {
502
504
  const response = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
503
505
  params: {
504
- id: session.userId,
505
- msg: `开始游戏${difficulty}`
506
+ id: getUserRealId(session),
507
+ msg: `开始游戏${finalDifficulty}`
506
508
  },
507
509
  timeout: config.apiConfig.timeout
508
510
  });
@@ -516,30 +518,6 @@ function apply(ctx, config) {
516
518
  reply = data.message || '游戏开始失败,请稍后再试';
517
519
  }
518
520
  await session.send(reply);
519
- if (getBotParticipate(session)) {
520
- setTimeout(async () => {
521
- const heroList = ['李白', '韩信', '貂蝉', '诸葛亮', '妲己', '亚瑟', '鲁班七号', '孙尚香', '孙悟空', '安琪拉'];
522
- const randomHero = heroList[Math.floor(Math.random() * heroList.length)];
523
- const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
524
- params: {
525
- id: session.selfId,
526
- msg: randomHero
527
- },
528
- timeout: config.apiConfig.timeout
529
- });
530
- let botReply = session.text('wzHero.botGuess', [randomHero]);
531
- if (botResponse.data.status !== 'success' || botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
532
- botReply += '\n' + session.text('wzHero.botWrong');
533
- }
534
- else {
535
- botReply += '\n' + session.text('wzHero.botRight', [randomHero]);
536
- state.wzHero.started = false;
537
- }
538
- state.wzHero.botAnswered = true;
539
- gameStates.set(key, state);
540
- await session.send(botReply);
541
- }, 2000);
542
- }
543
521
  }
544
522
  catch (error) {
545
523
  logger.error('王者英雄猜谜开始游戏失败:', error);
@@ -554,7 +532,7 @@ function apply(ctx, config) {
554
532
  await session.send(session.text('wzHero.stop'));
555
533
  }
556
534
  else {
557
- await session.send(session.text('wzHero.startUsage'));
535
+ await session.send('用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难');
558
536
  }
559
537
  return '';
560
538
  });
@@ -570,6 +548,10 @@ function apply(ctx, config) {
570
548
  const key = getSessionKey(session);
571
549
  const state = gameStates.get(key) || initSessionState(key);
572
550
  if (action === 'start') {
551
+ if (checkGameRunning(state, 'chengyuImage')) {
552
+ await session.send(session.text('common.gameRunning'));
553
+ return '';
554
+ }
573
555
  try {
574
556
  const response = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
575
557
  params: {
@@ -578,45 +560,14 @@ function apply(ctx, config) {
578
560
  timeout: config.apiConfig.timeout
579
561
  });
580
562
  const data = response.data;
581
- if (data.success) {
563
+ if (data.success && data.data?.question) {
582
564
  state.chengyuImage.started = true;
583
565
  state.chengyuImage.currentId = data.data.question.id;
584
566
  state.chengyuImage.currentPage = data.data.question.page;
585
567
  state.chengyuImage.options = data.data.question.options;
586
- state.chengyuImage.botGuessed = false;
587
568
  gameStates.set(key, state);
588
- const reply = `${session.text('chengyuImage.start')}\n${data.data.message}\n选项:${data.data.question.options.join('、')}\n图片链接:${data.data.question.image_url}`;
569
+ const reply = `${session.text('chengyuImage.submitUsage')}\n${data.data.message || '请从选项中选择4个字组成成语'}\n选项:${data.data.question.options.join('、')}\n[CQ:image,file=${data.data.question.image_url}]`;
589
570
  await session.send(reply);
590
- if (getBotParticipate(session)) {
591
- setTimeout(async () => {
592
- const randomWords = [];
593
- for (let i = 0; i < 4; i++) {
594
- if (data.data.question.options.length > i) {
595
- randomWords.push(data.data.question.options[Math.floor(Math.random() * data.data.question.options.length)]);
596
- }
597
- }
598
- const randomIdiom = randomWords.join('');
599
- const botResponse = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
600
- params: {
601
- action: 'submit_answer',
602
- id: data.data.question.id,
603
- answer: randomIdiom
604
- },
605
- timeout: config.apiConfig.timeout
606
- });
607
- let botReply = session.text('chengyuImage.botGuess', [randomIdiom]);
608
- if (botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
609
- botReply += '\n' + session.text('chengyuImage.botWrong');
610
- }
611
- else {
612
- botReply += '\n' + session.text('chengyuImage.botRight', [randomIdiom]);
613
- state.chengyuImage.started = false;
614
- }
615
- state.chengyuImage.botGuessed = true;
616
- gameStates.set(key, state);
617
- await session.send(botReply);
618
- }, 2000);
619
- }
620
571
  }
621
572
  else {
622
573
  await session.send('获取题目失败,请稍后再试');
@@ -649,13 +600,17 @@ function apply(ctx, config) {
649
600
  const key = getSessionKey(session);
650
601
  const state = gameStates.get(key) || initSessionState(key);
651
602
  if (action === 'start') {
603
+ if (checkGameRunning(state, 'chengyuJielong')) {
604
+ await session.send(session.text('common.gameRunning'));
605
+ return '';
606
+ }
652
607
  state.chengyuJielong.started = true;
653
608
  state.chengyuJielong.botTurn = true;
654
609
  gameStates.set(key, state);
655
610
  try {
656
611
  const response = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
657
612
  params: {
658
- id: session.userId,
613
+ id: getUserRealId(session),
659
614
  msg: '开始成语接龙'
660
615
  },
661
616
  timeout: config.apiConfig.timeout
@@ -1,42 +1,49 @@
1
+ # locales/zh-CN.yml
1
2
  guessNumber:
2
- usage: 用法错误!正确用法:guess start/stop 或 直接输入数字
3
- start: 猜数字游戏开始!初始范围是 {0}-{1},快来猜猜看~
4
- stop: 猜数字游戏已停止,正确数字是 {0}
5
- outOfRange: 数字超出当前范围 [{0}-{1}],请重新输入!
6
- tooSmall: 猜小啦!当前范围更新为 [{0}-{1}]
7
- tooBig: 猜大啦!当前范围更新为 [{0}-{1}]
8
- correct: 恭喜你猜中了!正确数字就是 {0} 🎉
9
- botWin: 哈哈我猜中了!我猜的是 {0},正确数字就是 {0},我赢啦 🎉
10
- botGuessTooSmall: 我猜 {0},猜小啦!当前范围 [{1}-{2}]
11
- botGuessTooBig: 我猜 {0},猜大啦!当前范围 [{1}-{2}]
12
- commandDesc: 猜数字小游戏指令
3
+ usage: "用法错误!正确用法:guess start/stop 或 直接输入数字"
4
+ start: "猜数字游戏开始!初始范围是 {0}-{1},快来猜猜看~"
5
+ stop: "猜数字游戏已停止,正确数字是 {0}"
6
+ outOfRange: "数字超出当前范围 [{0}-{1}],请重新输入!"
7
+ tooSmall: "猜小啦!当前范围更新为 [{0}-{1}]"
8
+ tooBig: "猜大啦!当前范围更新为 [{0}-{1}]"
9
+ correct: "恭喜你猜中了!正确数字就是 {0} 🎉"
10
+ botWin: "哈哈我猜中了!我猜的是 {0},正确数字就是 {0},我赢啦 🎉"
11
+ botGuessTooSmall: "我猜 {0},猜小啦!当前范围 [{1}-{2}]"
12
+ botGuessTooBig: "我猜 {0},猜大啦!当前范围 [{1}-{2}]"
13
+ disabled: "猜数字游戏功能已关闭,请联系管理员开启"
14
+
13
15
  wzHero:
14
- startUsage: 用法错误!正确用法:wzhero start <难度>,难度可选:简单/中等/困难
15
- stop: 王者英雄猜谜游戏已停止
16
- notStarted: 王者英雄猜谜游戏尚未开始,请输入 wzhero start <难度> 开始游戏
17
- hint: 提示
18
- commandDesc: 猜王者荣耀英雄小游戏指令
19
- apiError: API请求失败,请稍后再试
20
- botGuess: 让我猜猜~我觉得是:{0}
21
- botWrong: 哎呀猜错了😜,继续猜猜看!
22
- botRight: 耶!我猜对了~就是{0} ✨
16
+ startUsage: "用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难"
17
+ stop: "王者英雄猜谜游戏已停止"
18
+ notStarted: "王者英雄猜谜游戏尚未开始,请输入 wzhero start [难度] 开始游戏"
19
+ hint: "提示"
20
+ apiError: "API请求失败,请稍后再试"
21
+ botGuess: "让我猜猜~我觉得是:{0}"
22
+ botWrong: "哎呀猜错了😜,继续猜猜看!"
23
+ botRight: "耶!我猜对了~就是{0} ✨"
24
+ disabled: "王者英雄猜谜功能已关闭,请联系管理员开启"
25
+
23
26
  chengyuImage:
24
- start: 看图猜成语游戏开始!
25
- stop: 看图猜成语游戏已停止
26
- submitUsage: 请直接输入你猜测的成语,或输入 提示 获取线索
27
- notStarted: 看图猜成语游戏尚未开始,请输入 cyimage start 开始游戏
28
- next: 下一题来啦!
29
- hintUsage: 提示等级可选1-5,用法:提示 <等级>,如 提示 2
30
- commandDesc: 看图猜成语小游戏指令
31
- apiError: API请求失败,请稍后再试
32
- botGuess: 我来试试!我猜是:{0}
33
- botWrong: 猜错了😭,换个试试!
34
- botRight: 太棒了!我猜对了~就是{0} 🎊
27
+ start: "看图猜成语游戏开始!"
28
+ stop: "看图猜成语游戏已停止"
29
+ submitUsage: "请直接输入你猜测的成语,或输入 提示 获取线索"
30
+ notStarted: "看图猜成语游戏尚未开始,请输入 cyimage start 开始游戏"
31
+ next: "下一题来啦!"
32
+ hintUsage: "提示等级可选1-5,用法:提示 <等级>,如 提示 2"
33
+ apiError: "API请求失败,请稍后再试"
34
+ hintSuccess: "提示(等级{0}):{1}"
35
+ hintFail: "获取提示失败,请稍后再试"
36
+ disabled: "看图猜成语功能已关闭,请联系管理员开启"
37
+
35
38
  chengyuJielong:
36
- start: 成语接龙游戏开始!我先来~
37
- stop: 成语接龙游戏已停止
38
- notStarted: 成语接龙游戏尚未开始,请输入 cyjl start 开始游戏
39
- joinUsage: 请输入 我接<成语> 进行接龙,如 我接一帆风顺
40
- commandDesc: 成语接龙小游戏指令
41
- apiError: API请求失败,请稍后再试
42
- botTurn: 该我了!我接:{0}({1})\n释义:{2}
39
+ start: "成语接龙游戏开始!我先来~"
40
+ stop: "成语接龙游戏已停止"
41
+ notStarted: "成语接龙游戏尚未开始,请输入 cyjl start 开始游戏"
42
+ joinUsage: "请输入 我接<成语> 进行接龙,如 我接一帆风顺"
43
+ apiError: "API请求失败,请稍后再试"
44
+ botTurn: "该我了!我接:{0}({1})\n释义:{2}"
45
+ botWin: "哈哈我接不上了,你赢啦~"
46
+ disabled: "成语接龙功能已关闭,请联系管理员开启"
47
+
48
+ common:
49
+ gameRunning: "当前已有游戏在运行中,请先结束当前游戏后再开始新游戏!"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-game-mini",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "一款包含猜数字、猜王者英雄、看图猜成语、成语接龙的多功能小游戏插件",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",