@hieuzest/koishi-plugin-mahjongpub 0.2.12 → 0.2.13
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 +2 -0
- package/lib/index.js +14 -7
- package/lib/manager.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Context, Dict, Schema, Service } from 'koishi';
|
|
2
2
|
import { ContestAdmin, TeamAdmin } from './api';
|
|
3
3
|
import { ContestManager } from './manager';
|
|
4
|
+
import { MahjongPub as Contest } from './mahjongpub';
|
|
4
5
|
declare module 'koishi' {
|
|
5
6
|
interface Context {
|
|
6
7
|
mahjongpub: MahjongPub;
|
|
@@ -26,6 +27,7 @@ export declare class MahjongPub extends Service {
|
|
|
26
27
|
config: MahjongPub.Config;
|
|
27
28
|
teams: Dict<TeamAdmin>;
|
|
28
29
|
contests: Dict<ContestAdmin>;
|
|
30
|
+
contest: Contest;
|
|
29
31
|
constructor(ctx: Context, config: MahjongPub.Config);
|
|
30
32
|
getTeam(pw: string): Promise<TeamAdmin>;
|
|
31
33
|
getContest(cid: string, pw: string): Promise<ContestAdmin>;
|
package/lib/index.js
CHANGED
|
@@ -351,15 +351,18 @@ var ContestExtra = class {
|
|
|
351
351
|
type;
|
|
352
352
|
round;
|
|
353
353
|
lobby;
|
|
354
|
+
playerIndex;
|
|
354
355
|
ver = 0;
|
|
355
356
|
async broadcast(msg) {
|
|
356
357
|
this.subscribers.forEach((channel) => this.ctx.sendMessage(channel, msg).catch((e) => this.ctx.logger.debug(e)));
|
|
357
358
|
}
|
|
358
359
|
};
|
|
359
|
-
function getRowPlayer(contest, team, rowi) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
360
|
+
function getRowPlayer(contest, team, rowi, index) {
|
|
361
|
+
if ((0, import_koishi2.isNullable)(index)) {
|
|
362
|
+
const roleList = contest.t_type.split(/\s+/);
|
|
363
|
+
const roleSet = [...new Set(roleList).values()];
|
|
364
|
+
index = roleSet.indexOf(roleList[rowi]);
|
|
365
|
+
}
|
|
363
366
|
return team.players[index]?.split("##", 1)[0];
|
|
364
367
|
}
|
|
365
368
|
__name(getRowPlayer, "getRowPlayer");
|
|
@@ -369,7 +372,7 @@ var ContestManager = class {
|
|
|
369
372
|
this.config = config;
|
|
370
373
|
this.mahjongpub = MahjongPub.new(ctx);
|
|
371
374
|
ctx.command("mahjongpub.manager", { authority: 3 }).action(import_koishi2.noop);
|
|
372
|
-
ctx.command("mahjongpub.manager.init").channelFields(["mahjongpub/bind-contest"]).option("clear", "-c").option("type", "-t [type:string]").option("ver", "-v [ver:number]").option("round", "-r [round:number]").option("lobby", "-l [lobby:string]").action(async ({ session, options }) => {
|
|
375
|
+
ctx.command("mahjongpub.manager.init").channelFields(["mahjongpub/bind-contest"]).option("clear", "-c").option("type", "-t [type:string]").option("ver", "-v [ver:number]").option("round", "-r [round:number]").option("lobby", "-l [lobby:string]").option("index", "-i [index:number]").action(async ({ session, options }) => {
|
|
373
376
|
const cid = +(session.channel["mahjongpub/bind-contest"] || 0);
|
|
374
377
|
if (!cid) return "Unauthorized.";
|
|
375
378
|
this.extra[cid] ??= new ContestExtra(ctx);
|
|
@@ -379,6 +382,7 @@ var ContestManager = class {
|
|
|
379
382
|
if (!(0, import_koishi2.isNullable)(options.ver)) this.extra[cid].ver = options.ver;
|
|
380
383
|
if (!(0, import_koishi2.isNullable)(options.round)) this.extra[cid].round = options.round;
|
|
381
384
|
if (!(0, import_koishi2.isNullable)(options.lobby)) this.extra[cid].lobby = options.lobby;
|
|
385
|
+
if (!(0, import_koishi2.isNullable)(options.index)) this.extra[cid].playerIndex = options.index;
|
|
382
386
|
return "Finished.";
|
|
383
387
|
});
|
|
384
388
|
ctx.command("mahjongpub.manager.deinit").channelFields(["mahjongpub/bind-contest"]).option("clear", "-c").action(async ({ session, options }) => {
|
|
@@ -478,7 +482,7 @@ var ContestManager = class {
|
|
|
478
482
|
return;
|
|
479
483
|
}
|
|
480
484
|
const round = Object.values(rounds).find((x) => x.round === (cextra.round ?? contest.c_round) && x.t_class === cls);
|
|
481
|
-
const players = round.tids.map((tid) => getRowPlayer(contest, teams[tid], rowi));
|
|
485
|
+
const players = round.tids.map((tid) => getRowPlayer(contest, teams[tid], rowi, cextra.playerIndex));
|
|
482
486
|
if (!players.every((x) => x)) {
|
|
483
487
|
cextra.broadcast(`[${tag}] 失败: 名单未填写`);
|
|
484
488
|
return;
|
|
@@ -563,6 +567,7 @@ var MahjongPub2 = class extends import_koishi3.Service {
|
|
|
563
567
|
this.config = config;
|
|
564
568
|
ctx.plugin(ContestManager, config.manager);
|
|
565
569
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
570
|
+
this.contest = MahjongPub.new(ctx);
|
|
566
571
|
ctx.model.extend("user", {
|
|
567
572
|
"mahjongpub/bind-team": "string",
|
|
568
573
|
"mahjongpub/bind-teams": "json"
|
|
@@ -826,6 +831,7 @@ var MahjongPub2 = class extends import_koishi3.Service {
|
|
|
826
831
|
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
832
|
const [cid] = [session.channel["mahjongpub/bind-contest"]];
|
|
828
833
|
try {
|
|
834
|
+
const cteams = await this.contest.getTeams(+cid);
|
|
829
835
|
const record = await ctx.mahjong.database.db("scoreboard").collection("matches").find({
|
|
830
836
|
cid,
|
|
831
837
|
round,
|
|
@@ -841,7 +847,7 @@ var MahjongPub2 = class extends import_koishi3.Service {
|
|
|
841
847
|
seenCls.add(r.cls);
|
|
842
848
|
}
|
|
843
849
|
});
|
|
844
|
-
return filtered.map((r) => `[${r.cls}
|
|
850
|
+
return filtered.map((r) => `[${r.cls}-${r.rowi + 1}] ` + r.results.map((x, i) => `${cteams[r.tids[i]].t_name} ${x.num}`).join(" / ")).join("\n");
|
|
845
851
|
} catch (e) {
|
|
846
852
|
ctx.logger.warn(e);
|
|
847
853
|
return session.text(".failed");
|
|
@@ -931,6 +937,7 @@ var MahjongPub2 = class extends import_koishi3.Service {
|
|
|
931
937
|
}
|
|
932
938
|
teams = {};
|
|
933
939
|
contests = {};
|
|
940
|
+
contest;
|
|
934
941
|
async getTeam(pw) {
|
|
935
942
|
return new TeamAdmin(this.ctx, pw, this.config);
|
|
936
943
|
}
|
package/lib/manager.d.ts
CHANGED