@hieuzest/koishi-plugin-mahjongpub 0.1.12 → 0.1.14

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
@@ -35,6 +35,7 @@ export declare namespace MahjongPub {
35
35
  informNotbind: boolean;
36
36
  endpoint: string;
37
37
  batchInterval: number;
38
+ batchCount: number;
38
39
  }
39
40
  const Config: Schema<Config>;
40
41
  }
package/lib/index.js CHANGED
@@ -79,18 +79,15 @@ class MahjongPub {
79
79
  return config.informNotbind ? session.text('.notbind') : '';
80
80
  return session.text('.output', [pw]);
81
81
  });
82
- ctx.command('mahjongpub.team.stats [user:user]')
82
+ ctx.command('mahjongpub.team.stats')
83
83
  .alias('!信息', '!信息', '!概况', '!概况')
84
84
  .option('channel', '-c <channel:channel>')
85
85
  .option('team', '-t <team:string>')
86
86
  .userFields(['mahjongpub/bind-team', 'mahjongpub/bind-teams'])
87
87
  .channelFields(['mahjongpub/bind-team', 'mahjongpub/bind-contest', 'mahjongpub/bind-contestpw'])
88
- .action(async ({ session, options }, user) => {
88
+ .action(async ({ session, options }) => {
89
89
  let pw = options.channel ? (await session.getChannel(parsePlatform(options.channel)[1], ['mahjongpub/bind-team']))['mahjongpub/bind-team']
90
- : session.isDirect ? session.user['mahjongpub/bind-team']
91
- : session.channel['mahjongpub/bind-contest']
92
- ? (user ? session.user['mahjongpub/bind-teams'][session.channel['mahjongpub/bind-contest']] : session.user['mahjongpub/bind-team'])
93
- : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
90
+ : session.isDirect ? session.user['mahjongpub/bind-team'] : session.channel['mahjongpub/bind-team'] ?? session.user['mahjongpub/bind-team'];
94
91
  if (options.team) {
95
92
  const [cid, cpw] = [session.channel['mahjongpub/bind-contest'], session.channel['mahjongpub/bind-contestpw']];
96
93
  if (!cid || !cpw)
@@ -229,6 +226,7 @@ class MahjongPub {
229
226
  .option('team', '-t <team:string>')
230
227
  .option('start', '-s <start:number>')
231
228
  .option('end', '-e <end:number>')
229
+ .option('slim', '--slim')
232
230
  .userFields(['mahjongpub/bind-team', 'mahjongpub/bind-teams'])
233
231
  .channelFields(['mahjongpub/bind-team', 'mahjongpub/bind-contest', 'mahjongpub/bind-contestpw'])
234
232
  .action(async ({ session, options }, ...indices) => {
@@ -245,18 +243,22 @@ class MahjongPub {
245
243
  else if (options.start && options.end) {
246
244
  if (options.end - options.start > 100)
247
245
  return session.text('.wide-range');
246
+ const msg = [];
248
247
  for (let tid = options.start; tid <= options.end; tid++) {
249
- await session.execute({
248
+ msg.push(await session.execute({
250
249
  name: 'mahjongpub.team.swap',
251
250
  args: indices,
252
251
  options: {
253
252
  channel: options.channel,
254
253
  team: `${tid}`,
254
+ slim: true,
255
255
  },
256
- });
256
+ }, true));
257
+ if (msg.length >= config.batchCount)
258
+ await session.send(msg.splice(0).join('\n'));
257
259
  await ctx.sleep(config.batchInterval);
258
260
  }
259
- return '';
261
+ return msg.length ? msg.join('\n') : '';
260
262
  }
261
263
  if (!pw)
262
264
  return config.informNotbind ? session.text('.notbind') : '';
@@ -272,7 +274,10 @@ class MahjongPub {
272
274
  }
273
275
  const msg = await team.write();
274
276
  await team.read(true);
275
- return msg + '\n' + session.text('.success', team);
277
+ if (options.slim)
278
+ return `[${team.tid} ${team.name}] ${msg} ` + indices.map(i => `${i}. ${team.players[i - 1]}`).join(' ');
279
+ else
280
+ return msg + '\n' + session.text('.success', team);
276
281
  }
277
282
  catch (e) {
278
283
  ctx.logger.warn(e);
@@ -337,7 +342,8 @@ exports.MahjongPub = MahjongPub;
337
342
  MahjongPub.Config = koishi_1.Schema.object({
338
343
  informNotbind: koishi_1.Schema.boolean().default(false),
339
344
  endpoint: koishi_1.Schema.string().default('https://cdn.r-mj.com/'),
340
- batchInterval: koishi_1.Schema.natural().default(500),
345
+ batchInterval: koishi_1.Schema.natural().default(300),
346
+ batchCount: koishi_1.Schema.natural().default(10),
341
347
  });
342
348
  })(MahjongPub || (exports.MahjongPub = MahjongPub = {}));
343
349
  exports.default = MahjongPub;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hieuzest/koishi-plugin-mahjongpub",
3
3
  "description": "Mahjong.pub API",
4
- "version": "0.1.12",
4
+ "version": "0.1.14",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [