koishi-plugin-game-mini 0.2.0 → 0.2.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.d.ts +0 -2
- package/lib/index.js +159 -50
- package/lib/locales/locales/zh-CN.yml +31 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -19,12 +19,10 @@ export interface Config {
|
|
|
19
19
|
showRank: boolean;
|
|
20
20
|
};
|
|
21
21
|
wzHero: {
|
|
22
|
-
botParticipateInGroup: boolean;
|
|
23
22
|
totalRounds: number;
|
|
24
23
|
showRank: boolean;
|
|
25
24
|
};
|
|
26
25
|
chengyuImage: {
|
|
27
|
-
botParticipateInGroup: boolean;
|
|
28
26
|
totalRounds: number;
|
|
29
27
|
showRank: boolean;
|
|
30
28
|
};
|
package/lib/index.js
CHANGED
|
@@ -14,40 +14,114 @@ exports.name = 'game-mini';
|
|
|
14
14
|
exports.using = ['i18n'];
|
|
15
15
|
exports.inject = ['console'];
|
|
16
16
|
exports.Config = koishi_1.Schema.object({
|
|
17
|
-
enableNumberGuess: koishi_1.Schema.boolean().default(true)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
enableNumberGuess: koishi_1.Schema.boolean().default(true)
|
|
18
|
+
.description('是否启用猜数字游戏')
|
|
19
|
+
.i18n({ 'zh-CN': '启用猜数字游戏' }),
|
|
20
|
+
enableWzHero: koishi_1.Schema.boolean().default(true)
|
|
21
|
+
.description('是否启用王者英雄猜谜游戏')
|
|
22
|
+
.i18n({ 'zh-CN': '启用王者英雄猜谜' }),
|
|
23
|
+
enableChengyuImage: koishi_1.Schema.boolean().default(true)
|
|
24
|
+
.description('是否启用看图猜成语游戏')
|
|
25
|
+
.i18n({ 'zh-CN': '启用看图猜成语' }),
|
|
26
|
+
enableChengyuJielong: koishi_1.Schema.boolean().default(true)
|
|
27
|
+
.description('是否启用成语接龙游戏')
|
|
28
|
+
.i18n({ 'zh-CN': '启用成语接龙' }),
|
|
29
|
+
enablePrivateGame: koishi_1.Schema.boolean().default(true)
|
|
30
|
+
.description('是否允许私聊玩游戏')
|
|
31
|
+
.i18n({ 'zh-CN': '允许私聊玩游戏' }),
|
|
32
|
+
autoPlayDelay: koishi_1.Schema.number().min(0).default(10)
|
|
33
|
+
.description('成语接龙机器人自动接龙延迟(秒)')
|
|
34
|
+
.i18n({ 'zh-CN': '机器人自动接龙延迟(秒)' }),
|
|
35
|
+
autoPlayMaxCount: koishi_1.Schema.number().min(1).default(5)
|
|
36
|
+
.description('成语接龙机器人最大自动接龙次数')
|
|
37
|
+
.i18n({ 'zh-CN': '机器人最大自动接龙次数' }),
|
|
38
|
+
autoStopInactiveTime: koishi_1.Schema.number().min(0).default(30)
|
|
39
|
+
.description('游戏无操作自动停止时间(秒)')
|
|
40
|
+
.i18n({ 'zh-CN': '无操作自动停止时间(秒)' }),
|
|
25
41
|
guessNumber: koishi_1.Schema.object({
|
|
26
|
-
min: koishi_1.Schema.number().min(0).default(0)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
min: koishi_1.Schema.number().min(0).default(0)
|
|
43
|
+
.description('猜数字最小值')
|
|
44
|
+
.i18n({ 'zh-CN': '最小值' }),
|
|
45
|
+
max: koishi_1.Schema.number().min(1).default(100)
|
|
46
|
+
.description('猜数字最大值')
|
|
47
|
+
.i18n({ 'zh-CN': '最大值' }),
|
|
48
|
+
botParticipateInGroup: koishi_1.Schema.boolean().default(true)
|
|
49
|
+
.description('群聊中机器人是否参与猜数字')
|
|
50
|
+
.i18n({ 'zh-CN': '机器人参与群聊游戏' }),
|
|
51
|
+
totalRounds: koishi_1.Schema.number().min(1).default(10)
|
|
52
|
+
.description('猜数字总回合数')
|
|
53
|
+
.i18n({ 'zh-CN': '总回合数' }),
|
|
54
|
+
showRank: koishi_1.Schema.boolean().default(true)
|
|
55
|
+
.description('游戏结束后是否显示排行榜')
|
|
56
|
+
.i18n({ 'zh-CN': '显示排行榜' }),
|
|
57
|
+
}).description('猜数字游戏配置')
|
|
58
|
+
.i18n({ 'zh-CN': '猜数字游戏配置' }),
|
|
32
59
|
wzHero: koishi_1.Schema.object({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
totalRounds: koishi_1.Schema.number().min(1).default(10)
|
|
61
|
+
.description('王者英雄猜谜总回合数')
|
|
62
|
+
.i18n({ 'zh-CN': '总回合数' }),
|
|
63
|
+
showRank: koishi_1.Schema.boolean().default(true)
|
|
64
|
+
.description('游戏结束后是否显示排行榜')
|
|
65
|
+
.i18n({ 'zh-CN': '显示排行榜' }),
|
|
66
|
+
}).description('王者英雄猜谜游戏配置')
|
|
67
|
+
.i18n({ 'zh-CN': '王者英雄猜谜配置' }),
|
|
37
68
|
chengyuImage: koishi_1.Schema.object({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
totalRounds: koishi_1.Schema.number().min(1).default(10)
|
|
70
|
+
.description('看图猜成语总回合数')
|
|
71
|
+
.i18n({ 'zh-CN': '总回合数' }),
|
|
72
|
+
showRank: koishi_1.Schema.boolean().default(true)
|
|
73
|
+
.description('游戏结束后是否显示排行榜')
|
|
74
|
+
.i18n({ 'zh-CN': '显示排行榜' }),
|
|
75
|
+
}).description('看图猜成语游戏配置')
|
|
76
|
+
.i18n({ 'zh-CN': '看图猜成语配置' }),
|
|
42
77
|
chengyuJielong: koishi_1.Schema.object({
|
|
43
|
-
botParticipateInGroup: koishi_1.Schema.boolean().default(true)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
78
|
+
botParticipateInGroup: koishi_1.Schema.boolean().default(true)
|
|
79
|
+
.description('群聊中机器人是否参与成语接龙')
|
|
80
|
+
.i18n({ 'zh-CN': '机器人参与群聊游戏' }),
|
|
81
|
+
totalRounds: koishi_1.Schema.number().min(1).default(10)
|
|
82
|
+
.description('成语接龙总回合数')
|
|
83
|
+
.i18n({ 'zh-CN': '总回合数' }),
|
|
84
|
+
showRank: koishi_1.Schema.boolean().default(true)
|
|
85
|
+
.description('游戏结束后是否显示排行榜')
|
|
86
|
+
.i18n({ 'zh-CN': '显示排行榜' }),
|
|
87
|
+
}).description('成语接龙游戏配置')
|
|
88
|
+
.i18n({ 'zh-CN': '成语接龙配置' }),
|
|
47
89
|
apiConfig: koishi_1.Schema.object({
|
|
48
|
-
timeout: koishi_1.Schema.number().default(5000)
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
timeout: koishi_1.Schema.number().default(5000)
|
|
91
|
+
.description('API请求超时时间(毫秒)')
|
|
92
|
+
.i18n({ 'zh-CN': '请求超时时间(毫秒)' }),
|
|
93
|
+
}).description('API接口配置')
|
|
94
|
+
.i18n({ 'zh-CN': 'API接口配置' }),
|
|
95
|
+
}).i18n({
|
|
96
|
+
'zh-CN': {
|
|
97
|
+
'enableNumberGuess': '启用猜数字游戏',
|
|
98
|
+
'enableWzHero': '启用王者英雄猜谜',
|
|
99
|
+
'enableChengyuImage': '启用看图猜成语',
|
|
100
|
+
'enableChengyuJielong': '启用成语接龙',
|
|
101
|
+
'enablePrivateGame': '允许私聊玩游戏',
|
|
102
|
+
'autoPlayDelay': '机器人自动接龙延迟(秒)',
|
|
103
|
+
'autoPlayMaxCount': '机器人最大自动接龙次数',
|
|
104
|
+
'autoStopInactiveTime': '无操作自动停止时间(秒)',
|
|
105
|
+
'guessNumber': '猜数字游戏配置',
|
|
106
|
+
'guessNumber.min': '最小值',
|
|
107
|
+
'guessNumber.max': '最大值',
|
|
108
|
+
'guessNumber.botParticipateInGroup': '机器人参与群聊游戏',
|
|
109
|
+
'guessNumber.totalRounds': '总回合数',
|
|
110
|
+
'guessNumber.showRank': '显示排行榜',
|
|
111
|
+
'wzHero': '王者英雄猜谜配置',
|
|
112
|
+
'wzHero.totalRounds': '总回合数',
|
|
113
|
+
'wzHero.showRank': '显示排行榜',
|
|
114
|
+
'chengyuImage': '看图猜成语配置',
|
|
115
|
+
'chengyuImage.totalRounds': '总回合数',
|
|
116
|
+
'chengyuImage.showRank': '显示排行榜',
|
|
117
|
+
'chengyuJielong': '成语接龙配置',
|
|
118
|
+
'chengyuJielong.botParticipateInGroup': '机器人参与群聊游戏',
|
|
119
|
+
'chengyuJielong.totalRounds': '总回合数',
|
|
120
|
+
'chengyuJielong.showRank': '显示排行榜',
|
|
121
|
+
'apiConfig': 'API接口配置',
|
|
122
|
+
'apiConfig.timeout': '请求超时时间(毫秒)'
|
|
123
|
+
}
|
|
124
|
+
});
|
|
51
125
|
const logger = new koishi_1.Logger('game-mini');
|
|
52
126
|
const gameStates = new Map();
|
|
53
127
|
const getSessionKey = (s) => s.channelId ? `g:${s.channelId}` : `p:${s.userId}`;
|
|
@@ -77,11 +151,17 @@ const checkGameRunning = (s, t) => {
|
|
|
77
151
|
return true;
|
|
78
152
|
return false;
|
|
79
153
|
};
|
|
154
|
+
const clearGameTimer = (state) => {
|
|
155
|
+
if (state.stopTimer)
|
|
156
|
+
clearTimeout(state.stopTimer);
|
|
157
|
+
};
|
|
80
158
|
const clearAllTimers = (st) => {
|
|
159
|
+
clearGameTimer(st.guessNumber);
|
|
160
|
+
clearGameTimer(st.wzHero);
|
|
161
|
+
clearGameTimer(st.chengyuImage);
|
|
162
|
+
clearGameTimer(st.chengyuJielong);
|
|
81
163
|
if (st.chengyuJielong.autoPlayTimer)
|
|
82
164
|
clearTimeout(st.chengyuJielong.autoPlayTimer);
|
|
83
|
-
if (st.chengyuJielong.stopTimer)
|
|
84
|
-
clearTimeout(st.chengyuJielong.stopTimer);
|
|
85
165
|
};
|
|
86
166
|
const initState = (key, c) => {
|
|
87
167
|
const s = {
|
|
@@ -147,7 +227,7 @@ const generateRankText = (players) => {
|
|
|
147
227
|
const sortedPlayers = playerList.sort((a, b) => b.score - a.score);
|
|
148
228
|
let rankText = '🏆 排行榜 🏆\n';
|
|
149
229
|
sortedPlayers.forEach((player, index) => {
|
|
150
|
-
rankText += `${index + 1}. ${player.name}
|
|
230
|
+
rankText += `${index + 1}. ${player.name} - 得分:${player.score}分(答对${player.correctCount}题)\n`;
|
|
151
231
|
});
|
|
152
232
|
return rankText.trim();
|
|
153
233
|
};
|
|
@@ -156,6 +236,7 @@ const clearGameData = (gameState) => {
|
|
|
156
236
|
gameState.participants = [];
|
|
157
237
|
gameState.currentRound = 0;
|
|
158
238
|
gameState.started = false;
|
|
239
|
+
clearGameTimer(gameState);
|
|
159
240
|
};
|
|
160
241
|
const addScoreToOthers = (players, excludePlayerKey) => {
|
|
161
242
|
Object.keys(players).forEach(playerKey => {
|
|
@@ -164,6 +245,18 @@ const addScoreToOthers = (players, excludePlayerKey) => {
|
|
|
164
245
|
}
|
|
165
246
|
});
|
|
166
247
|
};
|
|
248
|
+
const setupAutoStop = (session, state, cfg, endMsg, showRank) => {
|
|
249
|
+
clearGameTimer(state);
|
|
250
|
+
if (cfg.autoStopInactiveTime <= 0)
|
|
251
|
+
return;
|
|
252
|
+
state.stopTimer = setTimeout(() => {
|
|
253
|
+
clearGameData(state);
|
|
254
|
+
session.send(endMsg);
|
|
255
|
+
if (showRank && session.channelId) {
|
|
256
|
+
session.send(generateRankText(state.players));
|
|
257
|
+
}
|
|
258
|
+
}, cfg.autoStopInactiveTime * 1000);
|
|
259
|
+
};
|
|
167
260
|
function apply(ctx, cfg) {
|
|
168
261
|
const d = {
|
|
169
262
|
guessNumber: {
|
|
@@ -179,6 +272,7 @@ function apply(ctx, cfg) {
|
|
|
179
272
|
rankTitle: "🏆 排行榜 🏆",
|
|
180
273
|
rankEmpty: "暂无参与记录~",
|
|
181
274
|
disabled: "猜数字功能已关闭,请联系管理员开启",
|
|
275
|
+
autoStop: "游戏因长时间无人操作,已自动结束"
|
|
182
276
|
},
|
|
183
277
|
wzHero: {
|
|
184
278
|
start: "王者英雄猜谜开始!本次共 {0} 回合~",
|
|
@@ -194,6 +288,7 @@ function apply(ctx, cfg) {
|
|
|
194
288
|
rankTitle: "🏆 排行榜 🏆",
|
|
195
289
|
rankEmpty: "暂无参与记录~",
|
|
196
290
|
disabled: "王者英雄猜谜功能已关闭,请联系管理员开启",
|
|
291
|
+
autoStop: "游戏因长时间无人操作,已自动结束"
|
|
197
292
|
},
|
|
198
293
|
chengyuImage: {
|
|
199
294
|
start: "看图猜成语比赛开始!本次共 {0} 回合~",
|
|
@@ -211,6 +306,7 @@ function apply(ctx, cfg) {
|
|
|
211
306
|
rankTitle: "🏆 排行榜 🏆",
|
|
212
307
|
rankEmpty: "暂无参与记录~",
|
|
213
308
|
disabled: "看图猜成语功能已关闭,请联系管理员开启",
|
|
309
|
+
autoStop: "游戏因长时间无人操作,已自动结束"
|
|
214
310
|
},
|
|
215
311
|
chengyuJielong: {
|
|
216
312
|
start: "成语接龙比赛开始!本次共 {0} 回合~我先来~",
|
|
@@ -230,6 +326,7 @@ function apply(ctx, cfg) {
|
|
|
230
326
|
rankTitle: "🏆 排行榜 🏆",
|
|
231
327
|
rankEmpty: "暂无参与记录~",
|
|
232
328
|
disabled: "成语接龙功能已关闭,请联系管理员开启",
|
|
329
|
+
autoStop: "游戏因长时间无人操作,已自动结束"
|
|
233
330
|
},
|
|
234
331
|
common: {
|
|
235
332
|
gameRunning: "当前已有游戏在运行中,请先结束当前游戏后再开始新游戏!",
|
|
@@ -266,20 +363,6 @@ function apply(ctx, cfg) {
|
|
|
266
363
|
doAutoPlay(session, key, st);
|
|
267
364
|
}, delay);
|
|
268
365
|
};
|
|
269
|
-
const scheduleStop = (session, key, st) => {
|
|
270
|
-
clearTimeout(st.chengyuJielong.stopTimer);
|
|
271
|
-
st.chengyuJielong.stopTimer = setTimeout(() => {
|
|
272
|
-
st.chengyuJielong.started = false;
|
|
273
|
-
clearAllTimers(st);
|
|
274
|
-
session.send(d.common.gameStoppedByInactive);
|
|
275
|
-
if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
|
|
276
|
-
const rankText = generateRankText(st.chengyuJielong.players);
|
|
277
|
-
session.send(rankText);
|
|
278
|
-
}
|
|
279
|
-
clearGameData(st.chengyuJielong);
|
|
280
|
-
gameStates.set(key, st);
|
|
281
|
-
}, cfg.autoStopInactiveTime * 1000);
|
|
282
|
-
};
|
|
283
366
|
const doAutoPlay = async (session, key, st) => {
|
|
284
367
|
if (!st.chengyuJielong.started)
|
|
285
368
|
return;
|
|
@@ -289,7 +372,7 @@ function apply(ctx, cfg) {
|
|
|
289
372
|
session.send(d.chengyuJielong.autoPlayTooMany.replace('{0}', String(cfg.autoPlayMaxCount)));
|
|
290
373
|
st.chengyuJielong.hasTriggeredAutoPlay = true;
|
|
291
374
|
gameStates.set(key, st);
|
|
292
|
-
|
|
375
|
+
setupAutoStop(session, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
293
376
|
return;
|
|
294
377
|
}
|
|
295
378
|
st.chengyuJielong.hasTriggeredAutoPlay = true;
|
|
@@ -340,7 +423,7 @@ function apply(ctx, cfg) {
|
|
|
340
423
|
await session.send(d.chengyuJielong.apiError);
|
|
341
424
|
}
|
|
342
425
|
gameStates.set(key, st);
|
|
343
|
-
|
|
426
|
+
setupAutoStop(session, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
344
427
|
};
|
|
345
428
|
ctx.middleware(async (session, next) => {
|
|
346
429
|
if (!session.content)
|
|
@@ -353,11 +436,13 @@ function apply(ctx, cfg) {
|
|
|
353
436
|
const playerKey = `${session.platform}_${session.userId || 'unknown'}`;
|
|
354
437
|
if (cfg.enableChengyuJielong && st.chengyuJielong.started) {
|
|
355
438
|
refreshActive(st);
|
|
439
|
+
clearGameTimer(st.chengyuJielong);
|
|
356
440
|
if (!st.chengyuJielong.players[playerKey]) {
|
|
357
441
|
st.chengyuJielong.players[playerKey] = getPlayerData(session);
|
|
358
442
|
st.chengyuJielong.participants.push(playerKey);
|
|
359
443
|
}
|
|
360
444
|
if (!isFourCharIdiom(content)) {
|
|
445
|
+
setupAutoStop(session, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
361
446
|
scheduleAutoPlay(session, key, st);
|
|
362
447
|
return next();
|
|
363
448
|
}
|
|
@@ -407,6 +492,7 @@ function apply(ctx, cfg) {
|
|
|
407
492
|
m += '\n' + d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString());
|
|
408
493
|
await session.send(m);
|
|
409
494
|
st.chengyuJielong.hasTriggeredAutoPlay = false;
|
|
495
|
+
setupAutoStop(session, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
410
496
|
scheduleAutoPlay(session, key, st);
|
|
411
497
|
}
|
|
412
498
|
}
|
|
@@ -419,12 +505,14 @@ function apply(ctx, cfg) {
|
|
|
419
505
|
}
|
|
420
506
|
catch (error) {
|
|
421
507
|
await session.send(d.chengyuJielong.apiError);
|
|
508
|
+
setupAutoStop(session, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
422
509
|
scheduleAutoPlay(session, key, st);
|
|
423
510
|
}
|
|
424
511
|
gameStates.set(key, st);
|
|
425
512
|
return;
|
|
426
513
|
}
|
|
427
514
|
if (cfg.enableChengyuImage && st.chengyuImage.started) {
|
|
515
|
+
clearGameTimer(st.chengyuImage);
|
|
428
516
|
if (!st.chengyuImage.players[playerKey]) {
|
|
429
517
|
st.chengyuImage.players[playerKey] = getPlayerData(session);
|
|
430
518
|
st.chengyuImage.participants.push(playerKey);
|
|
@@ -449,10 +537,13 @@ function apply(ctx, cfg) {
|
|
|
449
537
|
catch (error) {
|
|
450
538
|
await session.send(d.chengyuImage.hintError);
|
|
451
539
|
}
|
|
540
|
+
setupAutoStop(session, st.chengyuImage, cfg, d.chengyuImage.autoStop, cfg.chengyuImage.showRank);
|
|
452
541
|
return;
|
|
453
542
|
}
|
|
454
|
-
if (!isFourCharIdiom(content))
|
|
543
|
+
if (!isFourCharIdiom(content)) {
|
|
544
|
+
setupAutoStop(session, st.chengyuImage, cfg, d.chengyuImage.autoStop, cfg.chengyuImage.showRank);
|
|
455
545
|
return next();
|
|
546
|
+
}
|
|
456
547
|
try {
|
|
457
548
|
const r = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
|
|
458
549
|
params: {
|
|
@@ -472,6 +563,7 @@ function apply(ctx, cfg) {
|
|
|
472
563
|
st.chengyuImage.currentRound += 1;
|
|
473
564
|
if (st.chengyuImage.currentRound > st.chengyuImage.totalRounds) {
|
|
474
565
|
st.chengyuImage.started = false;
|
|
566
|
+
clearGameTimer(st.chengyuImage);
|
|
475
567
|
await session.send(reply);
|
|
476
568
|
await session.send(d.chengyuImage.gameEnd);
|
|
477
569
|
if (cfg.chengyuImage.showRank && !isPrivate(session)) {
|
|
@@ -503,6 +595,7 @@ function apply(ctx, cfg) {
|
|
|
503
595
|
else {
|
|
504
596
|
await session.send('获取下一题失败,比赛结束!');
|
|
505
597
|
st.chengyuImage.started = false;
|
|
598
|
+
clearGameTimer(st.chengyuImage);
|
|
506
599
|
if (cfg.chengyuImage.showRank && !isPrivate(session)) {
|
|
507
600
|
const rankText = generateRankText(st.chengyuImage.players);
|
|
508
601
|
await session.send(rankText);
|
|
@@ -523,10 +616,12 @@ function apply(ctx, cfg) {
|
|
|
523
616
|
catch (error) {
|
|
524
617
|
await session.send(d.chengyuImage.apiError);
|
|
525
618
|
}
|
|
619
|
+
setupAutoStop(session, st.chengyuImage, cfg, d.chengyuImage.autoStop, cfg.chengyuImage.showRank);
|
|
526
620
|
gameStates.set(key, st);
|
|
527
621
|
return;
|
|
528
622
|
}
|
|
529
623
|
if (cfg.enableWzHero && st.wzHero.started) {
|
|
624
|
+
clearGameTimer(st.wzHero);
|
|
530
625
|
if (!st.wzHero.players[playerKey]) {
|
|
531
626
|
st.wzHero.players[playerKey] = getPlayerData(session);
|
|
532
627
|
st.wzHero.participants.push(playerKey);
|
|
@@ -546,6 +641,7 @@ function apply(ctx, cfg) {
|
|
|
546
641
|
st.wzHero.currentRound += 1;
|
|
547
642
|
if (st.wzHero.currentRound > st.wzHero.totalRounds) {
|
|
548
643
|
st.wzHero.started = false;
|
|
644
|
+
clearGameTimer(st.wzHero);
|
|
549
645
|
await session.send(text);
|
|
550
646
|
await session.send(d.wzHero.gameEnd);
|
|
551
647
|
if (cfg.wzHero.showRank && !isPrivate(session)) {
|
|
@@ -582,23 +678,28 @@ function apply(ctx, cfg) {
|
|
|
582
678
|
catch (error) {
|
|
583
679
|
await session.send(d.wzHero.apiError);
|
|
584
680
|
}
|
|
681
|
+
setupAutoStop(session, st.wzHero, cfg, d.wzHero.autoStop, cfg.wzHero.showRank);
|
|
585
682
|
gameStates.set(key, st);
|
|
586
683
|
return;
|
|
587
684
|
}
|
|
588
685
|
if (cfg.enableNumberGuess && st.guessNumber.started) {
|
|
686
|
+
clearGameTimer(st.guessNumber);
|
|
589
687
|
if (!st.guessNumber.players[playerKey]) {
|
|
590
688
|
st.guessNumber.players[playerKey] = getPlayerData(session);
|
|
591
689
|
st.guessNumber.participants.push(playerKey);
|
|
592
690
|
}
|
|
593
691
|
const num = parseInt(content);
|
|
594
|
-
if (isNaN(num))
|
|
692
|
+
if (isNaN(num)) {
|
|
693
|
+
setupAutoStop(session, st.guessNumber, cfg, d.guessNumber.autoStop, cfg.guessNumber.showRank);
|
|
595
694
|
return next();
|
|
695
|
+
}
|
|
596
696
|
if (num === st.guessNumber.target) {
|
|
597
697
|
await session.send(d.guessNumber.correct);
|
|
598
698
|
addScoreToOthers(st.guessNumber.players, playerKey);
|
|
599
699
|
st.guessNumber.currentRound += 1;
|
|
600
700
|
if (st.guessNumber.currentRound > st.guessNumber.totalRounds) {
|
|
601
701
|
st.guessNumber.started = false;
|
|
702
|
+
clearGameTimer(st.guessNumber);
|
|
602
703
|
await session.send(d.guessNumber.gameEnd);
|
|
603
704
|
if (cfg.guessNumber.showRank && !isPrivate(session)) {
|
|
604
705
|
const rankText = generateRankText(st.guessNumber.players);
|
|
@@ -618,6 +719,7 @@ function apply(ctx, cfg) {
|
|
|
618
719
|
else {
|
|
619
720
|
await session.send(d.guessNumber.tooBig.replace('{0}', num.toString()).replace('{1}', st.guessNumber.currentMin.toString()));
|
|
620
721
|
}
|
|
722
|
+
setupAutoStop(session, st.guessNumber, cfg, d.guessNumber.autoStop, cfg.guessNumber.showRank);
|
|
621
723
|
gameStates.set(key, st);
|
|
622
724
|
return;
|
|
623
725
|
}
|
|
@@ -659,6 +761,7 @@ function apply(ctx, cfg) {
|
|
|
659
761
|
t = d.wzHero.start.replace('{0}', cfg.wzHero.totalRounds.toString()) + '\n' + t;
|
|
660
762
|
st.wzHero.currentAnswer = dt.hint || '';
|
|
661
763
|
await s.send(t);
|
|
764
|
+
setupAutoStop(s, st.wzHero, cfg, d.wzHero.autoStop, cfg.wzHero.showRank);
|
|
662
765
|
}
|
|
663
766
|
else {
|
|
664
767
|
await s.send(dt.message || '开始失败');
|
|
@@ -671,6 +774,7 @@ function apply(ctx, cfg) {
|
|
|
671
774
|
}
|
|
672
775
|
else if (action === 'stop') {
|
|
673
776
|
st.wzHero.started = false;
|
|
777
|
+
clearGameTimer(st.wzHero);
|
|
674
778
|
await s.send(d.wzHero.stop);
|
|
675
779
|
if (cfg.wzHero.showRank && !isPrivate(s)) {
|
|
676
780
|
const rankText = generateRankText(st.wzHero.players);
|
|
@@ -717,6 +821,7 @@ function apply(ctx, cfg) {
|
|
|
717
821
|
await s.send(d.chengyuImage.start.replace('{0}', cfg.chengyuImage.totalRounds.toString()));
|
|
718
822
|
await s.send(`第 1 题来啦!\n请从选项中选择4个字组成成语\n选项:${dt.data.question.options.join('、')}`);
|
|
719
823
|
await s.send(koishi_1.segment.image(dt.data.question.image_url));
|
|
824
|
+
setupAutoStop(s, st.chengyuImage, cfg, d.chengyuImage.autoStop, cfg.chengyuImage.showRank);
|
|
720
825
|
}
|
|
721
826
|
else {
|
|
722
827
|
await s.send('获取题目失败,请稍后再试');
|
|
@@ -730,6 +835,7 @@ function apply(ctx, cfg) {
|
|
|
730
835
|
}
|
|
731
836
|
else if (action === 'stop') {
|
|
732
837
|
st.chengyuImage.started = false;
|
|
838
|
+
clearGameTimer(st.chengyuImage);
|
|
733
839
|
await s.send(d.chengyuImage.stop);
|
|
734
840
|
if (cfg.chengyuImage.showRank && !isPrivate(s)) {
|
|
735
841
|
const rankText = generateRankText(st.chengyuImage.players);
|
|
@@ -793,6 +899,7 @@ function apply(ctx, cfg) {
|
|
|
793
899
|
catch (error) {
|
|
794
900
|
await s.send(d.chengyuJielong.apiError);
|
|
795
901
|
}
|
|
902
|
+
setupAutoStop(s, st.chengyuJielong, cfg, d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank);
|
|
796
903
|
gameStates.set(key, st);
|
|
797
904
|
scheduleAutoPlay(s, key, st);
|
|
798
905
|
}
|
|
@@ -835,9 +942,11 @@ function apply(ctx, cfg) {
|
|
|
835
942
|
gameStates.set(key, st);
|
|
836
943
|
await s.send(d.guessNumber.start.replace('{0}', cfg.guessNumber.totalRounds.toString()));
|
|
837
944
|
await s.send(`猜数字范围:${st.guessNumber.currentMin} - ${st.guessNumber.currentMax},开始你的猜测吧!`);
|
|
945
|
+
setupAutoStop(s, st.guessNumber, cfg, d.guessNumber.autoStop, cfg.guessNumber.showRank);
|
|
838
946
|
}
|
|
839
947
|
else if (action === 'stop') {
|
|
840
948
|
st.guessNumber.started = false;
|
|
949
|
+
clearGameTimer(st.guessNumber);
|
|
841
950
|
await s.send(d.guessNumber.stop);
|
|
842
951
|
if (cfg.guessNumber.showRank && !isPrivate(s)) {
|
|
843
952
|
const rankText = generateRankText(st.guessNumber.players);
|
|
@@ -1,4 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
config:
|
|
2
|
+
game-mini:
|
|
3
|
+
enableNumberGuess: 启用猜数字游戏
|
|
4
|
+
enableWzHero: 启用王者英雄猜谜
|
|
5
|
+
enableChengyuImage: 启用看图猜成语
|
|
6
|
+
enableChengyuJielong: 启用成语接龙
|
|
7
|
+
enablePrivateGame: 允许私聊玩游戏
|
|
8
|
+
autoPlayDelay: 机器人自动接龙延迟(秒)
|
|
9
|
+
autoPlayMaxCount: 机器人最大自动接龙次数
|
|
10
|
+
autoStopInactiveTime: 无操作自动停止时间(秒)
|
|
11
|
+
guessNumber: 猜数字游戏配置
|
|
12
|
+
guessNumber.min: 最小值
|
|
13
|
+
guessNumber.max: 最大值
|
|
14
|
+
guessNumber.botParticipateInGroup: 机器人参与群聊游戏
|
|
15
|
+
guessNumber.totalRounds: 总回合数
|
|
16
|
+
guessNumber.showRank: 显示排行榜
|
|
17
|
+
wzHero: 王者英雄猜谜配置
|
|
18
|
+
wzHero.botParticipateInGroup: 机器人参与群聊游戏
|
|
19
|
+
wzHero.totalRounds: 总回合数
|
|
20
|
+
wzHero.showRank: 显示排行榜
|
|
21
|
+
chengyuImage: 看图猜成语配置
|
|
22
|
+
chengyuImage.botParticipateInGroup: 机器人参与群聊游戏
|
|
23
|
+
chengyuImage.totalRounds: 总回合数
|
|
24
|
+
chengyuImage.showRank: 显示排行榜
|
|
25
|
+
chengyuJielong: 成语接龙配置
|
|
26
|
+
chengyuJielong.botParticipateInGroup: 机器人参与群聊游戏
|
|
27
|
+
chengyuJielong.totalRounds: 总回合数
|
|
28
|
+
chengyuJielong.showRank: 显示排行榜
|
|
29
|
+
apiConfig: API接口配置
|
|
30
|
+
apiConfig.timeout: 请求超时时间(毫秒)
|
|
31
|
+
|
|
2
32
|
guessNumber:
|
|
3
33
|
usage: "用法错误!正确用法:guess start/stop 或 直接输入数字"
|
|
4
34
|
start: "猜数字比赛开始!本次共 {0} 回合~"
|