@hieuzest/koishi-plugin-riichi-city 0.5.6 → 0.5.8
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 +7 -10
- package/lib/lobby.d.ts +2 -0
- package/lib/lobby.js +53 -22
- package/lib/utils.d.ts +13 -0
- package/package.json +9 -4
package/lib/index.js
CHANGED
|
@@ -38,18 +38,17 @@ var require_zh_CN = __commonJS({
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
// src/index.ts
|
|
41
|
-
var
|
|
42
|
-
__export(
|
|
41
|
+
var src_exports = {};
|
|
42
|
+
__export(src_exports, {
|
|
43
43
|
RiichiCity: () => RiichiCity,
|
|
44
|
-
default: () =>
|
|
44
|
+
default: () => src_default
|
|
45
45
|
});
|
|
46
|
-
module.exports = __toCommonJS(
|
|
46
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
47
|
var import_koishi3 = require("koishi");
|
|
48
48
|
var import_api2 = require("./api");
|
|
49
49
|
|
|
50
50
|
// src/dhs.ts
|
|
51
51
|
var import_koishi = require("koishi");
|
|
52
|
-
var import_koishi_utils = require("@hieuzest/koishi-utils");
|
|
53
52
|
var import_lobby = require("./lobby");
|
|
54
53
|
var RiichiCityDHS = class extends import_koishi.Service {
|
|
55
54
|
constructor(ctx, config) {
|
|
@@ -236,13 +235,11 @@ ${config.extraHelp}`.trim();
|
|
|
236
235
|
return "已开启通知";
|
|
237
236
|
}
|
|
238
237
|
});
|
|
239
|
-
ctx.guild().command("rc-dhs.start <args:
|
|
240
|
-
if (!
|
|
238
|
+
ctx.guild().command("rc-dhs.start <args:mjlist>").userFields(["authority"]).channelFields(["rc-dhs/bind"]).action(async ({ session }, argsList) => {
|
|
239
|
+
if (!argsList?.length) return;
|
|
241
240
|
const contestId = session.channel["rc-dhs/bind"];
|
|
242
241
|
if (!contestId) return;
|
|
243
242
|
if (!this.checkPermission(session)) return;
|
|
244
|
-
args = import_koishi.h.unescape(args);
|
|
245
|
-
const argsList = (0, import_koishi_utils.splitBackslashEscapedArgs)(args);
|
|
246
243
|
const players = [];
|
|
247
244
|
const c = await this.getDHS(contestId);
|
|
248
245
|
if (!c) return "大会室未找到";
|
|
@@ -502,7 +499,7 @@ var RiichiCity = class extends import_koishi3.Service {
|
|
|
502
499
|
})
|
|
503
500
|
]);
|
|
504
501
|
})(RiichiCity || (RiichiCity = {}));
|
|
505
|
-
var
|
|
502
|
+
var src_default = RiichiCity;
|
|
506
503
|
// Annotate the CommonJS export names for ESM import in node:
|
|
507
504
|
0 && (module.exports = {
|
|
508
505
|
RiichiCity
|
package/lib/lobby.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Disposable, SessionError } from 'koishi';
|
|
2
2
|
import { RiichiCityApi } from './api';
|
|
3
3
|
import { LobbyDetails } from './types';
|
|
4
|
+
import { Lock } from './utils';
|
|
4
5
|
export declare class DHSError extends SessionError {
|
|
5
6
|
}
|
|
6
7
|
export declare class PlayerNotFoundError extends DHSError {
|
|
@@ -59,6 +60,7 @@ export declare class RiichiCityLobby {
|
|
|
59
60
|
notify?: Disposable;
|
|
60
61
|
notifyIdle: number;
|
|
61
62
|
notifyCache?: string[];
|
|
63
|
+
lock: Lock;
|
|
62
64
|
constructor(api: RiichiCityApi, id: number, extra: {
|
|
63
65
|
adminAccountId: number;
|
|
64
66
|
});
|
package/lib/lobby.js
CHANGED
|
@@ -32,6 +32,31 @@ __export(lobby_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(lobby_exports);
|
|
33
33
|
var import_koishi = require("koishi");
|
|
34
34
|
var import_api = require("./api");
|
|
35
|
+
|
|
36
|
+
// src/utils.ts
|
|
37
|
+
function noop() {
|
|
38
|
+
}
|
|
39
|
+
__name(noop, "noop");
|
|
40
|
+
var Lock = class {
|
|
41
|
+
static {
|
|
42
|
+
__name(this, "Lock");
|
|
43
|
+
}
|
|
44
|
+
tip;
|
|
45
|
+
constructor() {
|
|
46
|
+
this.tip = Promise.resolve(void 0);
|
|
47
|
+
}
|
|
48
|
+
async acquire() {
|
|
49
|
+
const oldTip = this.tip;
|
|
50
|
+
let resolver = noop;
|
|
51
|
+
const promise = new Promise((resolve) => {
|
|
52
|
+
resolver = resolve;
|
|
53
|
+
});
|
|
54
|
+
this.tip = oldTip.then(() => promise);
|
|
55
|
+
return oldTip.then(() => resolver);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/lobby.ts
|
|
35
60
|
var BOT_NAME = "電腦";
|
|
36
61
|
var DHSError = class extends import_koishi.SessionError {
|
|
37
62
|
static {
|
|
@@ -136,6 +161,7 @@ var RiichiCityLobby = class {
|
|
|
136
161
|
notify;
|
|
137
162
|
notifyIdle = 0;
|
|
138
163
|
notifyCache;
|
|
164
|
+
lock = new Lock();
|
|
139
165
|
async init() {
|
|
140
166
|
this.details = await this.api.enterLobby(this.id);
|
|
141
167
|
this.classifyID = this.details.classifyID;
|
|
@@ -172,32 +198,37 @@ var RiichiCityLobby = class {
|
|
|
172
198
|
return res.map((x) => new Paipu(this, x.roomID, x.players.map((p) => new Player(p.nickname, p.points, p.userId)), { paipuID: x.paiPuId }));
|
|
173
199
|
}
|
|
174
200
|
async startMatch(players, tag = "", randomPosition = true) {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
const release = await this.lock.acquire();
|
|
202
|
+
try {
|
|
203
|
+
const onlinePlayers = await this.listPlayers();
|
|
204
|
+
const notFound = [];
|
|
205
|
+
for (const player of players) {
|
|
206
|
+
if (player.accountId === null || player.accountId === void 0) {
|
|
207
|
+
if (player.nickname in onlinePlayers) {
|
|
208
|
+
player.accountId = onlinePlayers[player.nickname];
|
|
209
|
+
} else {
|
|
210
|
+
notFound.push(player.pattern);
|
|
211
|
+
}
|
|
212
|
+
} else if (player.accountId) {
|
|
213
|
+
if (!Object.values(onlinePlayers).includes(player.accountId)) notFound.push(player.pattern);
|
|
183
214
|
}
|
|
184
|
-
} else if (player.accountId) {
|
|
185
|
-
if (!Object.values(onlinePlayers).includes(player.accountId)) notFound.push(player.pattern);
|
|
186
215
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
216
|
+
if (notFound.length) throw new PlayerNotFoundError(...notFound);
|
|
217
|
+
for (const player of players) {
|
|
218
|
+
if (player.accountId === 0) {
|
|
219
|
+
player.accountId = await this.api.addLobbyBot();
|
|
220
|
+
}
|
|
192
221
|
}
|
|
222
|
+
if (randomPosition) players = import_koishi.Random.shuffle(players);
|
|
223
|
+
return await this.api.startMatch({
|
|
224
|
+
table_idx: 1,
|
|
225
|
+
usersID: players.map((p) => p.accountId),
|
|
226
|
+
initPoints: players.map((p) => p.point),
|
|
227
|
+
matchID: this.id
|
|
228
|
+
});
|
|
229
|
+
} finally {
|
|
230
|
+
release();
|
|
193
231
|
}
|
|
194
|
-
if (randomPosition) players = import_koishi.Random.shuffle(players);
|
|
195
|
-
return await this.api.startMatch({
|
|
196
|
-
table_idx: 1,
|
|
197
|
-
usersID: players.map((p) => p.accountId),
|
|
198
|
-
initPoints: players.map((p) => p.point),
|
|
199
|
-
matchID: this.id
|
|
200
|
-
});
|
|
201
232
|
}
|
|
202
233
|
};
|
|
203
234
|
// Annotate the CommonJS export names for ESM import in node:
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Resolver<T> {
|
|
2
|
+
readonly promise: Promise<T>;
|
|
3
|
+
private resolver;
|
|
4
|
+
private rejecter;
|
|
5
|
+
constructor();
|
|
6
|
+
get resolve(): (result?: T | PromiseLike<T>) => void;
|
|
7
|
+
get reject(): (reason: any | PromiseLike<any>) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare class Lock {
|
|
10
|
+
private tip;
|
|
11
|
+
constructor();
|
|
12
|
+
acquire(): Promise<() => void>;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hieuzest/koishi-plugin-riichi-city",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.8",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -24,11 +24,9 @@
|
|
|
24
24
|
"riichi-city"
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"@hieuzest/koishi-plugin-mahjong": "^3.0.0",
|
|
27
28
|
"koishi": "^4.17.8"
|
|
28
29
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"@hieuzest/koishi-utils": "^1.0.0"
|
|
31
|
-
},
|
|
32
30
|
"koishi": {
|
|
33
31
|
"service": {
|
|
34
32
|
"implements": [
|
|
@@ -40,5 +38,12 @@
|
|
|
40
38
|
]
|
|
41
39
|
},
|
|
42
40
|
"hidden": true
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@hieuzest/koishi-buildtools": "^1.0.2",
|
|
44
|
+
"@hieuzest/koishi-plugin-mahjong": "^3.0.0",
|
|
45
|
+
"@koishijs/plugin-admin": "^2.0.0-beta.4",
|
|
46
|
+
"@koishijs/plugin-proxy-agent": "^0.3.3",
|
|
47
|
+
"koishi": "^4.18.9"
|
|
43
48
|
}
|
|
44
49
|
}
|