@hieuzest/koishi-plugin-mahjongpub 0.2.11 → 0.2.12
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.js +48 -14
- package/lib/mahjongpub.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -242,6 +242,7 @@ var ContestAdmin = class {
|
|
|
242
242
|
// src/manager.ts
|
|
243
243
|
var import_koishi2 = require("koishi");
|
|
244
244
|
var import_api = require("@hieuzest/koishi-plugin-majsoul-dhs/api");
|
|
245
|
+
var import_api2 = require("@hieuzest/koishi-plugin-riichi-city/api");
|
|
245
246
|
var import_lobby = require("@hieuzest/koishi-plugin-riichi-city/lobby");
|
|
246
247
|
|
|
247
248
|
// src/mahjongpub.ts
|
|
@@ -321,7 +322,7 @@ var MahjongPub = class _MahjongPub {
|
|
|
321
322
|
maxAge: 60
|
|
322
323
|
},
|
|
323
324
|
"getTeams": {
|
|
324
|
-
maxAge:
|
|
325
|
+
maxAge: 15
|
|
325
326
|
},
|
|
326
327
|
"getMatches": {
|
|
327
328
|
maxAge: 120
|
|
@@ -387,14 +388,16 @@ var ContestManager = class {
|
|
|
387
388
|
this.extra[cid].subscribers.delete(session.cid);
|
|
388
389
|
return "Finished.";
|
|
389
390
|
});
|
|
390
|
-
ctx.command("mahjongpub.manager.start [cls:number]").channelFields(["mahjongpub/bind-contest"]).option("force", "-f").action(async ({ session, options },
|
|
391
|
+
ctx.command("mahjongpub.manager.start [...cls:number]").channelFields(["mahjongpub/bind-contest"]).option("force", "-f").action(async ({ session, options }, ...clsz) => {
|
|
391
392
|
const cid = +(session.channel["mahjongpub/bind-contest"] || 0);
|
|
392
393
|
if (!cid) return "Unauthorized.";
|
|
393
394
|
const cextra = this.extra[cid] ??= new ContestExtra(ctx);
|
|
394
395
|
cextra.subscribers.add(session.cid);
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
|
|
396
|
+
if (clsz.length) {
|
|
397
|
+
for (const cls of clsz) {
|
|
398
|
+
cextra.stopCls.delete(cls);
|
|
399
|
+
await this.startMatch(cid, cls, 0, options.force);
|
|
400
|
+
}
|
|
398
401
|
} else {
|
|
399
402
|
cextra.stopCls.clear();
|
|
400
403
|
const contest = await this.mahjongpub.getContest(cid);
|
|
@@ -406,12 +409,14 @@ var ContestManager = class {
|
|
|
406
409
|
}
|
|
407
410
|
}
|
|
408
411
|
});
|
|
409
|
-
ctx.command("mahjongpub.manager.stop [cls:number]").channelFields(["mahjongpub/bind-contest"]).action(async ({ session },
|
|
412
|
+
ctx.command("mahjongpub.manager.stop [...cls:number]").channelFields(["mahjongpub/bind-contest"]).action(async ({ session }, ...clsz) => {
|
|
410
413
|
const cid = +(session.channel["mahjongpub/bind-contest"] || 0);
|
|
411
|
-
if (!cid) return "Unauthorized
|
|
414
|
+
if (!cid) return "Unauthorized.";
|
|
412
415
|
const cextra = this.extra[cid] ??= new ContestExtra(ctx);
|
|
413
|
-
if (
|
|
414
|
-
|
|
416
|
+
if (clsz.length) {
|
|
417
|
+
for (const cls of clsz) {
|
|
418
|
+
cextra.stopCls.add(cls);
|
|
419
|
+
}
|
|
415
420
|
} else {
|
|
416
421
|
const contest = await this.mahjongpub.getContest(cid);
|
|
417
422
|
const rounds = await this.mahjongpub.getRounds(cid);
|
|
@@ -478,26 +483,31 @@ var ContestManager = class {
|
|
|
478
483
|
cextra.broadcast(`[${tag}] 失败: 名单未填写`);
|
|
479
484
|
return;
|
|
480
485
|
}
|
|
486
|
+
let failPatterns;
|
|
481
487
|
try {
|
|
482
488
|
if (cextra.type === "ti") {
|
|
483
|
-
|
|
489
|
+
failPatterns = players.map((x, i) => `${x} ${lastRecord ? lastRecord.results?.[i].num : 1e5}`).join(", ");
|
|
490
|
+
this.ctx.logger.info(`starting ti match ${cid}-${cls}, players ${failPatterns}`);
|
|
484
491
|
await this.ctx["zx-dhs"].startMatch(
|
|
485
492
|
+(cextra.lobby ?? round.code),
|
|
486
493
|
players.map((x, i) => import_lobby.Player.fromPattern(x, lastRecord ? lastRecord.results?.[i].num : 1e5))
|
|
487
494
|
);
|
|
488
495
|
} else if (cextra.type === "ssb") {
|
|
489
|
-
|
|
496
|
+
failPatterns = players.join(", ");
|
|
497
|
+
this.ctx.logger.info(`starting ssb match ${cid}-${cls}, players ${failPatterns}`);
|
|
490
498
|
await this.ctx["majsoul-dhs"].startMatch(+(cextra.lobby ?? round.code), players.map((x) => import_api.Player.fromPattern(x, 25e3)));
|
|
499
|
+
} else {
|
|
500
|
+
throw new Error(`unknown contest type: ${cextra.type}`);
|
|
491
501
|
}
|
|
492
|
-
cextra.broadcast(`[${tag}] 成功:` + players.join("
|
|
502
|
+
cextra.broadcast(`[${tag}] 成功:` + players.join(", "));
|
|
493
503
|
} catch (e) {
|
|
494
|
-
if (e instanceof import_lobby.DHSError || e instanceof import_api.DHSError) {
|
|
504
|
+
if (e instanceof import_lobby.DHSError || e instanceof import_api2.RiichiCityError || e instanceof import_api.DHSError) {
|
|
495
505
|
cextra.broadcast(`[${tag}] 失败:` + e.message + ` (timeout=${timeout / import_koishi2.Time.second}s)`);
|
|
496
506
|
if (timeout < this.config.startMaxTimeout) {
|
|
497
507
|
this.ctx.setTimeout(() => this.startMatch(cid, cls, timeout + this.config.startTimeoutInterval), this.config.startTimeoutInterval);
|
|
498
508
|
} else {
|
|
499
509
|
this.ctx.logger.warn(`start match ${cid}-${cls} exceed max retires`);
|
|
500
|
-
cextra.broadcast(`[${tag}] 失败:超过最大重试时间 【${
|
|
510
|
+
cextra.broadcast(`[${tag}] 失败:超过最大重试时间 【${failPatterns}】`);
|
|
501
511
|
}
|
|
502
512
|
} else {
|
|
503
513
|
this.ctx.logger.warn(`start match ${cid}-${cls} failed: ${e.message}`);
|
|
@@ -813,6 +823,30 @@ var MahjongPub2 = class extends import_koishi3.Service {
|
|
|
813
823
|
}
|
|
814
824
|
});
|
|
815
825
|
if (ctx.get("mahjong.database")) {
|
|
826
|
+
ctx.command("mahjongpub.database.record.last <round:natural>", { authority: 3 }).option("rowi", "-i <rowi:integer>", { fallback: -1 }).option("ver", "-v <ver:integer>", { fallback: 0 }).channelFields(["mahjongpub/bind-contest"]).action(async ({ session, options }, round, cls) => {
|
|
827
|
+
const [cid] = [session.channel["mahjongpub/bind-contest"]];
|
|
828
|
+
try {
|
|
829
|
+
const record = await ctx.mahjong.database.db("scoreboard").collection("matches").find({
|
|
830
|
+
cid,
|
|
831
|
+
round,
|
|
832
|
+
ver: options.ver,
|
|
833
|
+
...options.rowi === -1 ? {} : { rowi: options.rowi }
|
|
834
|
+
}).sort({ cls: 1, rowi: -1 }).toArray();
|
|
835
|
+
if (!record.length) return session.text(".failed");
|
|
836
|
+
const filtered = [];
|
|
837
|
+
const seenCls = /* @__PURE__ */ new Set();
|
|
838
|
+
record.forEach((r) => {
|
|
839
|
+
if (!seenCls.has(r.cls)) {
|
|
840
|
+
filtered.push(r);
|
|
841
|
+
seenCls.add(r.cls);
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
return filtered.map((r) => `[${r.cls}组] ` + r.results.map((x) => `${x.name} ${x.num}`).join(" / ")).join("\n");
|
|
845
|
+
} catch (e) {
|
|
846
|
+
ctx.logger.warn(e);
|
|
847
|
+
return session.text(".failed");
|
|
848
|
+
}
|
|
849
|
+
});
|
|
816
850
|
ctx.command("mahjongpub.database.record.get <round:natural> <cls:natural>", { authority: 3 }).option("rowi", "-i <rowi:integer>", { fallback: -1 }).option("ver", "-v <ver:integer>", { fallback: 0 }).channelFields(["mahjongpub/bind-contest"]).action(async ({ session, options }, round, cls) => {
|
|
817
851
|
const [cid] = [session.channel["mahjongpub/bind-contest"]];
|
|
818
852
|
try {
|
package/lib/mahjongpub.d.ts
CHANGED