koishi-plugin-game-mini 0.1.7 → 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.js +47 -149
- package/lib/locales/locales/zh-CN.yml +6 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -24,13 +24,13 @@ exports.Config = koishi_1.Schema.object({
|
|
|
24
24
|
botParticipateInGroup: koishi_1.Schema.boolean().default(true).description('群聊中Bot是否参与猜数字(私聊强制参与)')
|
|
25
25
|
}).description('猜数字游戏配置'),
|
|
26
26
|
wzHero: koishi_1.Schema.object({
|
|
27
|
-
botParticipateInGroup: koishi_1.Schema.boolean().default(
|
|
27
|
+
botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与王者英雄猜谜(私聊强制参与)')
|
|
28
28
|
}).description('王者英雄猜谜配置'),
|
|
29
29
|
chengyuImage: koishi_1.Schema.object({
|
|
30
|
-
botParticipateInGroup: koishi_1.Schema.boolean().default(
|
|
30
|
+
botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与看图猜成语(私聊强制参与)')
|
|
31
31
|
}).description('看图猜成语配置'),
|
|
32
32
|
chengyuJielong: koishi_1.Schema.object({
|
|
33
|
-
botParticipateInGroup: koishi_1.Schema.boolean().default(
|
|
33
|
+
botParticipateInGroup: koishi_1.Schema.boolean().default(false).description('群聊中Bot是否参与成语接龙(私聊强制参与)')
|
|
34
34
|
}).description('成语接龙配置'),
|
|
35
35
|
apiConfig: koishi_1.Schema.object({
|
|
36
36
|
wzHeroUserId: koishi_1.Schema.string().default('1828222534').description('王者英雄猜谜API的用户区分ID(建议填写Bot的QQ号/原生账号)'),
|
|
@@ -82,6 +82,17 @@ const commandDescriptions = {
|
|
|
82
82
|
const getUserRealId = (session) => {
|
|
83
83
|
return session.userId || `${session.platform}_${session.selfId}`;
|
|
84
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
|
+
};
|
|
85
96
|
function apply(ctx, config) {
|
|
86
97
|
const defaultI18n = {
|
|
87
98
|
guessNumber: {
|
|
@@ -116,9 +127,8 @@ function apply(ctx, config) {
|
|
|
116
127
|
next: '下一题来啦!',
|
|
117
128
|
hintUsage: '提示等级可选1-5,用法:提示 <等级>,如 提示 2',
|
|
118
129
|
apiError: 'API请求失败,请稍后再试',
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
botRight: '太棒了!我猜对了~就是{0} 🎊',
|
|
130
|
+
hintSuccess: '提示(等级{0}):{1}',
|
|
131
|
+
hintFail: '获取提示失败,请稍后再试',
|
|
122
132
|
disabled: '看图猜成语功能已关闭,请联系管理员开启',
|
|
123
133
|
},
|
|
124
134
|
chengyuJielong: {
|
|
@@ -130,6 +140,9 @@ function apply(ctx, config) {
|
|
|
130
140
|
botTurn: '该我了!我接:{0}({1})\n释义:{2}',
|
|
131
141
|
botWin: '哈哈我接不上了,你赢啦~',
|
|
132
142
|
disabled: '成语接龙功能已关闭,请联系管理员开启',
|
|
143
|
+
},
|
|
144
|
+
common: {
|
|
145
|
+
gameRunning: '当前已有游戏在运行中,请先结束当前游戏后再开始新游戏!'
|
|
133
146
|
}
|
|
134
147
|
};
|
|
135
148
|
try {
|
|
@@ -151,7 +164,7 @@ function apply(ctx, config) {
|
|
|
151
164
|
const getBotParticipate = (session, gameType) => {
|
|
152
165
|
const isPrivate = !session.channelId;
|
|
153
166
|
if (isPrivate)
|
|
154
|
-
return
|
|
167
|
+
return false;
|
|
155
168
|
switch (gameType) {
|
|
156
169
|
case 'guessNumber':
|
|
157
170
|
return config.guessNumber.botParticipateInGroup;
|
|
@@ -162,7 +175,7 @@ function apply(ctx, config) {
|
|
|
162
175
|
case 'chengyuJielong':
|
|
163
176
|
return config.chengyuJielong.botParticipateInGroup;
|
|
164
177
|
default:
|
|
165
|
-
return
|
|
178
|
+
return false;
|
|
166
179
|
}
|
|
167
180
|
};
|
|
168
181
|
const initSessionState = (key) => {
|
|
@@ -278,31 +291,6 @@ function apply(ctx, config) {
|
|
|
278
291
|
reply = data.message || '游戏出错了,请稍后再试';
|
|
279
292
|
}
|
|
280
293
|
await session.send(reply);
|
|
281
|
-
const botPlay = getBotParticipate(session, 'wzHero');
|
|
282
|
-
if (botPlay && !wzState.botAnswered) {
|
|
283
|
-
setTimeout(async () => {
|
|
284
|
-
const heroList = ['李白', '韩信', '貂蝉', '诸葛亮', '妲己', '亚瑟', '鲁班七号', '孙尚香', '孙悟空', '安琪拉'];
|
|
285
|
-
const randomHero = heroList[Math.floor(Math.random() * heroList.length)];
|
|
286
|
-
const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
|
|
287
|
-
params: {
|
|
288
|
-
id: config.apiConfig.wzHeroUserId,
|
|
289
|
-
msg: randomHero
|
|
290
|
-
},
|
|
291
|
-
timeout: config.apiConfig.timeout
|
|
292
|
-
});
|
|
293
|
-
let botReply = session.text('wzHero.botGuess', [randomHero]);
|
|
294
|
-
if (botResponse.data.status !== 'success' || botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
|
|
295
|
-
botReply += '\n' + session.text('wzHero.botWrong');
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
botReply += '\n' + session.text('wzHero.botRight', [randomHero]);
|
|
299
|
-
wzState.started = false;
|
|
300
|
-
}
|
|
301
|
-
wzState.botAnswered = true;
|
|
302
|
-
gameStates.set(key, state);
|
|
303
|
-
await session.send(botReply);
|
|
304
|
-
}, 3000);
|
|
305
|
-
}
|
|
306
294
|
}
|
|
307
295
|
catch (error) {
|
|
308
296
|
logger.error('王者英雄猜谜API请求失败:', error);
|
|
@@ -329,7 +317,12 @@ function apply(ctx, config) {
|
|
|
329
317
|
timeout: config.apiConfig.timeout
|
|
330
318
|
});
|
|
331
319
|
const data = response.data;
|
|
332
|
-
|
|
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
|
+
}
|
|
333
326
|
}
|
|
334
327
|
else if (content === '下一题') {
|
|
335
328
|
const response = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
|
|
@@ -340,13 +333,12 @@ function apply(ctx, config) {
|
|
|
340
333
|
timeout: config.apiConfig.timeout
|
|
341
334
|
});
|
|
342
335
|
const data = response.data;
|
|
343
|
-
if (data.success) {
|
|
336
|
+
if (data.success && data.data?.question) {
|
|
344
337
|
cyImageState.currentId = data.data.question.id;
|
|
345
338
|
cyImageState.currentPage = data.data.question.page;
|
|
346
339
|
cyImageState.options = data.data.question.options;
|
|
347
|
-
cyImageState.botGuessed = false;
|
|
348
340
|
gameStates.set(key, state);
|
|
349
|
-
reply = `${session.text('chengyuImage.next')}\n${data.data.message}\n选项:${data.data.question.options.join('、')}\n[CQ:image,file=${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}]`;
|
|
350
342
|
}
|
|
351
343
|
else {
|
|
352
344
|
reply = '获取下一题失败,请稍后再试';
|
|
@@ -373,37 +365,6 @@ function apply(ctx, config) {
|
|
|
373
365
|
}
|
|
374
366
|
}
|
|
375
367
|
await session.send(reply);
|
|
376
|
-
const botPlay = getBotParticipate(session, 'chengyuImage');
|
|
377
|
-
if (botPlay && !cyImageState.botGuessed && cyImageState.options.length > 0) {
|
|
378
|
-
setTimeout(async () => {
|
|
379
|
-
const randomWords = [];
|
|
380
|
-
for (let i = 0; i < 4; i++) {
|
|
381
|
-
if (cyImageState.options.length > i) {
|
|
382
|
-
randomWords.push(cyImageState.options[Math.floor(Math.random() * cyImageState.options.length)]);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
const randomIdiom = randomWords.join('');
|
|
386
|
-
const botResponse = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
|
|
387
|
-
params: {
|
|
388
|
-
action: 'submit_answer',
|
|
389
|
-
id: currentId,
|
|
390
|
-
answer: randomIdiom
|
|
391
|
-
},
|
|
392
|
-
timeout: config.apiConfig.timeout
|
|
393
|
-
});
|
|
394
|
-
let botReply = session.text('chengyuImage.botGuess', [randomIdiom]);
|
|
395
|
-
if (botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
|
|
396
|
-
botReply += '\n' + session.text('chengyuImage.botWrong');
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
botReply += '\n' + session.text('chengyuImage.botRight', [randomIdiom]);
|
|
400
|
-
cyImageState.started = false;
|
|
401
|
-
}
|
|
402
|
-
cyImageState.botGuessed = true;
|
|
403
|
-
gameStates.set(key, state);
|
|
404
|
-
await session.send(botReply);
|
|
405
|
-
}, 3000);
|
|
406
|
-
}
|
|
407
368
|
}
|
|
408
369
|
catch (error) {
|
|
409
370
|
logger.error('看图猜成语API请求失败:', error);
|
|
@@ -448,28 +409,6 @@ function apply(ctx, config) {
|
|
|
448
409
|
reply = data.msg || '接龙失败,请换个成语试试';
|
|
449
410
|
}
|
|
450
411
|
await session.send(reply);
|
|
451
|
-
const botPlay = getBotParticipate(session, 'chengyuJielong');
|
|
452
|
-
if (botPlay && cyJlState.lastChar) {
|
|
453
|
-
setTimeout(async () => {
|
|
454
|
-
const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
|
|
455
|
-
params: {
|
|
456
|
-
id: config.apiConfig.cyjlUserId,
|
|
457
|
-
msg: `开始成语接龙`
|
|
458
|
-
},
|
|
459
|
-
timeout: config.apiConfig.timeout
|
|
460
|
-
});
|
|
461
|
-
if (botResponse.data.code === 200 && botResponse.data.data.system) {
|
|
462
|
-
const botIdiom = botResponse.data.data.system.idiom;
|
|
463
|
-
const botPinyin = botResponse.data.data.system.pinyin;
|
|
464
|
-
const botMeaning = botResponse.data.data.system.meaning;
|
|
465
|
-
const botChar = botResponse.data.data.current_char;
|
|
466
|
-
const botReply = session.text('chengyuJielong.botTurn', [botIdiom, botPinyin, botMeaning]);
|
|
467
|
-
cyJlState.lastChar = botChar;
|
|
468
|
-
gameStates.set(key, state);
|
|
469
|
-
await session.send(botReply);
|
|
470
|
-
}
|
|
471
|
-
}, 2000);
|
|
472
|
-
}
|
|
473
412
|
}
|
|
474
413
|
catch (error) {
|
|
475
414
|
logger.error('成语接龙API请求失败:', error);
|
|
@@ -490,6 +429,10 @@ function apply(ctx, config) {
|
|
|
490
429
|
const key = getSessionKey(session);
|
|
491
430
|
const state = gameStates.get(key) || initSessionState(key);
|
|
492
431
|
if (action === 'start') {
|
|
432
|
+
if (checkGameRunning(state, 'guessNumber')) {
|
|
433
|
+
await session.send(session.text('common.gameRunning'));
|
|
434
|
+
return '';
|
|
435
|
+
}
|
|
493
436
|
state.guessNumber.target = koishi_1.Random.int(config.guessNumber.min, config.guessNumber.max);
|
|
494
437
|
state.guessNumber.currentMin = config.guessNumber.min;
|
|
495
438
|
state.guessNumber.currentMax = config.guessNumber.max;
|
|
@@ -544,6 +487,10 @@ function apply(ctx, config) {
|
|
|
544
487
|
const key = getSessionKey(session);
|
|
545
488
|
const state = gameStates.get(key) || initSessionState(key);
|
|
546
489
|
if (action === 'start') {
|
|
490
|
+
if (checkGameRunning(state, 'wzHero')) {
|
|
491
|
+
await session.send(session.text('common.gameRunning'));
|
|
492
|
+
return '';
|
|
493
|
+
}
|
|
547
494
|
const finalDifficulty = difficulty || '中等';
|
|
548
495
|
if (!['简单', '中等', '困难'].includes(finalDifficulty)) {
|
|
549
496
|
await session.send('用法错误!正确用法:wzhero start [难度],难度可选:简单/中等/困难');
|
|
@@ -571,31 +518,6 @@ function apply(ctx, config) {
|
|
|
571
518
|
reply = data.message || '游戏开始失败,请稍后再试';
|
|
572
519
|
}
|
|
573
520
|
await session.send(reply);
|
|
574
|
-
const botPlay = getBotParticipate(session, 'wzHero');
|
|
575
|
-
if (botPlay) {
|
|
576
|
-
setTimeout(async () => {
|
|
577
|
-
const heroList = ['李白', '韩信', '貂蝉', '诸葛亮', '妲己', '亚瑟', '鲁班七号', '孙尚香', '孙悟空', '安琪拉'];
|
|
578
|
-
const randomHero = heroList[Math.floor(Math.random() * heroList.length)];
|
|
579
|
-
const botResponse = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
|
|
580
|
-
params: {
|
|
581
|
-
id: config.apiConfig.wzHeroUserId,
|
|
582
|
-
msg: randomHero
|
|
583
|
-
},
|
|
584
|
-
timeout: config.apiConfig.timeout
|
|
585
|
-
});
|
|
586
|
-
let botReply = session.text('wzHero.botGuess', [randomHero]);
|
|
587
|
-
if (botResponse.data.status !== 'success' || botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
|
|
588
|
-
botReply += '\n' + session.text('wzHero.botWrong');
|
|
589
|
-
}
|
|
590
|
-
else {
|
|
591
|
-
botReply += '\n' + session.text('wzHero.botRight', [randomHero]);
|
|
592
|
-
state.wzHero.started = false;
|
|
593
|
-
}
|
|
594
|
-
state.wzHero.botAnswered = true;
|
|
595
|
-
gameStates.set(key, state);
|
|
596
|
-
await session.send(botReply);
|
|
597
|
-
}, 2000);
|
|
598
|
-
}
|
|
599
521
|
}
|
|
600
522
|
catch (error) {
|
|
601
523
|
logger.error('王者英雄猜谜开始游戏失败:', error);
|
|
@@ -626,6 +548,10 @@ function apply(ctx, config) {
|
|
|
626
548
|
const key = getSessionKey(session);
|
|
627
549
|
const state = gameStates.get(key) || initSessionState(key);
|
|
628
550
|
if (action === 'start') {
|
|
551
|
+
if (checkGameRunning(state, 'chengyuImage')) {
|
|
552
|
+
await session.send(session.text('common.gameRunning'));
|
|
553
|
+
return '';
|
|
554
|
+
}
|
|
629
555
|
try {
|
|
630
556
|
const response = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
|
|
631
557
|
params: {
|
|
@@ -634,46 +560,14 @@ function apply(ctx, config) {
|
|
|
634
560
|
timeout: config.apiConfig.timeout
|
|
635
561
|
});
|
|
636
562
|
const data = response.data;
|
|
637
|
-
if (data.success) {
|
|
563
|
+
if (data.success && data.data?.question) {
|
|
638
564
|
state.chengyuImage.started = true;
|
|
639
565
|
state.chengyuImage.currentId = data.data.question.id;
|
|
640
566
|
state.chengyuImage.currentPage = data.data.question.page;
|
|
641
567
|
state.chengyuImage.options = data.data.question.options;
|
|
642
|
-
state.chengyuImage.botGuessed = false;
|
|
643
568
|
gameStates.set(key, state);
|
|
644
|
-
const reply = `${session.text('chengyuImage.
|
|
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}]`;
|
|
645
570
|
await session.send(reply);
|
|
646
|
-
const botPlay = getBotParticipate(session, 'chengyuImage');
|
|
647
|
-
if (botPlay) {
|
|
648
|
-
setTimeout(async () => {
|
|
649
|
-
const randomWords = [];
|
|
650
|
-
for (let i = 0; i < 4; i++) {
|
|
651
|
-
if (data.data.question.options.length > i) {
|
|
652
|
-
randomWords.push(data.data.question.options[Math.floor(Math.random() * data.data.question.options.length)]);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
const randomIdiom = randomWords.join('');
|
|
656
|
-
const botResponse = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
|
|
657
|
-
params: {
|
|
658
|
-
action: 'submit_answer',
|
|
659
|
-
id: data.data.question.id,
|
|
660
|
-
answer: randomIdiom
|
|
661
|
-
},
|
|
662
|
-
timeout: config.apiConfig.timeout
|
|
663
|
-
});
|
|
664
|
-
let botReply = session.text('chengyuImage.botGuess', [randomIdiom]);
|
|
665
|
-
if (botResponse.data.message.includes('错误') || botResponse.data.message.includes('不对')) {
|
|
666
|
-
botReply += '\n' + session.text('chengyuImage.botWrong');
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
botReply += '\n' + session.text('chengyuImage.botRight', [randomIdiom]);
|
|
670
|
-
state.chengyuImage.started = false;
|
|
671
|
-
}
|
|
672
|
-
state.chengyuImage.botGuessed = true;
|
|
673
|
-
gameStates.set(key, state);
|
|
674
|
-
await session.send(botReply);
|
|
675
|
-
}, 2000);
|
|
676
|
-
}
|
|
677
571
|
}
|
|
678
572
|
else {
|
|
679
573
|
await session.send('获取题目失败,请稍后再试');
|
|
@@ -706,6 +600,10 @@ function apply(ctx, config) {
|
|
|
706
600
|
const key = getSessionKey(session);
|
|
707
601
|
const state = gameStates.get(key) || initSessionState(key);
|
|
708
602
|
if (action === 'start') {
|
|
603
|
+
if (checkGameRunning(state, 'chengyuJielong')) {
|
|
604
|
+
await session.send(session.text('common.gameRunning'));
|
|
605
|
+
return '';
|
|
606
|
+
}
|
|
709
607
|
state.chengyuJielong.started = true;
|
|
710
608
|
state.chengyuJielong.botTurn = true;
|
|
711
609
|
gameStates.set(key, state);
|
|
@@ -31,9 +31,8 @@ chengyuImage:
|
|
|
31
31
|
next: "下一题来啦!"
|
|
32
32
|
hintUsage: "提示等级可选1-5,用法:提示 <等级>,如 提示 2"
|
|
33
33
|
apiError: "API请求失败,请稍后再试"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
botRight: "太棒了!我猜对了~就是{0} 🎊"
|
|
34
|
+
hintSuccess: "提示(等级{0}):{1}"
|
|
35
|
+
hintFail: "获取提示失败,请稍后再试"
|
|
37
36
|
disabled: "看图猜成语功能已关闭,请联系管理员开启"
|
|
38
37
|
|
|
39
38
|
chengyuJielong:
|
|
@@ -44,4 +43,7 @@ chengyuJielong:
|
|
|
44
43
|
apiError: "API请求失败,请稍后再试"
|
|
45
44
|
botTurn: "该我了!我接:{0}({1})\n释义:{2}"
|
|
46
45
|
botWin: "哈哈我接不上了,你赢啦~"
|
|
47
|
-
disabled: "成语接龙功能已关闭,请联系管理员开启"
|
|
46
|
+
disabled: "成语接龙功能已关闭,请联系管理员开启"
|
|
47
|
+
|
|
48
|
+
common:
|
|
49
|
+
gameRunning: "当前已有游戏在运行中,请先结束当前游戏后再开始新游戏!"
|