@hieuzest/koishi-plugin-mahjongpub 0.1.22 → 0.2.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/api.d.ts +95 -17
- package/lib/index.d.ts +7 -4
- package/lib/index.js +6 -1
- package/lib/mahjongpub.d.ts +87 -0
- package/lib/manager.d.ts +47 -0
- package/package.json +1 -1
package/lib/api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Context, Dict, Quester } from 'koishi';
|
|
2
2
|
export interface Team {
|
|
3
3
|
pw?: string;
|
|
4
|
-
tid:
|
|
5
|
-
cid?:
|
|
4
|
+
tid: number;
|
|
5
|
+
cid?: number;
|
|
6
6
|
name: string;
|
|
7
7
|
players: string[];
|
|
8
8
|
qq?: string[];
|
|
@@ -12,8 +12,8 @@ export declare class TeamAdmin implements Team {
|
|
|
12
12
|
options: {
|
|
13
13
|
endpoint: string;
|
|
14
14
|
};
|
|
15
|
-
tid:
|
|
16
|
-
cid:
|
|
15
|
+
tid: number;
|
|
16
|
+
cid: number;
|
|
17
17
|
name: string;
|
|
18
18
|
description: string;
|
|
19
19
|
players: string[];
|
|
@@ -28,16 +28,16 @@ export declare class TeamAdmin implements Team {
|
|
|
28
28
|
}
|
|
29
29
|
declare namespace TeamAdmin {
|
|
30
30
|
interface Payload {
|
|
31
|
-
tid:
|
|
31
|
+
tid: number;
|
|
32
32
|
t_name: string;
|
|
33
33
|
t_player?: string;
|
|
34
34
|
t_sub?: string;
|
|
35
35
|
t_pw: string;
|
|
36
36
|
t_join_time?: string;
|
|
37
37
|
t_join_ip?: string;
|
|
38
|
-
t_type?:
|
|
38
|
+
t_type?: number;
|
|
39
39
|
t_ps?: string;
|
|
40
|
-
cid:
|
|
40
|
+
cid: number;
|
|
41
41
|
qq?: string;
|
|
42
42
|
ls_ip?: string;
|
|
43
43
|
ls_time?: string;
|
|
@@ -45,19 +45,22 @@ declare namespace TeamAdmin {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
export declare class ContestAdmin {
|
|
48
|
-
cid:
|
|
48
|
+
cid: number;
|
|
49
49
|
pw: string;
|
|
50
50
|
options: {
|
|
51
51
|
endpoint: string;
|
|
52
52
|
};
|
|
53
53
|
name: string;
|
|
54
54
|
teams: Dict<Team>;
|
|
55
|
+
round: number;
|
|
55
56
|
http: Quester;
|
|
56
57
|
raw?: ContestAdmin.Payload;
|
|
57
|
-
constructor(ctx: Context, cid:
|
|
58
|
+
constructor(ctx: Context, cid: number, pw: string, options: {
|
|
58
59
|
endpoint: string;
|
|
59
60
|
});
|
|
60
61
|
read(force?: boolean): Promise<void>;
|
|
62
|
+
getRounds(): Promise<Record<number, Record<number, Contest.Round>>>;
|
|
63
|
+
getRecords(round: number): Promise<Contest.Records>;
|
|
61
64
|
getRoundRecord(round: number, cls: number): Promise<ContestAdmin.MatchRoundRecord>;
|
|
62
65
|
updateRoundRecord(record: ContestAdmin.MatchRoundRecord): Promise<string>;
|
|
63
66
|
}
|
|
@@ -67,13 +70,13 @@ declare namespace ContestAdmin {
|
|
|
67
70
|
c_name: string;
|
|
68
71
|
c_gonggao: string;
|
|
69
72
|
c_pad: string;
|
|
70
|
-
c_round:
|
|
71
|
-
c_s_po:
|
|
72
|
-
c_sub_t:
|
|
73
|
-
cid:
|
|
74
|
-
r_type:
|
|
75
|
-
t_max:
|
|
76
|
-
t_sub:
|
|
73
|
+
c_round: number;
|
|
74
|
+
c_s_po: number;
|
|
75
|
+
c_sub_t: number;
|
|
76
|
+
cid: number;
|
|
77
|
+
r_type: number;
|
|
78
|
+
t_max: number;
|
|
79
|
+
t_sub: number;
|
|
77
80
|
t_type: string;
|
|
78
81
|
};
|
|
79
82
|
c_team: TeamAdmin.Payload[];
|
|
@@ -88,10 +91,85 @@ declare namespace ContestAdmin {
|
|
|
88
91
|
logurl: string;
|
|
89
92
|
}
|
|
90
93
|
interface MatchRoundRecord {
|
|
91
|
-
cid:
|
|
94
|
+
cid: number;
|
|
92
95
|
cls: number;
|
|
93
96
|
rnd: number;
|
|
94
97
|
matches: MatchRecord[];
|
|
95
98
|
}
|
|
99
|
+
interface RoundPayload {
|
|
100
|
+
clsmark: string;
|
|
101
|
+
code: string;
|
|
102
|
+
rid: number;
|
|
103
|
+
round: number;
|
|
104
|
+
t_class: number;
|
|
105
|
+
tid1: number;
|
|
106
|
+
tid2: number;
|
|
107
|
+
tid3: number;
|
|
108
|
+
tid4: number;
|
|
109
|
+
}
|
|
110
|
+
interface Round {
|
|
111
|
+
rid: number;
|
|
112
|
+
round: number;
|
|
113
|
+
cls: number;
|
|
114
|
+
code: string;
|
|
115
|
+
tids: number[];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
declare namespace Contest {
|
|
119
|
+
interface RoundPayload {
|
|
120
|
+
clsmark: string;
|
|
121
|
+
code: string;
|
|
122
|
+
rid: number;
|
|
123
|
+
round: number;
|
|
124
|
+
t_class: number;
|
|
125
|
+
tid1: number;
|
|
126
|
+
tid2: number;
|
|
127
|
+
tid3: number;
|
|
128
|
+
tid4: number;
|
|
129
|
+
}
|
|
130
|
+
interface Round {
|
|
131
|
+
rid: number;
|
|
132
|
+
round: number;
|
|
133
|
+
cls: number;
|
|
134
|
+
code: string;
|
|
135
|
+
tids: number[];
|
|
136
|
+
}
|
|
137
|
+
interface MatchPayload {
|
|
138
|
+
inx: number;
|
|
139
|
+
cid: number;
|
|
140
|
+
rowi: number;
|
|
141
|
+
name1: string;
|
|
142
|
+
num1: number;
|
|
143
|
+
name2: string;
|
|
144
|
+
num2: number;
|
|
145
|
+
name3: string;
|
|
146
|
+
num3: number;
|
|
147
|
+
name4: string;
|
|
148
|
+
num4: number;
|
|
149
|
+
url: string;
|
|
150
|
+
pint1: number;
|
|
151
|
+
pint2: number;
|
|
152
|
+
pint3: number;
|
|
153
|
+
pint4: number;
|
|
154
|
+
rid: number;
|
|
155
|
+
round: number;
|
|
156
|
+
i_time: string;
|
|
157
|
+
}
|
|
158
|
+
interface Match {
|
|
159
|
+
inx: number;
|
|
160
|
+
cid: number;
|
|
161
|
+
rowi: number;
|
|
162
|
+
players: {
|
|
163
|
+
name: string;
|
|
164
|
+
num: number;
|
|
165
|
+
point: number;
|
|
166
|
+
}[];
|
|
167
|
+
url: string;
|
|
168
|
+
rid: number;
|
|
169
|
+
round: number;
|
|
170
|
+
time: string;
|
|
171
|
+
}
|
|
172
|
+
type RecordsPayload = Record<number, MatchPayload[]>;
|
|
173
|
+
type Records = Record<number, Match[]>;
|
|
96
174
|
}
|
|
97
175
|
export {};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { Context, Dict, Schema } from 'koishi';
|
|
1
|
+
import { Context, Dict, Schema, Service } from 'koishi';
|
|
2
2
|
import { ContestAdmin, TeamAdmin } from './api';
|
|
3
3
|
declare module 'koishi' {
|
|
4
|
+
interface Context {
|
|
5
|
+
mahjongpub: MahjongPub;
|
|
6
|
+
}
|
|
4
7
|
interface User {
|
|
5
8
|
'mahjongpub/bind-team': string;
|
|
6
9
|
'mahjongpub/bind-teams': Dict<string>;
|
|
@@ -17,9 +20,9 @@ declare module '@koishijs/cache' {
|
|
|
17
20
|
teams: TeamAdmin;
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
|
-
export declare class MahjongPub {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
export declare class MahjongPub extends Service {
|
|
24
|
+
protected ctx: Context;
|
|
25
|
+
config: MahjongPub.Config;
|
|
23
26
|
teams: Dict<TeamAdmin>;
|
|
24
27
|
contests: Dict<ContestAdmin>;
|
|
25
28
|
constructor(ctx: Context, config: MahjongPub.Config);
|
package/lib/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
// src/locales/zh-CN.yml
|
|
24
24
|
var require_zh_CN = __commonJS({
|
|
25
25
|
"src/locales/zh-CN.yml"(exports2, module2) {
|
|
26
|
-
module2.exports = { commands: { "mahjongpub.team.bind": { description: "绑定队伍", messages: { failed: "绑定失败", success: "成功: [{cid}:{tid}] {name}" } }, "mahjongpub.team.unbind": { description: "解除绑定", messages: { notbind: "未绑定", success: "成功" } }, "mahjongpub.team.password": { description: "查看密码", messages: { notbind: "未绑定", output: "密码: {0}" } }, "mahjongpub.team.stats": { description: "查看队伍信息", messages: { notbind: "未绑定", failed: "失败", output: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.desc": { description: "队伍简介", messages: { notbind: "未绑定", failed: "失败", output: "- [{cid}:{tid}] {name}\n{description}\n" } }, "mahjongpub.team.logo": { description: "队伍头像", messages: { notbind: "未绑定", failed: "失败" } }, "mahjongpub.team.add": { description: "添加队员", messages: { notbind: "未绑定", failed: "失败", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.remove": { description: "删除队员", messages: { notbind: "未绑定", failed: "失败", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.swap": { description: "交换队员", messages: { notbind: "未绑定", failed: "失败", invalid: "参数错误", "wide-range": "范围过大", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.contest.bind": { description: "绑定比赛", messages: { failed: "绑定失败", success: "成功: [{cid}] {name}" } }, "mahjongpub.contest.record.get": { description: "查询比赛记录", messages: { failed: "查询失败" } }, "mahjongpub.contest.record.update": { description: "修改比赛记录", messages: { failed: "修改失败" } }, "mahjongpub.database.record.get": { description: "查询比赛记录", messages: { failed: "查询失败" } }, "mahjongpub.database.record.update": { description: "修改比赛记录", messages: { success: "修改成功", failed: "修改失败", unmodified: "未修改" } } } };
|
|
26
|
+
module2.exports = { commands: { "mahjongpub.team.bind": { description: "绑定队伍", messages: { failed: "绑定失败", success: "成功: [{cid}:{tid}] {name}" } }, "mahjongpub.team.unbind": { description: "解除绑定", messages: { notbind: "未绑定", success: "成功" } }, "mahjongpub.team.password": { description: "查看密码", messages: { notbind: "未绑定", output: "密码: {0}" } }, "mahjongpub.team.stats": { description: "查看队伍信息", messages: { notbind: "未绑定", failed: "失败", output: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.desc": { description: "队伍简介", messages: { notbind: "未绑定", failed: "失败", output: "- [{cid}:{tid}] {name}\n{description}\n" } }, "mahjongpub.team.logo": { description: "队伍头像", messages: { notbind: "未绑定", failed: "失败" } }, "mahjongpub.team.add": { description: "添加队员", messages: { notbind: "未绑定", failed: "失败", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.remove": { description: "删除队员", messages: { notbind: "未绑定", failed: "失败", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.team.swap": { description: "交换队员", messages: { notbind: "未绑定", failed: "失败", invalid: "参数错误", "wide-range": "范围过大", success: "- [{cid}:{tid}] {name}\n{players.map((p, i) => '' + (i+1) + ': ' + p).join('\\n')}\n" } }, "mahjongpub.contest.bind": { description: "绑定比赛", messages: { failed: "绑定失败", success: "成功: [{cid}] {name}" } }, "mahjongpub.contest.password": { description: "查看密码", messages: { failed: "未绑定", success: "[{0}] {1}\n" } }, "mahjongpub.contest.record.get": { description: "查询比赛记录", messages: { failed: "查询失败" } }, "mahjongpub.contest.record.update": { description: "修改比赛记录", messages: { failed: "修改失败" } }, "mahjongpub.database.record.get": { description: "查询比赛记录", messages: { failed: "查询失败" } }, "mahjongpub.database.record.update": { description: "修改比赛记录", messages: { success: "修改成功", failed: "修改失败", unmodified: "未修改" } } } };
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
@@ -395,6 +395,11 @@ var MahjongPub = class {
|
|
|
395
395
|
}
|
|
396
396
|
return session.text(".success", contest);
|
|
397
397
|
});
|
|
398
|
+
ctx.command("mahjongpub.contest.password", { authority: 4 }).option("channel", "-c <channel:channel>").channelFields(["mahjongpub/bind-contest", "mahjongpub/bind-contestpw"]).action(async ({ session }) => {
|
|
399
|
+
const [cid, cpw] = [session.channel["mahjongpub/bind-contest"], session.channel["mahjongpub/bind-contestpw"]];
|
|
400
|
+
if (cid) return session.text(".success", [cid, cpw]);
|
|
401
|
+
else return session.text(".failed");
|
|
402
|
+
});
|
|
398
403
|
ctx.command("mahjongpub.contest.record.get <round:natural> <cls:natural>", { authority: 3 }).option("rowi", "-i <rowi:integer>").channelFields(["mahjongpub/bind-contest", "mahjongpub/bind-contestpw"]).action(async ({ session, options }, round, cls) => {
|
|
399
404
|
const [cid, cpw] = [session.channel["mahjongpub/bind-contest"], session.channel["mahjongpub/bind-contestpw"]];
|
|
400
405
|
const contest = await this.getContest(cid, cpw);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Context, Dict } from 'koishi';
|
|
2
|
+
export declare class MahjongPub {
|
|
3
|
+
ctx: Context;
|
|
4
|
+
private serverUri;
|
|
5
|
+
private http;
|
|
6
|
+
constructor(ctx: Context);
|
|
7
|
+
getContest(cid: number): Promise<MahjongPub.Contest>;
|
|
8
|
+
getTeams(cid: number): Promise<Dict<MahjongPub.Team>>;
|
|
9
|
+
getRounds(cid: number): Promise<Dict<MahjongPub.Round>>;
|
|
10
|
+
getMatches(cid: number, round: number): Promise<Dict<MahjongPub.Match[]>>;
|
|
11
|
+
getAllMatches(cid: number): Promise<Dict<MahjongPub.Match[]>>;
|
|
12
|
+
static cacheOptions: {
|
|
13
|
+
readonly getContest: {
|
|
14
|
+
readonly maxAge: 120;
|
|
15
|
+
};
|
|
16
|
+
readonly getRounds: {
|
|
17
|
+
readonly maxAge: 60;
|
|
18
|
+
};
|
|
19
|
+
readonly getTeams: {
|
|
20
|
+
readonly maxAge: 30;
|
|
21
|
+
};
|
|
22
|
+
readonly getMatches: {
|
|
23
|
+
readonly maxAge: 120;
|
|
24
|
+
};
|
|
25
|
+
readonly getAllMatches: {
|
|
26
|
+
readonly maxAge: 300;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
static new(ctx: Context): import("@hieuzest/cachetools").CachedClass<MahjongPub, "getContest" | "getRounds" | "getTeams" | "getMatches" | "getAllMatches", "_">;
|
|
30
|
+
}
|
|
31
|
+
export declare namespace MahjongPub {
|
|
32
|
+
export interface Team {
|
|
33
|
+
tid: number;
|
|
34
|
+
cid: string;
|
|
35
|
+
t_name: string;
|
|
36
|
+
t_ps: string;
|
|
37
|
+
t_player?: string;
|
|
38
|
+
t_sub?: string;
|
|
39
|
+
img: string;
|
|
40
|
+
t_type: number;
|
|
41
|
+
players: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface Contest {
|
|
44
|
+
cid: number;
|
|
45
|
+
c_name: string;
|
|
46
|
+
c_round: number;
|
|
47
|
+
c_gonggao: string;
|
|
48
|
+
c_pad: string;
|
|
49
|
+
t_type: string;
|
|
50
|
+
}
|
|
51
|
+
export interface Round {
|
|
52
|
+
rid: number;
|
|
53
|
+
round: number;
|
|
54
|
+
t_class: number;
|
|
55
|
+
code: string;
|
|
56
|
+
tid1: number;
|
|
57
|
+
tid2: number;
|
|
58
|
+
tid3: number;
|
|
59
|
+
tid4: number;
|
|
60
|
+
tids: number[];
|
|
61
|
+
}
|
|
62
|
+
export interface MatchBrief {
|
|
63
|
+
inx: number;
|
|
64
|
+
cid: number;
|
|
65
|
+
rid: number;
|
|
66
|
+
round: number;
|
|
67
|
+
rowi: number;
|
|
68
|
+
i_time: string;
|
|
69
|
+
url: string;
|
|
70
|
+
}
|
|
71
|
+
type Stringiable = string | number;
|
|
72
|
+
type Suffixed<K, P extends Stringiable> = K extends string ? `${K}${P}` : never;
|
|
73
|
+
type SuffixRemoved<PK, P extends Stringiable> = PK extends Suffixed<infer K, P> ? K : '';
|
|
74
|
+
type SuffixedValue<T extends object, PK extends string, P extends Stringiable> = T extends {
|
|
75
|
+
[K in SuffixRemoved<PK, P>]: infer TValue;
|
|
76
|
+
} ? TValue : never;
|
|
77
|
+
type SuffixedObject<T extends object, P extends Stringiable> = {
|
|
78
|
+
[K in Suffixed<keyof T, P>]: SuffixedValue<T, K, P>;
|
|
79
|
+
};
|
|
80
|
+
interface MatchPlayerTemplate {
|
|
81
|
+
name: string;
|
|
82
|
+
num: number;
|
|
83
|
+
}
|
|
84
|
+
type MatchPlayer<P extends Stringiable> = SuffixedObject<MatchPlayerTemplate, P>;
|
|
85
|
+
export type Match = MatchBrief & MatchPlayer<1> & MatchPlayer<2> & MatchPlayer<3> & MatchPlayer<4>;
|
|
86
|
+
export {};
|
|
87
|
+
}
|
package/lib/manager.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Context, Dict, Schema } from 'koishi';
|
|
2
|
+
import { MahjongPub } from './mahjongpub';
|
|
3
|
+
interface PlayerResult {
|
|
4
|
+
name: string;
|
|
5
|
+
num: number;
|
|
6
|
+
pint: number;
|
|
7
|
+
}
|
|
8
|
+
interface MatchRecord {
|
|
9
|
+
_id: string;
|
|
10
|
+
inx?: string;
|
|
11
|
+
cid: string;
|
|
12
|
+
rid: string;
|
|
13
|
+
round: number;
|
|
14
|
+
rowi: number;
|
|
15
|
+
time?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
cls: number;
|
|
18
|
+
tids: number[];
|
|
19
|
+
players: string[];
|
|
20
|
+
ver?: number;
|
|
21
|
+
_finished?: boolean;
|
|
22
|
+
results?: PlayerResult[];
|
|
23
|
+
}
|
|
24
|
+
declare class ContestExtra {
|
|
25
|
+
ctx: Context;
|
|
26
|
+
subscribers: Set<string>;
|
|
27
|
+
stopCls: Set<number>;
|
|
28
|
+
constructor(ctx: Context);
|
|
29
|
+
broadcast(msg: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare class ContestManager {
|
|
32
|
+
protected ctx: Context;
|
|
33
|
+
config: ContestManager.Config;
|
|
34
|
+
static inject: string[];
|
|
35
|
+
mahjongpub: MahjongPub;
|
|
36
|
+
extra: Dict<ContestExtra>;
|
|
37
|
+
constructor(ctx: Context, config: ContestManager.Config);
|
|
38
|
+
startMatch(cid: number, cls: number, timeout?: number, tag?: string): Promise<void>;
|
|
39
|
+
onMatchFinished(record: MatchRecord): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare namespace ContestManager {
|
|
42
|
+
interface Config {
|
|
43
|
+
token?: string;
|
|
44
|
+
}
|
|
45
|
+
const Config: Schema<Config>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|