koishi-plugin-prism 0.1.18 → 0.1.19
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/README.md +4 -3
- package/lib/index.js +39 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
* 🎮 **玩家入场与结算**:通过 `/login` 和 `/logout` 指令开启或结算计费场次,支持 `/入场` 别名;命令回复会引用触发消息,结账账单可私聊通知管理员与指定用户。
|
|
10
10
|
* 💳 **账户钱包与资产管理**:支持查询钱包余额(`/wallet`)和持有的道具资产(`/items`)。
|
|
11
|
-
* 🀄 **麻将桌位集成**:包含 `/mahjong <tableId
|
|
11
|
+
* 🀄 **麻将桌位集成**:包含 `/mahjong <tableId>`、`/上桌 <桌号>`、自动识别当前桌位的 `/下桌`,以及用于查看桌名、别名和状态的 `/麻将列表`。`上桌` 仅允许已通过 `login`/`入场` 开启默认入场会话的玩家使用。`list` 按 session 标签分组:有非音乐游戏 session 的玩家归入最新的非音乐标签,纯音乐玩家归入音乐标签;麻将桌额外显示当前人数和容量。已开局桌位会从后端活跃 session 自动恢复,未满桌候座仍由机器人进程暂存,重启后不会保留。
|
|
12
12
|
* 🔌 **硬件设备状态与电源管理**:可直接在聊天中查看设备状态(`/show`)、远程开启/关闭电源(`/on`、`/off`)、远程投币(`/coin`)和模拟刷卡(`/scan`)。
|
|
13
13
|
* 🎟️ **礼物兑换码**:使用 `/redeem <code>` 兑换系统发放的福利礼包。
|
|
14
14
|
* 🛠️ **管理员快捷指令**:允许管理员为指定平台用户增加或扣除余额,并覆盖结账金额后立即结账。
|
|
@@ -70,8 +70,9 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
70
70
|
* `coin <deviceId> [count]` - 请求向指定设备投币指定枚数。
|
|
71
71
|
* `scan <deviceId> <subject>` - 请求向设备发送模拟刷卡。
|
|
72
72
|
* `redeem <code>` - 兑换礼物码。
|
|
73
|
-
* `mahjong <tableId>` / `上桌
|
|
74
|
-
*
|
|
73
|
+
* `mahjong <tableId>` / `上桌 [tableId]` - 加入指定麻将桌;`/上桌` 未提供桌号时会引导查看 `/麻将列表`。仅允许已通过 `login`/`入场` 开启默认入场会话的玩家使用。
|
|
74
|
+
* `下桌` - 自动离开当前所在麻将桌。
|
|
75
|
+
* `麻将列表` - 查看已配置机器的桌名、命令别名,以及空闲、等位或游玩中状态。
|
|
75
76
|
|
|
76
77
|
### 管理员快捷指令
|
|
77
78
|
启用 `enableStaffCommands`、配置 `staffUserIds` 白名单与 `staffSessionToken` 后可使用:
|
package/lib/index.js
CHANGED
|
@@ -50,7 +50,8 @@ exports.PrismBotClientError = PrismBotClientError;
|
|
|
50
50
|
const LOCAL_TZ_OFFSET_MINUTES = 8 * 60;
|
|
51
51
|
const USAGE = {
|
|
52
52
|
mahjong_join: "/上桌 <桌号>",
|
|
53
|
-
mahjong_leave: "/下桌
|
|
53
|
+
mahjong_leave: "/下桌",
|
|
54
|
+
mahjong_list: "/麻将列表",
|
|
54
55
|
prism_on: "/prism on <设备ID>",
|
|
55
56
|
prism_off: "/prism off <设备ID|all>",
|
|
56
57
|
prism_coin: "/prism coin <设备ID> [数量]",
|
|
@@ -75,8 +76,9 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
75
76
|
ctx.command("login [target:user]", "开启玩家计费场次").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
76
77
|
ctx.command("入场 [target:user]", "入场").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
77
78
|
ctx.command("mahjong <tableId>", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
78
|
-
ctx.command("上桌
|
|
79
|
-
ctx.command("下桌
|
|
79
|
+
ctx.command("上桌 [tableId]", "加入指定麻将桌").action(wrap(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
80
|
+
ctx.command("下桌", "离开当前所在麻将桌").action(wrap(async (context) => service.mahjongLeave(await service.sender(context))));
|
|
81
|
+
ctx.command("麻将列表", "查看麻将机状态与别名").action(wrap(async () => service.listMahjongTables()));
|
|
80
82
|
ctx.command("logout [target:user]", "结算玩家计费场次").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.logout(sender, context.session?.bot), context.session?.bot)));
|
|
81
83
|
ctx.command("billing [target:user]", "预览玩家结账费用").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.billing(sender), context.session?.bot)));
|
|
82
84
|
ctx.command("wallet [target:user]", "查看玩家钱包").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.wallet(sender), context.session?.bot)));
|
|
@@ -390,10 +392,10 @@ class PrismKoishiService {
|
|
|
390
392
|
async mahjongJoin(sender, rawTableId) {
|
|
391
393
|
const tableId = cleanText(rawTableId);
|
|
392
394
|
if (!tableId)
|
|
393
|
-
return
|
|
395
|
+
return "请指定麻将桌,例如 /上桌 a;可先使用 /麻将列表 查看可用桌位。";
|
|
394
396
|
const tableConfig = this.mahjongTableConfigs().get(tableId);
|
|
395
397
|
if (!tableConfig)
|
|
396
|
-
return
|
|
398
|
+
return `未找到麻将桌「${tableId}」。可先使用 /麻将列表 查看可用桌位。`;
|
|
397
399
|
const tableKey = tableConfig.tableId;
|
|
398
400
|
const tableSubject = tableConfig.displayName || `${tableKey} 桌`;
|
|
399
401
|
const player = await this.resolvePlayer(sender);
|
|
@@ -406,11 +408,11 @@ class PrismKoishiService {
|
|
|
406
408
|
}
|
|
407
409
|
const existing = this.mahjongTableForPlayer(playerId);
|
|
408
410
|
if (existing)
|
|
409
|
-
return `你已经在 ${existing}
|
|
411
|
+
return `你已经在 ${existing},无需重复上桌。`;
|
|
410
412
|
const state = this.mahjongTables.get(tableKey) ?? { waiting: [], activeSessions: {} };
|
|
411
413
|
this.mahjongTables.set(tableKey, state);
|
|
412
414
|
if (Object.keys(state.activeSessions).length > 0) {
|
|
413
|
-
return
|
|
415
|
+
return `「${tableSubject}」正在游玩中(${Object.keys(state.activeSessions).length}/${this.config.mahjongTableSize ?? 4}),请等待本局结束后再上桌。`;
|
|
414
416
|
}
|
|
415
417
|
state.waiting.push({
|
|
416
418
|
playerId,
|
|
@@ -437,20 +439,19 @@ class PrismKoishiService {
|
|
|
437
439
|
}
|
|
438
440
|
return `${tableSubject}已满,麻将计费已开始。`;
|
|
439
441
|
}
|
|
440
|
-
async mahjongLeave(sender
|
|
441
|
-
const tableId = cleanText(rawTableId);
|
|
442
|
-
if (!tableId)
|
|
443
|
-
return commandUsage("mahjong_leave");
|
|
444
|
-
const tableConfig = this.mahjongTableConfigs().get(tableId);
|
|
445
|
-
const tableKey = tableConfig?.tableId ?? tableId;
|
|
446
|
-
const tableSubject = tableConfig?.displayName || `${tableId} 桌`;
|
|
442
|
+
async mahjongLeave(sender) {
|
|
447
443
|
const activeResult = (await this.client.listActiveSessions());
|
|
448
444
|
this.syncMahjongTableStates((activeResult.sessions ?? []));
|
|
449
|
-
const state = this.mahjongTables.get(tableKey);
|
|
450
|
-
if (!state)
|
|
451
|
-
return `你不在 ${tableSubject}。`;
|
|
452
445
|
const player = await this.resolvePlayer(sender);
|
|
453
446
|
const playerId = String(player.id ?? "");
|
|
447
|
+
const tableKey = this.mahjongTableForPlayer(playerId);
|
|
448
|
+
if (!tableKey)
|
|
449
|
+
return "你当前未在任何麻将桌上。";
|
|
450
|
+
const tableConfig = uniqueMahjongConfigs(this.mahjongTableConfigs()).find((table) => table.tableId === tableKey);
|
|
451
|
+
const tableSubject = tableConfig?.displayName || tableKey;
|
|
452
|
+
const state = this.mahjongTables.get(tableKey);
|
|
453
|
+
if (!state)
|
|
454
|
+
return "你当前未在任何麻将桌上。";
|
|
454
455
|
const waitingBefore = state.waiting.length;
|
|
455
456
|
state.waiting = state.waiting.filter((seat) => seat.playerId !== playerId);
|
|
456
457
|
if (state.waiting.length !== waitingBefore) {
|
|
@@ -458,11 +459,31 @@ class PrismKoishiService {
|
|
|
458
459
|
}
|
|
459
460
|
const sessionId = state.activeSessions[playerId];
|
|
460
461
|
if (!sessionId)
|
|
461
|
-
return
|
|
462
|
+
return "你当前未在任何麻将桌上。";
|
|
462
463
|
delete state.activeSessions[playerId];
|
|
463
464
|
await this.client.stopSessionByIdentity(this.identity(sender), sessionId);
|
|
464
465
|
return `已离开 ${tableSubject},麻将计费已停止。`;
|
|
465
466
|
}
|
|
467
|
+
async listMahjongTables() {
|
|
468
|
+
const activeResult = (await this.client.listActiveSessions());
|
|
469
|
+
this.syncMahjongTableStates((activeResult.sessions ?? []));
|
|
470
|
+
const tableSize = this.config.mahjongTableSize ?? 4;
|
|
471
|
+
const tables = uniqueMahjongConfigs(this.mahjongTableConfigs());
|
|
472
|
+
if (tables.length === 0)
|
|
473
|
+
return "当前没有配置任何麻将机。";
|
|
474
|
+
const lines = [`🀄️ 麻将机列表(${tables.length} 台)`];
|
|
475
|
+
for (const table of tables) {
|
|
476
|
+
const state = this.mahjongTables.get(table.tableId) ?? { waiting: [], activeSessions: {} };
|
|
477
|
+
const activeCount = Object.keys(state.activeSessions).length;
|
|
478
|
+
const waitingCount = state.waiting.length;
|
|
479
|
+
const statuses = [
|
|
480
|
+
...(activeCount > 0 ? [`游玩中 ${activeCount}/${tableSize}`] : []),
|
|
481
|
+
...(waitingCount > 0 ? [`等位 ${waitingCount}/${tableSize}`] : []),
|
|
482
|
+
];
|
|
483
|
+
lines.push(`- ${table.displayName}|别名:${table.aliases.length > 0 ? table.aliases.join("、") : "无"}|${statuses.join(";") || "空闲"}`);
|
|
484
|
+
}
|
|
485
|
+
return lines.join("\n");
|
|
486
|
+
}
|
|
466
487
|
async billing(sender) {
|
|
467
488
|
const result = (await this.client.previewCheckoutByIdentity(this.identity(sender)));
|
|
468
489
|
return this.formatCheckoutPreview(result, sender);
|