koishi-plugin-game-mini 0.3.4 → 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;
@@ -171,6 +175,7 @@ export interface Config {
171
175
  autoStopInactiveTime: number;
172
176
  rewardScore: number;
173
177
  messages: {
178
+ enabled: boolean;
174
179
  usage: string;
175
180
  start: string;
176
181
  stop: string;
package/lib/index.js CHANGED
@@ -162,6 +162,7 @@ exports.Config = koishi_1.Schema.intersect([
162
162
  penaltyScore: koishi_1.Schema.number().max(0).default(-1).description('猜中者扣除分数(负数)'),
163
163
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('其他人奖励分数'),
164
164
  messages: koishi_1.Schema.object({
165
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
165
166
  usage: koishi_1.Schema.string().default(defaultMessages.guessNumber.usage).description('用法错误提示\n{0}-最小值, {1}-最大值'),
166
167
  start: koishi_1.Schema.string().default(defaultMessages.guessNumber.start).description('游戏开始提示\n{0}-总回合数'),
167
168
  stop: koishi_1.Schema.string().default(defaultMessages.guessNumber.stop).description('游戏停止提示'),
@@ -186,6 +187,7 @@ exports.Config = koishi_1.Schema.intersect([
186
187
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
187
188
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
188
189
  messages: koishi_1.Schema.object({
190
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
189
191
  usage: koishi_1.Schema.string().default(defaultMessages.wzHero.usage).description('用法错误提示'),
190
192
  start: koishi_1.Schema.string().default(defaultMessages.wzHero.start).description('游戏开始提示\n{0}-总回合数, {1}-难度'),
191
193
  stop: koishi_1.Schema.string().default(defaultMessages.wzHero.stop).description('游戏停止提示'),
@@ -211,6 +213,7 @@ exports.Config = koishi_1.Schema.intersect([
211
213
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
212
214
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
213
215
  messages: koishi_1.Schema.object({
216
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
214
217
  usage: koishi_1.Schema.string().default(defaultMessages.chengyuImage.usage).description('用法错误提示'),
215
218
  start: koishi_1.Schema.string().default(defaultMessages.chengyuImage.start).description('游戏开始提示\n{0}-总回合数, {1}-提示级别'),
216
219
  stop: koishi_1.Schema.string().default(defaultMessages.chengyuImage.stop).description('游戏停止提示'),
@@ -240,6 +243,7 @@ exports.Config = koishi_1.Schema.intersect([
240
243
  maxRounds: koishi_1.Schema.number().min(0).default(10).description('最大接龙回合数(0为无限)'),
241
244
  botParticipate: koishi_1.Schema.boolean().default(false).description('机器人是否参与接龙'),
242
245
  messages: koishi_1.Schema.object({
246
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
243
247
  usage: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.usage).description('用法错误提示'),
244
248
  start: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.start).description('游戏开始提示\n{0}-总回合数'),
245
249
  stop: koishi_1.Schema.string().default(defaultMessages.chengyuJielong.stop).description('游戏停止提示'),
@@ -280,6 +284,7 @@ exports.Config = koishi_1.Schema.intersect([
280
284
  autoStopInactiveTime: koishi_1.Schema.number().min(0).default(60).description('游戏无操作自动停止时间(秒)'),
281
285
  rewardScore: koishi_1.Schema.number().min(0).default(1).description('答对奖励分数'),
282
286
  messages: koishi_1.Schema.object({
287
+ enabled: koishi_1.Schema.boolean().default(true).description('启用自定义消息'),
283
288
  usage: koishi_1.Schema.string().default(defaultMessages.calc24.usage).description('用法错误提示'),
284
289
  start: koishi_1.Schema.string().default(defaultMessages.calc24.start).description('游戏开始提示\n{0}-总回合数, {1}-难度'),
285
290
  stop: koishi_1.Schema.string().default(defaultMessages.calc24.stop).description('游戏停止提示'),
@@ -299,7 +304,7 @@ exports.Config = koishi_1.Schema.intersect([
299
304
  }),
300
305
  koishi_1.Schema.object({
301
306
  apiConfig: koishi_1.Schema.object({
302
- timeout: koishi_1.Schema.number().default(5000).description('API请求超时时间(毫秒)'),
307
+ timeout: koishi_1.Schema.number().min(0).default(30000).description('API请求超时时间(毫秒,0为不超时)'),
303
308
  }).description('🌐 API接口配置'),
304
309
  }),
305
310
  koishi_1.Schema.object({
@@ -330,11 +335,11 @@ async function apply(ctx, cfg) {
330
335
  unique: [['guildId', 'platform', 'userId']]
331
336
  });
332
337
  const d = {
333
- guessNumber: cfg.guessNumber.messages,
334
- wzHero: cfg.wzHero.messages,
335
- chengyuImage: cfg.chengyuImage.messages,
336
- chengyuJielong: cfg.chengyuJielong.messages,
337
- 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,
338
343
  rank: cfg.rank.messages,
339
344
  common: cfg.commonMessages
340
345
  };
@@ -923,14 +928,24 @@ async function apply(ctx, cfg) {
923
928
  id: st.chengyuImage.currentId,
924
929
  level: cfg.chengyuImage.defaultHintLevel
925
930
  },
926
- 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
+ }
927
935
  });
928
936
  logDebug(`[看图猜成语] 获取提示API返回状态码: ${r.status}`);
929
937
  logDebug(`[看图猜成语] 获取提示API返回数据:`, r.data);
930
938
  const dt = r.data;
931
939
  if (dt.success) {
932
- logDebug(`[看图猜成语] 成功获取提示: ${dt.data.hint}`);
933
- 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));
934
949
  }
935
950
  else {
936
951
  logWarn(`[看图猜成语] 获取提示失败: ${dt.message}`);
@@ -958,7 +973,10 @@ async function apply(ctx, cfg) {
958
973
  id: st.chengyuImage.currentId,
959
974
  answer: content
960
975
  },
961
- 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
+ }
962
980
  });
963
981
  logDebug(`[看图猜成语] 提交答案API返回状态码: ${r.status}`);
964
982
  logDebug(`[看图猜成语] 提交答案API返回数据:`, r.data);
@@ -993,7 +1011,10 @@ async function apply(ctx, cfg) {
993
1011
  action: 'next_question',
994
1012
  page: st.chengyuImage.currentPage + 1
995
1013
  },
996
- 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
+ }
997
1018
  });
998
1019
  logDebug(`[看图猜成语] 下一题API返回状态码: ${nextR.status}`);
999
1020
  logDebug(`[看图猜成语] 下一题API返回数据:`, nextR.data);
@@ -1059,7 +1080,11 @@ async function apply(ctx, cfg) {
1059
1080
  try {
1060
1081
  logDebug(`[王者英雄] 开始调用API,用户ID: ${getUserId(session)}, 内容: ${content}`);
1061
1082
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1062
- 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
+ }
1063
1088
  });
1064
1089
  logDebug(`[王者英雄] API返回状态码: ${r.status}`);
1065
1090
  logDebug(`[王者英雄] API返回数据:`, r.data);
@@ -1091,7 +1116,11 @@ async function apply(ctx, cfg) {
1091
1116
  text += '\n' + d.wzHero.roundEnd.replace('{0}', st.wzHero.currentRound.toString()).replace('{1}', (st.wzHero.totalRounds - st.wzHero.currentRound).toString());
1092
1117
  logDebug(`[王者英雄] 开始调用下一题API`);
1093
1118
  const nextR = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1094
- 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
+ }
1095
1124
  });
1096
1125
  logDebug(`[王者英雄] 下一题API返回状态码: ${nextR.status}`);
1097
1126
  logDebug(`[王者英雄] 下一题API返回数据:`, nextR.data);
@@ -1341,7 +1370,10 @@ async function apply(ctx, cfg) {
1341
1370
  logDebug(`[王者英雄] 开始游戏,难度: ${st.wzHero.difficulty}`);
1342
1371
  const r = await axios_1.default.get('https://api.suol.cc/v1/game_wz.php', {
1343
1372
  params: { id: getUserId(session), msg: `开始游戏${st.wzHero.difficulty}` },
1344
- 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
+ }
1345
1377
  });
1346
1378
  logDebug(`[王者英雄] 开始游戏API返回状态码: ${r.status}`);
1347
1379
  logDebug(`[王者英雄] 开始游戏API返回数据:`, r.data);
@@ -1392,7 +1424,10 @@ async function apply(ctx, cfg) {
1392
1424
  logDebug(`[看图猜成语] 开始游戏,获取第一题`);
1393
1425
  const r = await axios_1.default.get('https://jcy.lvlong.xyz/api/api/chengyu.php', {
1394
1426
  params: { action: 'next_question', page: 1 },
1395
- 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
+ }
1396
1431
  });
1397
1432
  logDebug(`[看图猜成语] 获取题目API返回状态码: ${r.status}`);
1398
1433
  logDebug(`[看图猜成语] 获取题目API返回数据:`, r.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-game-mini",
3
- "version": "0.3.4",
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~ |