koishi-plugin-game-mini 0.2.8 → 0.3.0

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
@@ -131,7 +131,6 @@ export interface Config {
131
131
  autoStopInactiveTime: number;
132
132
  maxRounds: number;
133
133
  botParticipate: boolean;
134
- rewardScore: number;
135
134
  messages: {
136
135
  usage: string;
137
136
  start: string;
package/lib/index.js CHANGED
@@ -241,7 +241,6 @@ exports.Config = koishi_1.Schema.intersect([
241
241
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
242
242
  maxRounds: koishi_1.Schema.number().min(0).default(10).description('最大接龙回合数(0为无限)'),
243
243
  botParticipate: koishi_1.Schema.boolean().default(false).description('机器人是否参与接龙'),
244
- rewardScore: koishi_1.Schema.number().min(0).default(1).description('接龙成功奖励分数'),
245
244
  messages: koishi_1.Schema.object({
246
245
  usage: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.usage).description('用法错误提示'),
247
246
  start: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.start).description('游戏开始提示\n{0}-总回合数'),
@@ -675,37 +674,12 @@ async function apply(ctx, cfg) {
675
674
  const refreshActive = (st) => {
676
675
  st.chengyuJielong.lastActiveTime = Date.now();
677
676
  };
678
- const scheduleAutoPlay = (session, key, st) => {
679
- clearAllTimers(st);
680
- if (isPrivate(session)) {
681
- doAutoPlay(session, key, st);
682
- return;
683
- }
684
- if (!cfg.chengyuJielong.botParticipate)
685
- return;
686
- if (st.chengyuJielong.hasTriggeredAutoPlay)
687
- return;
688
- const delay = cfg.chengyuJielong.autoPlayDelay * 1000;
689
- st.chengyuJielong.autoPlayTimer = setTimeout(() => {
690
- doAutoPlay(session, key, st);
691
- }, delay);
692
- };
693
677
  const doAutoPlay = async (session, key, st) => {
694
678
  if (!st.chengyuJielong.started)
695
679
  return;
696
- if (st.chengyuJielong.hasTriggeredAutoPlay)
697
- return;
698
- if (st.chengyuJielong.autoPlayCount >= cfg.chengyuJielong.autoPlayMaxCount) {
699
- st.chengyuJielong.hasTriggeredAutoPlay = true;
700
- gameStates.set(key, st);
701
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
702
- return;
703
- }
704
- st.chengyuJielong.hasTriggeredAutoPlay = true;
705
- st.chengyuJielong.autoPlayCount += 1;
706
- gameStates.set(key, st);
707
680
  try {
708
681
  const intUserId = getIntUserId(session);
682
+ logger.info(`[成语接龙] 开始调用API,用户ID: ${intUserId}`);
709
683
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
710
684
  params: {
711
685
  id: intUserId,
@@ -716,6 +690,7 @@ async function apply(ctx, cfg) {
716
690
  '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'
717
691
  }
718
692
  });
693
+ logger.info(`[成语接龙] API返回状态码: ${r.status}`);
719
694
  const dt = r.data;
720
695
  let m = '';
721
696
  if (dt.code === 200 && dt.data?.system) {
@@ -723,14 +698,19 @@ async function apply(ctx, cfg) {
723
698
  m = d.chengyuJielong.botTurn.replace('{0}', sys.idiom);
724
699
  st.chengyuJielong.lastChar = dt.data.current_char || '';
725
700
  st.chengyuJielong.jielongCount += 1;
701
+ st.chengyuJielong.botTurn = false;
702
+ logger.info(`[成语接龙] 成功获取成语: ${sys.idiom}`);
703
+ await session.send(m);
726
704
  }
727
705
  else {
706
+ logger.warn(`[成语接龙] API返回异常: code=${dt.code}, msg=${dt.msg}`);
728
707
  m = dt.msg || d.chengyuJielong.botWin;
729
708
  st.chengyuJielong.currentRound += 1;
709
+ st.chengyuJielong.botTurn = true;
710
+ await session.send(m);
730
711
  if (st.chengyuJielong.currentRound > st.chengyuJielong.totalRounds) {
731
712
  st.chengyuJielong.started = false;
732
713
  clearAllTimers(st);
733
- await session.send(m);
734
714
  await session.send(d.chengyuJielong.gameEnd);
735
715
  if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
736
716
  const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
@@ -741,13 +721,12 @@ async function apply(ctx, cfg) {
741
721
  return;
742
722
  }
743
723
  else {
744
- m += '\n' + d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString());
724
+ await session.send(d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString()));
745
725
  }
746
726
  }
747
727
  if (cfg.chengyuJielong.maxRounds > 0 && st.chengyuJielong.jielongCount >= cfg.chengyuJielong.maxRounds) {
748
728
  st.chengyuJielong.started = false;
749
729
  clearAllTimers(st);
750
- await session.send(m);
751
730
  await session.send(d.chengyuJielong.gameEnd);
752
731
  if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
753
732
  const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
@@ -757,9 +736,10 @@ async function apply(ctx, cfg) {
757
736
  gameStates.set(key, st);
758
737
  return;
759
738
  }
760
- await session.send(m);
761
739
  }
762
740
  catch (error) {
741
+ const err = error;
742
+ logger.error(`[成语接龙] API调用失败: ${err.message}`);
763
743
  await session.send(d.chengyuJielong.apiError);
764
744
  }
765
745
  gameStates.set(key, st);
@@ -796,14 +776,19 @@ async function apply(ctx, cfg) {
796
776
  st.chengyuJielong.participants.push(playerKey);
797
777
  await updatePlayerPlayCount(session);
798
778
  }
779
+ if (st.chengyuJielong.botTurn) {
780
+ await session.send('现在是机器人的回合,请稍候...');
781
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
782
+ return;
783
+ }
799
784
  if (!isFourCharIdiom(content)) {
800
785
  await session.send(d.chengyuJielong.notIdiom);
801
786
  setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
802
- scheduleAutoPlay(session, key, st);
803
787
  return;
804
788
  }
805
789
  try {
806
790
  const intUserId = getIntUserId(session);
791
+ logger.info(`[成语接龙玩家] 开始调用API,用户ID: ${intUserId}, 内容: ${content}`);
807
792
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_cyjl.php', {
808
793
  params: {
809
794
  id: intUserId,
@@ -814,6 +799,7 @@ async function apply(ctx, cfg) {
814
799
  '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'
815
800
  }
816
801
  });
802
+ logger.info(`[成语接龙玩家] API返回状态码: ${r.status}`);
817
803
  const dt = r.data;
818
804
  let m = '';
819
805
  if (dt.code === 200) {
@@ -821,62 +807,40 @@ async function apply(ctx, cfg) {
821
807
  if (dt.data?.user) {
822
808
  m += d.chengyuJielong.correct + '\n';
823
809
  m += `你的成语:${dt.data.user.idiom}\n`;
824
- st.chengyuJielong.players[playerKey].score += cfg.chengyuJielong.rewardScore;
825
- st.chengyuJielong.players[playerKey].correctCount += 1;
826
- await savePlayerData(session, st.chengyuJielong.players[playerKey]);
810
+ st.chengyuJielong.botTurn = true;
811
+ logger.info(`[成语接龙玩家] 接龙成功: ${dt.data.user.idiom}`);
827
812
  }
828
813
  else {
829
814
  m += d.chengyuJielong.wrong + '\n';
815
+ logger.info(`[成语接龙玩家] 接龙失败`);
830
816
  }
831
817
  if (dt.data?.system) {
832
818
  m += `我的接龙:${dt.data.system.idiom}`;
833
819
  st.chengyuJielong.lastChar = dt.data.current_char || '';
834
820
  st.chengyuJielong.jielongCount += 1;
821
+ logger.info(`[成语接龙玩家] 机器人接龙: ${dt.data.system.idiom}`);
835
822
  }
836
823
  st.chengyuJielong.currentRound += 1;
837
- if (cfg.chengyuJielong.maxRounds > 0 && st.chengyuJielong.jielongCount >= cfg.chengyuJielong.maxRounds) {
838
- st.chengyuJielong.started = false;
839
- clearAllTimers(st);
840
- await session.send(m);
841
- await session.send(d.chengyuJielong.gameEnd);
842
- if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
843
- const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
844
- await session.send(rankText);
845
- }
846
- clearGameData(st.chengyuJielong);
847
- gameStates.set(key, st);
848
- return;
849
- }
850
- if (st.chengyuJielong.currentRound > st.chengyuJielong.totalRounds) {
851
- st.chengyuJielong.started = false;
852
- clearAllTimers(st);
853
- await session.send(m);
854
- await session.send(d.chengyuJielong.gameEnd);
855
- if (cfg.chengyuJielong.showRank && !isPrivate(session)) {
856
- const rankText = generateGameRankText(st.chengyuJielong.players, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
857
- await session.send(rankText);
858
- }
859
- clearGameData(st.chengyuJielong);
860
- }
861
- else {
862
- m += '\n' + d.chengyuJielong.roundEnd.replace('{0}', st.chengyuJielong.currentRound.toString()).replace('{1}', (st.chengyuJielong.totalRounds - st.chengyuJielong.currentRound).toString());
863
- await session.send(m);
864
- st.chengyuJielong.hasTriggeredAutoPlay = false;
865
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
866
- scheduleAutoPlay(session, key, st);
824
+ await session.send(m);
825
+ if (cfg.chengyuJielong.botParticipate && st.chengyuJielong.botTurn) {
826
+ setTimeout(() => {
827
+ doAutoPlay(session, key, st);
828
+ }, cfg.chengyuJielong.autoPlayDelay * 1000);
867
829
  }
868
830
  }
869
831
  else {
832
+ logger.warn(`[成语接龙玩家] API返回异常: code=${dt.code}, msg=${dt.msg}`);
870
833
  m = dt.msg || '接龙失败';
871
834
  m += '\n' + d.chengyuJielong.wrong;
872
835
  await session.send(m);
873
836
  }
874
837
  }
875
838
  catch (error) {
839
+ const err = error;
840
+ logger.error(`[成语接龙玩家] API调用失败: ${err.message}`);
876
841
  await session.send(d.chengyuJielong.apiError);
877
- setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
878
- scheduleAutoPlay(session, key, st);
879
842
  }
843
+ setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
880
844
  gameStates.set(key, st);
881
845
  return;
882
846
  }
@@ -1354,12 +1318,12 @@ async function apply(ctx, cfg) {
1354
1318
  if (action === '开始') {
1355
1319
  st.chengyuJielong.started = true;
1356
1320
  st.chengyuJielong.currentRound = 1;
1357
- st.chengyuJielong.hasTriggeredAutoPlay = false;
1358
1321
  st.chengyuJielong.autoPlayCount = 0;
1359
1322
  st.chengyuJielong.jielongCount = 0;
1323
+ st.chengyuJielong.botTurn = true;
1360
1324
  await session.send(d.chengyuJielong.start.replace('{0}', st.chengyuJielong.totalRounds.toString()));
1361
1325
  setTimeout(() => {
1362
- scheduleAutoPlay(session, key, st);
1326
+ doAutoPlay(session, key, st);
1363
1327
  }, 100);
1364
1328
  gameStates.set(key, st);
1365
1329
  setupAutoStop(session, st.chengyuJielong, 'chengyuJielong', d.chengyuJielong.autoStop, cfg.chengyuJielong.showRank, d.chengyuJielong.rankTitle, d.chengyuJielong.rankEmpty);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-game-mini",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Koishi多功能小游戏合集:猜数字、猜王者英雄、看图猜成语、成语接龙、算24点",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
package/readme.md CHANGED
@@ -118,7 +118,6 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
118
118
  | `chengyuJielong.autoStopInactiveTime` | 游戏无操作自动停止时间(秒) | 60 |
119
119
  | `chengyuJielong.maxRounds` | 最大接龙回合数(0为无限) | 10 |
120
120
  | `chengyuJielong.botParticipate` | 机器人是否参与接龙 | false |
121
- | `chengyuJielong.rewardScore` | 接龙成功奖励分数 | 1 |
122
121
  | **🧮 算24点配置** | | |
123
122
  | `calc24.totalRounds` | 总回合数 | 5 |
124
123
  | `calc24.showRank` | 游戏结束后显示本局排行榜 | true |
@@ -187,7 +186,6 @@ This is a lightweight, multi-functional mini-game plugin developed for the Koish
187
186
  | `chengyuJielong.autoStopInactiveTime` | Auto stop time due to inactivity (seconds) | 60 |
188
187
  | `chengyuJielong.maxRounds` | Maximum solitaire rounds (0 for unlimited) | 10 |
189
188
  | `chengyuJielong.botParticipate` | Whether bot participates in solitaire | false |
190
- | `chengyuJielong.rewardScore` | Reward score for successful solitaire | 1 |
191
189
  | **🧮 24-Point Calculation Configuration** | | |
192
190
  | `calc24.totalRounds` | Total rounds | 5 |
193
191
  | `calc24.showRank` | Show rank after game ends | true |