koishi-plugin-game-mini 0.3.3 → 0.3.5

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
@@ -61,6 +61,7 @@ export interface Config {
61
61
  penaltyScore: number;
62
62
  rewardScore: number;
63
63
  messages: {
64
+ enabled: boolean;
64
65
  usage: string;
65
66
  start: string;
66
67
  stop: string;
@@ -83,6 +84,7 @@ export interface Config {
83
84
  autoStopInactiveTime: number;
84
85
  rewardScore: number;
85
86
  messages: {
87
+ enabled: boolean;
86
88
  usage: string;
87
89
  start: string;
88
90
  stop: string;
@@ -106,6 +108,7 @@ export interface Config {
106
108
  autoStopInactiveTime: number;
107
109
  rewardScore: number;
108
110
  messages: {
111
+ enabled: boolean;
109
112
  usage: string;
110
113
  start: string;
111
114
  stop: string;
@@ -133,6 +136,7 @@ export interface Config {
133
136
  maxRounds: number;
134
137
  botParticipate: boolean;
135
138
  messages: {
139
+ enabled: boolean;
136
140
  usage: string;
137
141
  start: string;
138
142
  stop: string;
@@ -146,8 +150,6 @@ export interface Config {
146
150
  wrong: string;
147
151
  roundEnd: string;
148
152
  gameEnd: string;
149
- rankTitle: string;
150
- rankEmpty: string;
151
153
  disabled: string;
152
154
  autoStop: string;
153
155
  };
@@ -173,6 +175,7 @@ export interface Config {
173
175
  autoStopInactiveTime: number;
174
176
  rewardScore: number;
175
177
  messages: {
178
+ enabled: boolean;
176
179
  usage: string;
177
180
  start: string;
178
181
  stop: string;
package/lib/index.js CHANGED
@@ -77,8 +77,6 @@ const defaultMessages = {
77
77
  wrong: "接龙失败!",
78
78
  roundEnd: "第 {0} 回合结束!剩余回合:{1}",
79
79
  gameEnd: "🎉 成语接龙比赛结束!🎉",
80
- rankTitle: "🏆 本局排行榜 🏆",
81
- rankEmpty: "暂无参与记录~",
82
80
  disabled: "成语接龙功能已关闭,请联系管理员开启",
83
81
  autoStop: "太久没人玩啦,比赛自动结束~"
84
82
  },
@@ -164,6 +162,7 @@ exports.Config = koishi_1.Schema.intersect([
164
162
  penaltyScore: koishi_1.Schema.number().max(0).default(-1).description('猜中者扣除分数(负数)'),
165
163
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('其他人奖励分数'),
166
164
  messages: koishi_1.Schema.object({
165
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
167
166
  usage: koishi_1.Schema.string().default(defaultMessages.guessNumber.usage).description('用法错误提示\n{0}-最小值, {1}-最大值'),
168
167
  start: koishi_1.Schema.string().default(defaultMessages.guessNumber.start).description('游戏开始提示\n{0}-总回合数'),
169
168
  stop: koishi_1.Schema.string().default(defaultMessages.guessNumber.stop).description('游戏停止提示'),
@@ -188,6 +187,7 @@ exports.Config = koishi_1.Schema.intersect([
188
187
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
189
188
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
190
189
  messages: koishi_1.Schema.object({
190
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
191
191
  usage: koishi_1.Schema.string().default(defaultMessages.wzHero.usage).description('用法错误提示'),
192
192
  start: koishi_1.Schema.string().default(defaultMessages.wzHero.start).description('游戏开始提示\n{0}-总回合数, {1}-难度'),
193
193
  stop: koishi_1.Schema.string().default(defaultMessages.wzHero.stop).description('游戏停止提示'),
@@ -213,6 +213,7 @@ exports.Config = koishi_1.Schema.intersect([
213
213
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
214
214
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
215
215
  messages: koishi_1.Schema.object({
216
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
216
217
  usage: koishi_1.Schema.string().default(defaultMessages.chengyuImage.usage).description('用法错误提示'),
217
218
  start: koishi_1.Schema.string().default(defaultMessages.chengyuImage.start).description('游戏开始提示\n{0}-总回合数, {1}-提示级别'),
218
219
  stop: koishi_1.Schema.string().default(defaultMessages.chengyuImage.stop).description('游戏停止提示'),
@@ -235,13 +236,14 @@ exports.Config = koishi_1.Schema.intersect([
235
236
  koishi_1.Schema.object({
236
237
  chengyuJielong: koishi_1.Schema.object({
237
238
  totalRounds: koishi_1.Schema.number().min(1).default(10).description('总回合数'),
238
- showRank: koishi_1.Schema.boolean().default(true).description('游戏结束后显示本局排行榜'),
239
+ showRank: koishi_1.Schema.boolean().default(false).description('游戏结束后显示本局排行榜'),
239
240
  autoPlayDelay: koishi_1.Schema.number().min(0).default(10).description('机器人自动操作延迟(秒)'),
240
241
  autoPlayMaxCount: koishi_1.Schema.number().min(1).default(5).description('机器人最大自动操作次数'),
241
242
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
242
243
  maxRounds: koishi_1.Schema.number().min(0).default(10).description('最大接龙回合数(0为无限)'),
243
244
  botParticipate: koishi_1.Schema.boolean().default(false).description('机器人是否参与接龙'),
244
245
  messages: koishi_1.Schema.object({
246
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
245
247
  usage: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.usage).description('用法错误提示'),
246
248
  start: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.start).description('游戏开始提示\n{0}-总回合数'),
247
249
  stop: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.stop).description('游戏停止提示'),
@@ -255,8 +257,6 @@ exports.Config = koishi_1.Schema.intersect([
255
257
  wrong: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.wrong).description('接龙失败提示'),
256
258
  roundEnd: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.roundEnd).description('回合结束提示\n{0}-当前回合, {1}-剩余回合'),
257
259
  gameEnd: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.gameEnd).description('游戏结束提示'),
258
- rankTitle: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.rankTitle).description('本局排行榜标题'),
259
- rankEmpty: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.rankEmpty).description('本局排行榜为空提示'),
260
260
  disabled: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.disabled).description('功能禁用提示'),
261
261
  autoStop: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.autoStop).description('自动停止提示'),
262
262
  }).description('💬 成语接龙消息配置'),
@@ -284,6 +284,7 @@ exports.Config = koishi_1.Schema.intersect([
284
284
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
285
285
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
286
286
  messages: koishi_1.Schema.object({
287
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
287
288
  usage: koishi_1.Schema.string().default(defaultMessages.calc24.usage).description('用法错误提示'),
288
289
  start: koishi_1.Schema.string().default(defaultMessages.calc24.start).description('游戏开始提示\n{0}-总回合数, {1}-难度'),
289
290
  stop: koishi_1.Schema.string().default(defaultMessages.calc24.stop).description('游戏停止提示'),
@@ -303,7 +304,7 @@ exports.Config = koishi_1.Schema.intersect([
303
304
  }),
304
305
  koishi_1.Schema.object({
305
306
  apiConfig: koishi_1.Schema.object({
306
- timeout: koishi_1.Schema.number().default(5000).description('API请求超时时间(毫秒)'),
307
+ timeout: koishi_1.Schema.number().min(0).default(30000).description('API请求超时时间(毫秒,0为不超时)'),
307
308
  }).description('🌐 API接口配置'),
308
309
  }),
309
310
  koishi_1.Schema.object({
@@ -334,11 +335,11 @@ async function apply(ctx, cfg) {
334
335
  unique: [['guildId', 'platform', 'userId']]
335
336
  });
336
337
  const d = {
337
- guessNumber: cfg.guessNumber.messages,
338
- wzHero: cfg.wzHero.messages,
339
- chengyuImage: cfg.chengyuImage.messages,
340
- chengyuJielong: cfg.chengyuJielong.messages,
341
- calc24: cfg.calc24.messages,
338
+ guessNumber: cfg.guessNumber.messages.enabled ? cfg.guessNumber.messages : defaultMessages.guessNumber,
339
+ wzHero: cfg.wzHero.messages.enabled ? cfg.wzHero.messages : defaultMessages.wzHero,
340
+ chengyuImage: cfg.chengyuImage.messages.enabled ? cfg.chengyuImage.messages : defaultMessages.chengyuImage,
341
+ chengyuJielong: cfg.chengyuJielong.messages.enabled ? cfg.chengyuJielong.messages : defaultMessages.chengyuJielong,
342
+ calc24: cfg.calc24.messages.enabled ? cfg.calc24.messages : defaultMessages.calc24,
342
343
  rank: cfg.rank.messages,
343
344
  common: cfg.commonMessages
344
345
  };
@@ -528,7 +529,8 @@ async function apply(ctx, cfg) {
528
529
  target: 0,
529
530
  currentMin: cfg.guessNumber.min,
530
531
  currentMax: cfg.guessNumber.max,
531
- botGuess: []
532
+ botGuess: [],
533
+ autoPlayCount: 0
532
534
  },
533
535
  wzHero: {
534
536
  started: false,
@@ -697,6 +699,63 @@ async function apply(ctx, cfg) {
697
699
  const refreshActive = (st) => {
698
700
  st.chengyuJielong.lastActiveTime = Date.now();
699
701
  };
702
+ const doGuessNumberAutoPlay = async (session, key, st) => {
703
+ if (!st.guessNumber.started)
704
+ return;
705
+ if (st.guessNumber.autoPlayCount >= cfg.guessNumber.autoPlayMaxCount)
706
+ return;
707
+ st.guessNumber.autoPlayCount += 1;
708
+ const guess = koishi_1.Random.int(st.guessNumber.currentMin, st.guessNumber.currentMax + 1);
709
+ await session.send(`机器人猜:${guess}`);
710
+ if (guess === st.guessNumber.target) {
711
+ st.guessNumber.players['bot'] = st.guessNumber.players['bot'] || {
712
+ platform: 'bot',
713
+ userId: 'bot',
714
+ name: '机器人',
715
+ score: 0,
716
+ correctCount: 0,
717
+ playCount: 0,
718
+ lastGameTime: 0
719
+ };
720
+ st.guessNumber.players['bot'].score += cfg.guessNumber.penaltyScore;
721
+ let message = d.guessNumber.correct;
722
+ if (cfg.guessNumber.enablePenalty) {
723
+ Object.keys(st.guessNumber.players).forEach(key => {
724
+ if (key !== 'bot') {
725
+ st.guessNumber.players[key].score += cfg.guessNumber.rewardScore;
726
+ }
727
+ });
728
+ message += `\n猜中者被扣 ${-cfg.guessNumber.penaltyScore} 分,其他玩家各加 ${cfg.guessNumber.rewardScore} 分`;
729
+ }
730
+ await session.send(message);
731
+ st.guessNumber.currentRound += 1;
732
+ if (st.guessNumber.currentRound > st.guessNumber.totalRounds) {
733
+ st.guessNumber.started = false;
734
+ clearAllTimers(st);
735
+ await session.send(d.guessNumber.gameEnd);
736
+ if (cfg.guessNumber.showRank && !isPrivate(session)) {
737
+ const rankText = generateGameRankText(st.guessNumber.players, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
738
+ await session.send(rankText);
739
+ }
740
+ clearGameData(st.guessNumber);
741
+ }
742
+ else {
743
+ st.guessNumber.target = koishi_1.Random.int(st.guessNumber.currentMin, st.guessNumber.currentMax);
744
+ await session.send(d.guessNumber.roundEnd.replace('{0}', st.guessNumber.currentRound.toString()).replace('{1}', (st.guessNumber.totalRounds - st.guessNumber.currentRound).toString()));
745
+ await session.send(`新回合开始!猜数字范围:${st.guessNumber.currentMin} - ${st.guessNumber.currentMax}`);
746
+ }
747
+ }
748
+ else if (guess < st.guessNumber.target) {
749
+ st.guessNumber.currentMin = guess + 1;
750
+ await session.send(d.guessNumber.tooSmall.replace('{0}', st.guessNumber.currentMin.toString()).replace('{1}', st.guessNumber.currentMax.toString()));
751
+ }
752
+ else {
753
+ st.guessNumber.currentMax = guess - 1;
754
+ await session.send(d.guessNumber.tooBig.replace('{0}', st.guessNumber.currentMin.toString()).replace('{1}', st.guessNumber.currentMax.toString()));
755
+ }
756
+ gameStates.set(key, st);
757
+ setupAutoStop(session, st.guessNumber, 'guessNumber', d.guessNumber.autoStop, cfg.guessNumber.showRank, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
758
+ };
700
759
  const doAutoPlay = async (session, key, st) => {
701
760
  if (!st.chengyuJielong.started)
702
761
  return;
@@ -745,7 +804,7 @@ async function apply(ctx, cfg) {
745
804
  await session.send(d.chengyuJielong.apiError);
746
805
  }
747
806
  gameStates.set(key, st);
748
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
807
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, undefined, undefined);
749
808
  };
750
809
  ctx.middleware(async (session, next) => {
751
810
  if (!session.content)
@@ -780,12 +839,12 @@ async function apply(ctx, cfg) {
780
839
  }
781
840
  if (st.chengyuJielong.botTurn) {
782
841
  await session.send('现在是机器人的回合,请稍候...');
783
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
842
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, undefined, undefined);
784
843
  return;
785
844
  }
786
845
  if (!isFourCharIdiom(content)) {
787
846
  await session.send(d.chengyuJielong.notIdiom);
788
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
847
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, undefined, undefined);
789
848
  return;
790
849
  }
791
850
  try {
@@ -848,7 +907,7 @@ async function apply(ctx, cfg) {
848
907
  logError(`[成语接龙玩家] API调用失败: ${err.message}`, err);
849
908
  await session.send(d.chengyuJielong.apiError);
850
909
  }
851
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
910
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, undefined, undefined);
852
911
  gameStates.set(key, st);
853
912
  return;
854
913
  }
@@ -869,14 +928,24 @@ async function apply(ctx, cfg) {
869
928
  id: st.chengyuImage.currentId,
870
929
  level: cfg.chengyuImage.defaultHintLevel
871
930
  },
872
- timeout: cfg.apiConfig.timeout
931
+ timeout: cfg.apiConfig.timeout,
932
+ headers: {
933
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
934
+ }
873
935
  });
874
936
  logDebug(`[看图猜成语] 获取提示API返回状态码: ${r.status}`);
875
937
  logDebug(`[看图猜成语] 获取提示API返回数据:`, r.data);
876
938
  const dt = r.data;
877
939
  if (dt.success) {
878
- logDebug(`[看图猜成语] 成功获取提示: ${dt.data.hint}`);
879
- await session.send(d.chengyuImage.hintGet.replace('{0}', dt.data.hint));
940
+ let hintText = '';
941
+ if (dt.data.hint && typeof dt.data.hint === 'object') {
942
+ hintText = dt.data.hint.message || JSON.stringify(dt.data.hint);
943
+ }
944
+ else {
945
+ hintText = dt.data.hint || dt.message;
946
+ }
947
+ logDebug(`[看图猜成语] 成功获取提示: ${hintText}`);
948
+ await session.send(d.chengyuImage.hintGet.replace('{0}', hintText));
880
949
  }
881
950
  else {
882
951
  logWarn(`[看图猜成语] 获取提示失败: ${dt.message}`);
@@ -904,14 +973,18 @@ async function apply(ctx, cfg) {
904
973
  id: st.chengyuImage.currentId,
905
974
  answer: content
906
975
  },
907
- timeout: cfg.apiConfig.timeout
976
+ timeout: cfg.apiConfig.timeout,
977
+ headers: {
978
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
979
+ }
908
980
  });
909
981
  logDebug(`[看图猜成语] 提交答案API返回状态码: ${r.status}`);
910
982
  logDebug(`[看图猜成语] 提交答案API返回数据:`, r.data);
911
983
  const dt = r.data;
912
984
  if (dt.success) {
913
985
  let reply = '';
914
- if (dt.message.includes('正确') || dt.message.includes('答对')) {
986
+ const isCorrect = dt.data?.result === 'correct';
987
+ if (isCorrect) {
915
988
  st.chengyuImage.players[playerKey].score += cfg.chengyuImage.rewardScore;
916
989
  st.chengyuImage.players[playerKey].correctCount += 1;
917
990
  await savePlayerData(session, st.chengyuImage.players[playerKey]);
@@ -938,7 +1011,10 @@ async function apply(ctx, cfg) {
938
1011
  action: 'next_question',
939
1012
  page: st.chengyuImage.currentPage + 1
940
1013
  },
941
- timeout: cfg.apiConfig.timeout
1014
+ timeout: cfg.apiConfig.timeout,
1015
+ headers: {
1016
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1017
+ }
942
1018
  });
943
1019
  logDebug(`[看图猜成语] 下一题API返回状态码: ${nextR.status}`);
944
1020
  logDebug(`[看图猜成语] 下一题API返回数据:`, nextR.data);
@@ -1004,7 +1080,11 @@ async function apply(ctx, cfg) {
1004
1080
  try {
1005
1081
  logDebug(`[王者英雄] 开始调用API,用户ID: ${getUserId(session)}, 内容: ${content}`);
1006
1082
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1007
- params: { id: getUserId(session), msg: content }, timeout: cfg.apiConfig.timeout
1083
+ params: { id: getUserId(session), msg: content },
1084
+ timeout: cfg.apiConfig.timeout,
1085
+ headers: {
1086
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1087
+ }
1008
1088
  });
1009
1089
  logDebug(`[王者英雄] API返回状态码: ${r.status}`);
1010
1090
  logDebug(`[王者英雄] API返回数据:`, r.data);
@@ -1036,7 +1116,11 @@ async function apply(ctx, cfg) {
1036
1116
  text += '\n' + d.wzHero.roundEnd.replace('{0}', st.wzHero.currentRound.toString()).replace('{1}', (st.wzHero.totalRounds - st.wzHero.currentRound).toString());
1037
1117
  logDebug(`[王者英雄] 开始调用下一题API`);
1038
1118
  const nextR = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1039
- params: { id: getUserId(session), msg: `开始游戏${st.wzHero.difficulty}` }, timeout: cfg.apiConfig.timeout
1119
+ params: { id: getUserId(session), msg: `开始游戏${st.wzHero.difficulty}` },
1120
+ timeout: cfg.apiConfig.timeout,
1121
+ headers: {
1122
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1123
+ }
1040
1124
  });
1041
1125
  logDebug(`[王者英雄] 下一题API返回状态码: ${nextR.status}`);
1042
1126
  logDebug(`[王者英雄] 下一题API返回数据:`, nextR.data);
@@ -1087,11 +1171,21 @@ async function apply(ctx, cfg) {
1087
1171
  const num = parseInt(content);
1088
1172
  if (isNaN(num)) {
1089
1173
  setupAutoStop(session, st.guessNumber, 'guessNumber', d.guessNumber.autoStop, cfg.guessNumber.showRank, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
1174
+ if (cfg.guessNumber.botParticipateInGroup && !isPrivate(session) && st.guessNumber.autoPlayCount < cfg.guessNumber.autoPlayMaxCount) {
1175
+ setTimeout(() => {
1176
+ doGuessNumberAutoPlay(session, key, st);
1177
+ }, cfg.guessNumber.autoPlayDelay * 1000);
1178
+ }
1090
1179
  return next();
1091
1180
  }
1092
1181
  if (num < st.guessNumber.currentMin || num > st.guessNumber.currentMax) {
1093
1182
  await session.send(d.guessNumber.outOfRange.replace('{0}', st.guessNumber.currentMin.toString()).replace('{1}', st.guessNumber.currentMax.toString()));
1094
1183
  setupAutoStop(session, st.guessNumber, 'guessNumber', d.guessNumber.autoStop, cfg.guessNumber.showRank, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
1184
+ if (cfg.guessNumber.botParticipateInGroup && !isPrivate(session) && st.guessNumber.autoPlayCount < cfg.guessNumber.autoPlayMaxCount) {
1185
+ setTimeout(() => {
1186
+ doGuessNumberAutoPlay(session, key, st);
1187
+ }, cfg.guessNumber.autoPlayDelay * 1000);
1188
+ }
1095
1189
  return;
1096
1190
  }
1097
1191
  if (num === st.guessNumber.target) {
@@ -1134,6 +1228,11 @@ async function apply(ctx, cfg) {
1134
1228
  await session.send(d.guessNumber.tooBig.replace('{0}', st.guessNumber.currentMin.toString()).replace('{1}', st.guessNumber.currentMax.toString()));
1135
1229
  }
1136
1230
  setupAutoStop(session, st.guessNumber, 'guessNumber', d.guessNumber.autoStop, cfg.guessNumber.showRank, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
1231
+ if (cfg.guessNumber.botParticipateInGroup && !isPrivate(session) && st.guessNumber.autoPlayCount < cfg.guessNumber.autoPlayMaxCount) {
1232
+ setTimeout(() => {
1233
+ doGuessNumberAutoPlay(session, key, st);
1234
+ }, cfg.guessNumber.autoPlayDelay * 1000);
1235
+ }
1137
1236
  gameStates.set(key, st);
1138
1237
  return;
1139
1238
  }
@@ -1228,10 +1327,16 @@ async function apply(ctx, cfg) {
1228
1327
  st.guessNumber.currentMin = cfg.guessNumber.min;
1229
1328
  st.guessNumber.currentMax = cfg.guessNumber.max;
1230
1329
  st.guessNumber.currentRound = 1;
1330
+ st.guessNumber.autoPlayCount = 0;
1231
1331
  await session.send(d.guessNumber.start.replace('{0}', st.guessNumber.totalRounds.toString()));
1232
1332
  await session.send(`猜数字范围:${st.guessNumber.currentMin} - ${st.guessNumber.currentMax}`);
1233
1333
  gameStates.set(key, st);
1234
1334
  setupAutoStop(session, st.guessNumber, 'guessNumber', d.guessNumber.autoStop, cfg.guessNumber.showRank, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
1335
+ if (cfg.guessNumber.botParticipateInGroup && !isPrivate(session)) {
1336
+ setTimeout(() => {
1337
+ doGuessNumberAutoPlay(session, key, st);
1338
+ }, cfg.guessNumber.autoPlayDelay * 1000);
1339
+ }
1235
1340
  }
1236
1341
  else if (action === '结束') {
1237
1342
  clearGameData(st.guessNumber, cfg.guessNumber.showRank && !isPrivate(session), session, d.guessNumber.rankTitle, d.guessNumber.rankEmpty);
@@ -1265,7 +1370,10 @@ async function apply(ctx, cfg) {
1265
1370
  logDebug(`[王者英雄] 开始游戏,难度: ${st.wzHero.difficulty}`);
1266
1371
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1267
1372
  params: { id: getUserId(session), msg: `开始游戏${st.wzHero.difficulty}` },
1268
- timeout: cfg.apiConfig.timeout
1373
+ timeout: cfg.apiConfig.timeout,
1374
+ headers: {
1375
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1376
+ }
1269
1377
  });
1270
1378
  logDebug(`[王者英雄] 开始游戏API返回状态码: ${r.status}`);
1271
1379
  logDebug(`[王者英雄] 开始游戏API返回数据:`, r.data);
@@ -1316,7 +1424,10 @@ async function apply(ctx, cfg) {
1316
1424
  logDebug(`[看图猜成语] 开始游戏,获取第一题`);
1317
1425
  const r = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
1318
1426
  params: { action: 'next_question', page: 1 },
1319
- timeout: cfg.apiConfig.timeout
1427
+ timeout: cfg.apiConfig.timeout,
1428
+ headers: {
1429
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
1430
+ }
1320
1431
  });
1321
1432
  logDebug(`[看图猜成语] 获取题目API返回状态码: ${r.status}`);
1322
1433
  logDebug(`[看图猜成语] 获取题目API返回数据:`, r.data);
@@ -1379,10 +1490,10 @@ async function apply(ctx, cfg) {
1379
1490
  doAutoPlay(session, key, st);
1380
1491
  }, 100);
1381
1492
  gameStates.set(key, st);
1382
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
1493
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, undefined, undefined);
1383
1494
  }
1384
1495
  else if (action === '结束') {
1385
- clearGameData(st.chengyuJielong, cfg.chengyuJielong.showRank && !isPrivate(session), session, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
1496
+ clearGameData(st.chengyuJielong, cfg.chengyuJielong.showRank && !isPrivate(session), session, undefined, undefined);
1386
1497
  await session.send(d.chengyuJielong.stop);
1387
1498
  gameStates.set(key, st);
1388
1499
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-game-mini",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Koishi多功能小游戏合集:猜数字、猜王者英雄、看图猜成语、成语接龙、算24点",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
package/readme.md CHANGED
@@ -6,7 +6,7 @@
6
6
  这是一款为 Koishi 聊天机器人框架开发的轻量级多功能小游戏插件,包含经典猜数字、猜王者荣耀英雄、看图猜成语、成语接龙、算24点五款趣味游戏
7
7
 
8
8
  ### English
9
- This is a lightweight, multi-functional mini-game plugin developed for the Koishi chatbot framework. It includes five fun games: Guess the Number, Guess the King of Glory Hero, Guess the Idiom from the Picture, Idiom Chain, and 24 Points.
9
+ This is a lightweight, multi-functional mini-game plugin developed for the Koishi chatbot framework. It includes five fun games: Guess the Number, Guess the King of Glory Hero, Guess the Idiom from the Picture, Idiom Chain, and 24 Points.
10
10
 
11
11
  ## 使用说明 (Usage)
12
12
 
@@ -100,18 +100,21 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
100
100
  | `guessNumber.enablePenalty` | 启用惩罚机制(猜中者扣分,其他人加分) | true |
101
101
  | `guessNumber.penaltyScore` | 猜中者扣除分数(负数) | -1 |
102
102
  | `guessNumber.rewardScore` | 其他人奖励分数 | 1 |
103
+ | `guessNumber.messages.enabled` | 启用自定义消息 | true |
103
104
  | **⚔️ 王者英雄猜谜配置** | | |
104
105
  | `wzHero.totalRounds` | 总回合数 | 10 |
105
106
  | `wzHero.showRank` | 游戏结束后显示本局排行榜 | true |
106
107
  | `wzHero.defaultDifficulty` | 默认难度 | 简单 |
107
108
  | `wzHero.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
108
109
  | `wzHero.rewardScore` | 答对奖励分数 | 1 |
110
+ | `wzHero.messages.enabled` | 启用自定义消息 | true |
109
111
  | **🖼️ 看图猜成语配置** | | |
110
112
  | `chengyuImage.totalRounds` | 总回合数 | 10 |
111
113
  | `chengyuImage.showRank` | 游戏结束后显示本局排行榜 | true |
112
114
  | `chengyuImage.defaultHintLevel` | 默认提示级别 | 1 |
113
115
  | `chengyuImage.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
114
116
  | `chengyuImage.rewardScore` | 答对奖励分数 | 1 |
117
+ | `chengyuImage.messages.enabled` | 启用自定义消息 | true |
115
118
  | **🐉 成语接龙配置** | | |
116
119
  | `chengyuJielong.totalRounds` | 总回合数 | 10 |
117
120
  | `chengyuJielong.showRank` | 游戏结束后显示本局排行榜 | false |
@@ -120,6 +123,7 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
120
123
  | `chengyuJielong.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
121
124
  | `chengyuJielong.maxRounds` | 最大接龙回合数(0为无限) | 10 |
122
125
  | `chengyuJielong.botParticipate` | 机器人是否参与接龙 | false |
126
+ | `chengyuJielong.messages.enabled` | 启用自定义消息 | true |
123
127
  | **🧮 算24点配置** | | |
124
128
  | `calc24.totalRounds` | 总回合数 | 5 |
125
129
  | `calc24.showRank` | 游戏结束后显示本局排行榜 | true |
@@ -129,8 +133,9 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
129
133
  | `calc24.difficultyLevels.hard` | 困难难度数字范围 | min:1, max:13 |
130
134
  | `calc24.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
131
135
  | `calc24.rewardScore` | 答对奖励分数 | 1 |
136
+ | `calc24.messages.enabled` | 启用自定义消息 | true |
132
137
  | **🌐 API接口配置** | | |
133
- | `apiConfig.timeout` | API请求超时时间(毫秒) | 5000 |
138
+ | `apiConfig.timeout` | API请求超时时间(毫秒,0为不超时) | 30000 |
134
139
  | **💬 通用消息配置** | | |
135
140
  | `commonMessages.gameRunning` | 游戏运行中提示 | 当前已有游戏在运行中,请先结束当前游戏后再开始新游戏! |
136
141
  | `commonMessages.gameStoppedByInactive` | 无操作停止提示 | 太久没人玩啦,比赛自动结束~ |
@@ -170,18 +175,21 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
170
175
  | `guessNumber.enablePenalty` | Enable penalty mechanism (guesser loses points, others gain) | true |
171
176
  | `guessNumber.penaltyScore` | Points deducted from guesser (negative number) | -1 |
172
177
  | `guessNumber.rewardScore` | Points rewarded to others | 1 |
178
+ | `guessNumber.messages.enabled` | Enable custom messages | true |
173
179
  | **⚔️ King of Glory Hero Configuration** | | |
174
180
  | `wzHero.totalRounds` | Total rounds | 10 |
175
181
  | `wzHero.showRank` | Show rank after game ends | true |
176
182
  | `wzHero.defaultDifficulty` | Default difficulty | easy |
177
183
  | `wzHero.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
178
184
  | `wzHero.rewardScore` | Reward score for correct answer | 1 |
185
+ | `wzHero.messages.enabled` | Enable custom messages | true |
179
186
  | **🖼️ Idiom Guessing from Pictures Configuration** | | |
180
187
  | `chengyuImage.totalRounds` | Total rounds | 10 |
181
188
  | `chengyuImage.showRank` | Show rank after game ends | true |
182
189
  | `chengyuImage.defaultHintLevel` | Default hint level | 1 |
183
190
  | `chengyuImage.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
184
191
  | `chengyuImage.rewardScore` | Reward score for correct answer | 1 |
192
+ | `chengyuImage.messages.enabled` | Enable custom messages | true |
185
193
  | **🐉 Idiom Solitaire Configuration** | | |
186
194
  | `chengyuJielong.totalRounds` | Total rounds | 10 |
187
195
  | `chengyuJielong.showRank` | Show rank after game ends | false |
@@ -190,6 +198,7 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
190
198
  | `chengyuJielong.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
191
199
  | `chengyuJielong.maxRounds` | Maximum solitaire rounds (0 for unlimited) | 10 |
192
200
  | `chengyuJielong.botParticipate` | Whether bot participates in solitaire | false |
201
+ | `chengyuJielong.messages.enabled` | Enable custom messages | true |
193
202
  | **🧮 24-Point Calculation Configuration** | | |
194
203
  | `calc24.totalRounds` | Total rounds | 5 |
195
204
  | `calc24.showRank` | Show rank after game ends | true |
@@ -199,8 +208,9 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
199
208
  | `calc24.difficultyLevels.hard` | Hard difficulty number range | min:1, max:13 |
200
209
  | `calc24.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
201
210
  | `calc24.rewardScore` | Reward score for correct answer | 1 |
211
+ | `calc24.messages.enabled` | Enable custom messages | true |
202
212
  | **🌐 API Configuration** | | |
203
- | `apiConfig.timeout` | API request timeout (milliseconds) | 5000 |
213
+ | `apiConfig.timeout` | API request timeout (milliseconds, 0 for no timeout) | 30000 |
204
214
  | **💬 Common Messages Configuration** | | |
205
215
  | `commonMessages.gameRunning` | Game running prompt | A game is already running, please end it first before starting a new one! |
206
216
  | `commonMessages.gameStoppedByInactive` | Inactivity stop prompt | Too long no activity, game auto ended~ |