koishi-plugin-prism 0.1.37 → 0.1.39
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 +36 -4
- package/lib/index.d.ts +3 -0
- package/lib/index.js +147 -50
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
| 配置项 | 类型 | 默认值 | 描述 |
|
|
23
23
|
| :--- | :---: | :---: | :--- |
|
|
24
24
|
| `baseUrl` | `string` | - | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
|
|
25
|
+
| `shopCode` | `string` | - | 统一平台的店铺公开编号;单店兼容部署留空。 |
|
|
25
26
|
| `integrationToken` | `string` | - | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
|
|
26
27
|
| `provider` | `string` | `"qq"` | 当前绑定的账号提供商平台名称(如 `"qq"`,`"discord"`)。 |
|
|
27
28
|
| `autoRegister` | `boolean` | `true` | 当玩家未注册时,是否在首次操作(如入场/查钱包)时自动在 PRiSM 中创建新玩家。 |
|
|
@@ -33,10 +34,18 @@
|
|
|
33
34
|
| `resolveDisplayName` | `function` | - | 可选。自定义用于获取群内昵称作为玩家注册名的异步逻辑。 |
|
|
34
35
|
| `enableStaffCommands` | `boolean` | `false` | 是否开启管理员快捷指令。 |
|
|
35
36
|
| `staffUserIds` | `string[]` | `[]` | 允许执行管理员快捷指令的平台用户 ID(如 QQ 号)白名单。空列表不授予目标用户操作权限。 |
|
|
36
|
-
| `powerCommandsAdminOnly` | `boolean` | `false` |
|
|
37
|
+
| `powerCommandsAdminOnly` | `boolean` | `false` | 关机是否仅允许 `staffUserIds` 中的管理员使用。`/on` 始终只允许已入场玩家使用。 |
|
|
37
38
|
| `logoutNotifyUserIds` | `string[]` | `[]` | 结账成功后额外私聊完整账单的平台用户 ID。通知收件人为该列表与 `staffUserIds` 的去重并集。 |
|
|
38
39
|
| `mahjongTableConfigs` | `object[]` | `[]` | 推荐的结构化麻将桌列表。每项填写显示名称、命令别名列表与计费方案 ID 列表。显示名称同时作为内部桌位锚点与 session 标签。 |
|
|
39
40
|
|
|
41
|
+
### 统一平台
|
|
42
|
+
|
|
43
|
+
配置 `baseUrl`、`shopCode` 和本店的 Integration 令牌后,插件调用 `/api/v1/shops/:shopCode/integration`;单店兼容部署调用 `/api/v1/integration`。
|
|
44
|
+
|
|
45
|
+
玩家在网页取得验证码后,向 Bot 发送 `prism.bind 验证码`。绑定使用消息发送人的 QQ,不接受代填 QQ。允许哪些群或私聊使用此指令,由店家在 Bot 框架中配置过滤;后端和插件不再维护群白名单或群聊/私聊限制。网页账号可以跨店使用,QQ 验证和余额分别属于各店;默认只允许绑定本店已有玩家,店主可以开启新玩家注册。
|
|
46
|
+
|
|
47
|
+
统一平台以店铺的入场规则和注册开关为准。Web 与 Bot 普通入场共享去重;显式的麻将规则继续使用桌位流程。店铺启用入场、出场或机器操作定位时,对应 Bot 操作会返回本店网页地址。玩家余额不足时结账失败并继续计时。
|
|
48
|
+
|
|
40
49
|
### 麻将桌配置
|
|
41
50
|
|
|
42
51
|
在 Koishi 配置页的 `mahjongTableConfigs` 中新增桌位,每一项填写:
|
|
@@ -71,11 +80,11 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
71
80
|
* `show [deviceId]` - 查看设备电源与连接状态。
|
|
72
81
|
设备状态按后端的普通字符串契约显示;插件仍兼容历史数据库中的 JSON 字符串状态,避免旧记录显示为 `unknown`。
|
|
73
82
|
* `history` - 查看自己的历史游玩记录。
|
|
74
|
-
* `lock` -
|
|
83
|
+
* `lock` - 为默认 TTLock 门锁生成一个 8 位随机临时密码(有效期 3 分钟)并回复密码。
|
|
75
84
|
* `on <deviceRef>` - 使用后台设备名称、别名或 `all` 请求启动电源;仅已通过 `login`/`入场` 开启活跃计费 session 的玩家可用。不接受 Home Assistant entity ID,成功回复使用后端返回的设备名称。
|
|
76
85
|
* `off <deviceRef>` - 使用后台设备名称、别名或 `all` 请求关闭电源;与 `/on` 一样仅允许已入场玩家使用,不接受 Home Assistant entity ID,`all` 显示为“所有设备”。
|
|
77
|
-
* `coin
|
|
78
|
-
* `scan
|
|
86
|
+
* `coin <设备名或别名> [count]` - 请求向后台配置的 Hinata IO 设备投币;需要玩家已入场。
|
|
87
|
+
* `scan <设备名或别名>` - 使用当前玩家后台绑定的 Aime 卡向设备刷卡,不在群聊中输入或显示卡号。
|
|
79
88
|
* `redeem <code>` - 兑换礼物码。
|
|
80
89
|
* `mahjong <tableId>` / `上桌 [tableId]` - 加入指定麻将桌;`/上桌` 未提供桌号时会引导查看 `/麻将列表`。仅允许已通过 `login`/`入场` 开启默认入场会话的玩家使用。支持在桌位未满但已开局时进行中途补位(即直接开始计费上桌)。
|
|
81
90
|
* `下桌` - 自动离开当前所在麻将桌,下桌后会停止计费,并显示该麻将桌的剩余游玩人数。
|
|
@@ -109,6 +118,29 @@ Bot 版本直接读取本 npm 包的 `package.json`,后端版本读取无需
|
|
|
109
118
|
bun run test
|
|
110
119
|
```
|
|
111
120
|
|
|
121
|
+
### CI 自动发布
|
|
122
|
+
|
|
123
|
+
发布使用 GitHub Actions 的 npm Trusted Publishing。修改版本后推送带 `v` 前缀且与 `package.json` 一致的标签即可自动测试、构建并发布:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm version patch
|
|
127
|
+
git push origin main --follow-tags
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
首次使用前,在 npm 包设置的 Trusted Publisher 中选择 GitHub Actions,填写仓库 `nerimoe/koishi-plugin-prism` 和工作流文件名 `publish.yml`,并允许 `npm publish`。
|
|
131
|
+
|
|
112
132
|
## 📄 开源协议
|
|
113
133
|
|
|
114
134
|
[MIT License](LICENSE)
|
|
135
|
+
|
|
136
|
+
统一平台支持 QQ 绑定、查人以及原有计费/设备命令。持有有效店铺 Integration 令牌的 Bot 不受玩家定位和扫码入口限制;玩家身份、入场要求、投币冷却及插件员工权限仍保留。查人合并后端持久化麻将名单和旧 Bot 桌位记录。普通入场的 `entry` 标签兼容旧 `loginSessionLabel`,不会误拒绝已入场玩家上桌。
|
|
137
|
+
|
|
138
|
+
2026-09-13 使用 Koishi 4.18.11 实际命令解析和本地 HTTP,对已有 MMW prism-next 快照运行旧新版对比:18 名在店玩家的账单/钱包/资产/历史与查人共 73 次查询文本一致;另测试入退场、四人麻将、余额调整、兑换、开关机、门锁、投币冷却、重复刷卡、离线和权限拒绝。QQ 消息本地注入,硬件使用本地模拟服务,不代表真实 QQ 投递或物理硬件验收。
|
|
139
|
+
|
|
140
|
+
### QQ 绑定与查人验收
|
|
141
|
+
|
|
142
|
+
QQ 绑定支持 Koishi 的 `qq` 和 `onebot` 平台,发送人 ID 必须是 QQ 号码;群/私聊过滤仍交给 Koishi。`/list` 使用店铺作用域接口并兼容 data 响应封装,人数统计包括尚未开局的麻将等待玩家,按玩家 ID 去重。只通过源码测试不能证明运行中的 Bot 已更新;npm 发行版与分支提交需要分别核对。
|
|
143
|
+
|
|
144
|
+
### 0.1.39
|
|
145
|
+
|
|
146
|
+
支持统一平台店铺 API、QQ/OneBot 绑定和麻将查人统计;兼容新版入场标签,修复已入场玩家无法通过 Bot 上桌的问题。
|
package/lib/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type PrismKoishiPluginConfig = {
|
|
|
41
41
|
resolveDisplayName?: (subject: string) => Promise<string | null | undefined> | string | null | undefined;
|
|
42
42
|
/** Get a stable current ISO timestamp; mainly for tests. */
|
|
43
43
|
now?: () => Date;
|
|
44
|
+
shopCode?: string;
|
|
44
45
|
baseUrl?: string;
|
|
45
46
|
integrationToken?: string;
|
|
46
47
|
client?: any;
|
|
@@ -61,6 +62,8 @@ export type KoishiLikeContext = {
|
|
|
61
62
|
};
|
|
62
63
|
export type KoishiActionContext = {
|
|
63
64
|
session: {
|
|
65
|
+
platform?: string;
|
|
66
|
+
isDirect?: boolean;
|
|
64
67
|
userId: string;
|
|
65
68
|
messageId?: string;
|
|
66
69
|
senderId?: string;
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.version = package_json_1.default.version;
|
|
|
15
15
|
exports.Config = koishi_1.Schema.object({
|
|
16
16
|
provider: koishi_1.Schema.string().required().description("平台提供商 (如 qq)"),
|
|
17
17
|
autoRegister: koishi_1.Schema.boolean().default(true).description("是否自动注册"),
|
|
18
|
+
shopCode: koishi_1.Schema.string().description("统一平台店铺编号(单店兼容模式留空)"),
|
|
18
19
|
baseUrl: koishi_1.Schema.string().description("PRiSM 后端 API Base URL"),
|
|
19
20
|
integrationToken: koishi_1.Schema.string().role("secret").description("集成 API Token"),
|
|
20
21
|
currencyName: koishi_1.Schema.string().default("猫粮").description("代币名称"),
|
|
@@ -24,7 +25,7 @@ exports.Config = koishi_1.Schema.object({
|
|
|
24
25
|
loginSessionLabel: koishi_1.Schema.string().default("音游区间").description("默认入场场次标签 (防重复入场)"),
|
|
25
26
|
enableStaffCommands: koishi_1.Schema.boolean().default(false).description("是否启用管理员指令"),
|
|
26
27
|
staffUserIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("允许执行管理员指令的平台用户ID列表"),
|
|
27
|
-
powerCommandsAdminOnly: koishi_1.Schema.boolean().default(false).description("
|
|
28
|
+
powerCommandsAdminOnly: koishi_1.Schema.boolean().default(false).description("关机是否仅允许管理员使用;开机始终仅已入场玩家可用"),
|
|
28
29
|
logoutNotifyUserIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("结账账单私聊通知的平台用户ID列表"),
|
|
29
30
|
powerOffInterval: koishi_1.Schema.number().default(0).description("无人自动关机等待秒数 (0为禁用)"),
|
|
30
31
|
mahjongTableConfigs: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
@@ -60,8 +61,8 @@ const USAGE = {
|
|
|
60
61
|
api_benchmark: "/api测速 [次数]",
|
|
61
62
|
prism_on: "/prism on <设备名|别名|all>",
|
|
62
63
|
prism_off: "/prism off <设备名|别名|all>",
|
|
63
|
-
prism_coin: "/prism coin
|
|
64
|
-
prism_scan: "/prism scan
|
|
64
|
+
prism_coin: "/prism coin <设备名或别名> [数量]",
|
|
65
|
+
prism_scan: "/prism scan <设备名或别名>",
|
|
65
66
|
prism_redeem: "/prism redeem <兑换码>",
|
|
66
67
|
list: "/list",
|
|
67
68
|
show: "/show [设备ID]",
|
|
@@ -78,6 +79,20 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
78
79
|
return context.session?.messageId ? `${(0, koishi_1.h)("quote", { id: context.session.messageId })}${message}` : message;
|
|
79
80
|
}
|
|
80
81
|
};
|
|
82
|
+
ctx.command("prism.bind <code:string>", "绑定网页登录账号到本店 QQ 身份").action(wrap(async (context, code) => {
|
|
83
|
+
if (!["qq", "onebot"].includes(context.session.platform ?? ""))
|
|
84
|
+
return "请使用 QQ 身份发送验证码";
|
|
85
|
+
if (!/^[1-9]\d{4,19}$/.test(context.session.userId ?? ""))
|
|
86
|
+
return "无法获取发送人的 QQ 号";
|
|
87
|
+
if (!config.shopCode || !config.baseUrl || !config.integrationToken)
|
|
88
|
+
return "请店家配置统一平台店铺编号与 Bot 凭据";
|
|
89
|
+
const response = await fetch(`${config.baseUrl.replace(/\/+$/, "")}/api/v1/shops/${encodeURIComponent(config.shopCode)}/integration/qq-binding/confirm`, {
|
|
90
|
+
method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${config.integrationToken}` },
|
|
91
|
+
body: JSON.stringify({ code, qq: context.session.userId }),
|
|
92
|
+
});
|
|
93
|
+
const body = await response.json();
|
|
94
|
+
return response.ok ? "绑定成功,请返回网页继续操作" : body.error?.message ?? "绑定失败,请重新生成验证码";
|
|
95
|
+
}));
|
|
81
96
|
ctx.command("register", "绑定或注册当前平台用户到 PRiSM").action(wrap(async (context) => service.register(await service.sender(context))));
|
|
82
97
|
ctx.command("login [target:user]", "开启玩家计费场次").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
83
98
|
ctx.command("入场 [target:user]", "入场").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
@@ -97,8 +112,8 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
97
112
|
ctx.command("lock", "向默认门锁设备发送开门指令").action(wrap(async (context) => service.lock(await service.sender(context))));
|
|
98
113
|
ctx.command("on <deviceRef>", "请求启动指定设备电源").action(wrap(async (context, deviceRef) => service.powerOn(await service.sender(context), deviceRef)));
|
|
99
114
|
ctx.command("off <deviceRef>", "请求关闭指定设备电源").action(wrap(async (context, deviceRef) => service.powerOff(await service.sender(context), deviceRef)));
|
|
100
|
-
ctx.command("coin <
|
|
101
|
-
ctx.command("scan <
|
|
115
|
+
ctx.command("coin <deviceRef> [count]", "请求向指定设备投币").action(wrap(async (context, deviceRef, count) => service.coin(await service.sender(context), deviceRef, count)));
|
|
116
|
+
ctx.command("scan <deviceRef>", "使用当前玩家绑定的 Aime 卡刷卡").action(wrap(async (context, deviceRef) => service.scan(await service.sender(context), deviceRef)));
|
|
102
117
|
ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(await service.sender(context), code)));
|
|
103
118
|
ctx.command("add <target:user> <amount:number>", "增加玩家余额").action(wrap(async (context, target, amount) => service.adjustTargetBalance(await service.sender(context), target, amount, 1, context.session?.bot)));
|
|
104
119
|
ctx.command("del <target:user> <amount:number>", "扣除玩家余额").action(wrap(async (context, target, amount) => service.adjustTargetBalance(await service.sender(context), target, amount, -1, context.session?.bot)));
|
|
@@ -126,7 +141,7 @@ class PrismApiClient {
|
|
|
126
141
|
};
|
|
127
142
|
}
|
|
128
143
|
async request(method, path, options) {
|
|
129
|
-
let url = path;
|
|
144
|
+
let url = path.replace(/^\/rpc\//, this.config.shopCode ? `/api/v1/shops/${encodeURIComponent(this.config.shopCode)}/` : "/api/v1/");
|
|
130
145
|
if (options.params) {
|
|
131
146
|
for (const [key, value] of Object.entries(options.params)) {
|
|
132
147
|
url = url.replace(`:${key}`, encodeURIComponent(String(value)));
|
|
@@ -154,7 +169,7 @@ class PrismApiClient {
|
|
|
154
169
|
else {
|
|
155
170
|
throw new Error(`Unsupported method ${method}`);
|
|
156
171
|
}
|
|
157
|
-
return response;
|
|
172
|
+
return response && typeof response === "object" && Object.hasOwn(response, "data") ? response.data : response;
|
|
158
173
|
}
|
|
159
174
|
catch (error) {
|
|
160
175
|
if (error?.response) {
|
|
@@ -267,13 +282,12 @@ class PrismApiClient {
|
|
|
267
282
|
...this.identityBody(identity),
|
|
268
283
|
target: {
|
|
269
284
|
kind: "game_machine",
|
|
270
|
-
|
|
285
|
+
ref: scan.deviceRef,
|
|
271
286
|
},
|
|
272
287
|
action: {
|
|
273
288
|
type: "aime.scan",
|
|
274
289
|
payload: {
|
|
275
290
|
provider: scan.provider,
|
|
276
|
-
subject: scan.subject,
|
|
277
291
|
},
|
|
278
292
|
},
|
|
279
293
|
},
|
|
@@ -350,6 +364,7 @@ class PrismKoishiService {
|
|
|
350
364
|
};
|
|
351
365
|
this.client = new PrismApiClient(http, {
|
|
352
366
|
baseUrl: config.baseUrl,
|
|
367
|
+
shopCode: config.shopCode,
|
|
353
368
|
integrationToken: config.integrationToken,
|
|
354
369
|
});
|
|
355
370
|
}
|
|
@@ -646,11 +661,28 @@ class PrismKoishiService {
|
|
|
646
661
|
return formatHistory(result.sessions, this.config.currencyName);
|
|
647
662
|
}
|
|
648
663
|
async lock(sender) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
664
|
+
try {
|
|
665
|
+
const result = await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
|
|
666
|
+
type: "door.open",
|
|
667
|
+
target: { kind: "facility", ref: this.config.defaultDoorDeviceId },
|
|
668
|
+
});
|
|
669
|
+
const failure = this.getCommandFailureMessage(result);
|
|
670
|
+
if (failure) {
|
|
671
|
+
this.logDeviceCommandFailure(result);
|
|
672
|
+
return `🔑 开门失败,${deviceCommandFailureReason(result)}`;
|
|
673
|
+
}
|
|
674
|
+
if (result?.action?.executorKind && result.action.executorKind !== "ttlock") {
|
|
675
|
+
return "🔑 门锁指令已发送";
|
|
676
|
+
}
|
|
677
|
+
const password = cleanText(result?.action?.payload?.temporaryPassword);
|
|
678
|
+
if (!password)
|
|
679
|
+
return "🔑 临时门锁密码生成失败,请稍后再试";
|
|
680
|
+
return `🔑 临时门锁密码:${password}\n有效期:3 分钟`;
|
|
681
|
+
}
|
|
682
|
+
catch (error) {
|
|
683
|
+
this.logCommandError(error);
|
|
684
|
+
return `🔑 开门失败,${deviceActionFailureReason(error)}`;
|
|
685
|
+
}
|
|
654
686
|
}
|
|
655
687
|
async powerOn(sender, rawDeviceRef) {
|
|
656
688
|
const deviceRef = cleanText(rawDeviceRef);
|
|
@@ -664,37 +696,53 @@ class PrismKoishiService {
|
|
|
664
696
|
return commandUsage("prism_off");
|
|
665
697
|
return this.power(sender, deviceRef, "off");
|
|
666
698
|
}
|
|
667
|
-
async coin(sender,
|
|
668
|
-
const
|
|
669
|
-
if (!
|
|
699
|
+
async coin(sender, rawDeviceRef, rawCount) {
|
|
700
|
+
const deviceRef = cleanText(rawDeviceRef);
|
|
701
|
+
if (!deviceRef)
|
|
670
702
|
return commandUsage("prism_coin");
|
|
671
703
|
const { value, error } = parsePositiveInt(rawCount, "prism_coin", "数量", 1);
|
|
672
704
|
if (error)
|
|
673
705
|
return error;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
706
|
+
try {
|
|
707
|
+
const result = await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
|
|
708
|
+
type: "coin",
|
|
709
|
+
target: { kind: "game_machine", ref: deviceRef },
|
|
710
|
+
payload: { count: value },
|
|
711
|
+
});
|
|
712
|
+
const failure = deviceCommandFailureReason(result);
|
|
713
|
+
if (failure) {
|
|
714
|
+
this.logDeviceCommandFailure(result);
|
|
715
|
+
return `投币失败,${failure}`;
|
|
716
|
+
}
|
|
717
|
+
const label = deviceCommandLabel(result) || deviceRef;
|
|
718
|
+
return `🪙 ${label} 投币成功(${value} 币)`;
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
this.logCommandError(error);
|
|
722
|
+
return `投币失败,${deviceActionFailureReason(error)}`;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
async scan(sender, rawDeviceRef) {
|
|
726
|
+
const deviceRef = cleanText(rawDeviceRef);
|
|
727
|
+
if (!deviceRef)
|
|
688
728
|
return commandUsage("prism_scan");
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
729
|
+
try {
|
|
730
|
+
const result = await this.client.requestScanByIdentity(this.identity(sender), {
|
|
731
|
+
deviceRef,
|
|
732
|
+
provider: this.config.defaultScanProvider || "aime",
|
|
733
|
+
});
|
|
734
|
+
const failure = deviceCommandFailureReason(result);
|
|
735
|
+
if (failure) {
|
|
736
|
+
this.logDeviceCommandFailure(result);
|
|
737
|
+
return `刷卡失败,${failure}`;
|
|
738
|
+
}
|
|
739
|
+
const label = deviceCommandLabel(result) || deviceRef;
|
|
740
|
+
return `💳 ${label} 刷卡成功`;
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
this.logCommandError(error);
|
|
744
|
+
return `刷卡失败,${deviceActionFailureReason(error)}`;
|
|
745
|
+
}
|
|
698
746
|
}
|
|
699
747
|
async redeem(sender, rawCode) {
|
|
700
748
|
const code = cleanText(rawCode);
|
|
@@ -717,7 +765,20 @@ class PrismKoishiService {
|
|
|
717
765
|
const players = groupSessionsByPlayer(sessions);
|
|
718
766
|
const groups = await this.buildPlayerGroups(players, tableByLabel);
|
|
719
767
|
this.mergeWaitingSeats(groups);
|
|
720
|
-
|
|
768
|
+
const tables = result.mahjongTables;
|
|
769
|
+
if (!tables)
|
|
770
|
+
return formatPlayerGroups(groups, this.config.mahjongTableSize ?? 4);
|
|
771
|
+
const seated = new Set(tables.flatMap(table => table.players.map(player => player.id)));
|
|
772
|
+
for (const group of groups.groups)
|
|
773
|
+
group.players = group.players.filter(player => !seated.has(player.playerId));
|
|
774
|
+
return [
|
|
775
|
+
formatPlayerGroups(groups, this.config.mahjongTableSize ?? 4, new Set([
|
|
776
|
+
...seated, ...groups.groups.flatMap(group => group.players.map(player => player.playerId)),
|
|
777
|
+
]).size),
|
|
778
|
+
...tables.map(table => `
|
|
779
|
+
${table.name}(${table.players.length}/${table.capacity}):
|
|
780
|
+
${table.players.map(player => player.name).join("、")}`),
|
|
781
|
+
].filter(Boolean).join("\n");
|
|
721
782
|
}
|
|
722
783
|
async listDeviceStates(rawAlias) {
|
|
723
784
|
const alias = cleanText(rawAlias);
|
|
@@ -755,7 +816,7 @@ class PrismKoishiService {
|
|
|
755
816
|
/* ---------------------------- helpers ---------------------------------- */
|
|
756
817
|
async power(sender, deviceRef, state, systemOverride = false) {
|
|
757
818
|
const operation = state === "on" ? "启动" : "关闭";
|
|
758
|
-
const staffOverride = systemOverride || this.config.powerCommandsAdminOnly === true;
|
|
819
|
+
const staffOverride = systemOverride || (state === "off" && this.config.powerCommandsAdminOnly === true);
|
|
759
820
|
if (!systemOverride && staffOverride && !(this.config.staffUserIds ?? []).includes(sender.id)) {
|
|
760
821
|
return `${operation}失败,权限不足`;
|
|
761
822
|
}
|
|
@@ -766,8 +827,10 @@ class PrismKoishiService {
|
|
|
766
827
|
payload: { state },
|
|
767
828
|
}, staffOverride ? { staffOverride: true } : undefined);
|
|
768
829
|
const failure = this.getCommandFailureMessage(result);
|
|
769
|
-
if (failure)
|
|
770
|
-
|
|
830
|
+
if (failure) {
|
|
831
|
+
this.logDeviceCommandFailure(result);
|
|
832
|
+
return `${operation}失败,${deviceCommandFailureReason(result)}`;
|
|
833
|
+
}
|
|
771
834
|
const deviceLabel = result.action.payload.deviceLabel;
|
|
772
835
|
return state === "on" ? `✅ ${deviceLabel} 启动成功` : `🛑 ${deviceLabel} 关闭成功`;
|
|
773
836
|
}
|
|
@@ -816,10 +879,10 @@ class PrismKoishiService {
|
|
|
816
879
|
const musicLabel = this.config.loginSessionLabel?.trim() || "音游区间";
|
|
817
880
|
for (const player of players.values()) {
|
|
818
881
|
player.displayName = await this.displayNameForPlayer(player);
|
|
819
|
-
const nonMusic = player.sessions.filter((session) => Boolean(session.label) && session.label !== musicLabel);
|
|
882
|
+
const nonMusic = player.sessions.filter((session) => Boolean(session.label) && session.label !== "entry" && session.label !== musicLabel);
|
|
820
883
|
const source = nonMusic.length > 0 ? nonMusic : player.sessions;
|
|
821
884
|
const selected = source.reduce((latest, session) => !latest || sessionStartedAt(session) > sessionStartedAt(latest) ? session : latest, undefined);
|
|
822
|
-
const label = selected?.label || musicLabel;
|
|
885
|
+
const label = selected?.label === "entry" ? musicLabel : selected?.label || musicLabel;
|
|
823
886
|
let group = groupByLabel.get(label);
|
|
824
887
|
if (!group) {
|
|
825
888
|
group = { label, table: tableByLabel.get(label), players: [] };
|
|
@@ -917,7 +980,7 @@ class PrismKoishiService {
|
|
|
917
980
|
}
|
|
918
981
|
hasEntrySession(playerId, sessions) {
|
|
919
982
|
const label = this.config.loginSessionLabel?.trim();
|
|
920
|
-
return sessions.some((session) => session.playerId === playerId && (label ? session.label === label : true));
|
|
983
|
+
return sessions.some((session) => session.playerId === playerId && (session.label === "entry" || (label ? session.label === label : true)));
|
|
921
984
|
}
|
|
922
985
|
identity(sender) {
|
|
923
986
|
return {
|
|
@@ -1002,7 +1065,7 @@ class PrismKoishiService {
|
|
|
1002
1065
|
lines.push(`⏰ 游玩时间:${formatHM(overallStart)}–${formatHM(overallEnd)}`);
|
|
1003
1066
|
}
|
|
1004
1067
|
for (const sPrev of sessionPreviews) {
|
|
1005
|
-
const label = sPrev?.label || "计时区间";
|
|
1068
|
+
const label = sPrev?.label === "entry" ? this.config.loginSessionLabel?.trim() || "音游区间" : sPrev?.label || "计时区间";
|
|
1006
1069
|
const startDt = parseDateTime(sPrev?.startedAt);
|
|
1007
1070
|
const endDt = sessionDisplayEnd(sPrev, previewedAt);
|
|
1008
1071
|
const status = sPrev?.status ?? "active";
|
|
@@ -1080,6 +1143,9 @@ class PrismKoishiService {
|
|
|
1080
1143
|
handleCommandError(error) {
|
|
1081
1144
|
this.logCommandError(error);
|
|
1082
1145
|
if (error instanceof PrismBotClientError) {
|
|
1146
|
+
if (error.code?.startsWith("LOCATION_") && this.config.shopCode && this.config.baseUrl) {
|
|
1147
|
+
return `请在网页完成到店校验:${this.config.baseUrl.replace(/\/+$/, "")}/t/${encodeURIComponent(this.config.shopCode)}`;
|
|
1148
|
+
}
|
|
1083
1149
|
return humanReadableBotError(error);
|
|
1084
1150
|
}
|
|
1085
1151
|
return genericCommandFailure();
|
|
@@ -1089,6 +1155,10 @@ class PrismKoishiService {
|
|
|
1089
1155
|
? (error.originalError ?? error)
|
|
1090
1156
|
: error);
|
|
1091
1157
|
}
|
|
1158
|
+
logDeviceCommandFailure(result) {
|
|
1159
|
+
const action = result?.action;
|
|
1160
|
+
this.logger?.warn("PRiSM device command failed", action?.payload?.executorFailure ?? action);
|
|
1161
|
+
}
|
|
1092
1162
|
}
|
|
1093
1163
|
function humanReadableBotError(error) {
|
|
1094
1164
|
if (error.code === "DUPLICATE_SESSION_LABEL") {
|
|
@@ -1133,6 +1203,33 @@ function powerFailureReason(error) {
|
|
|
1133
1203
|
}
|
|
1134
1204
|
return "请稍后再试";
|
|
1135
1205
|
}
|
|
1206
|
+
function deviceActionFailureReason(error) {
|
|
1207
|
+
if (!(error instanceof PrismBotClientError))
|
|
1208
|
+
return "请稍后再试";
|
|
1209
|
+
if (error.code === "DEVICE_COMMAND_REQUIRES_ACTIVE_SESSION")
|
|
1210
|
+
return "玩家未入场";
|
|
1211
|
+
if (error.code === "DEVICE_NOT_FOUND")
|
|
1212
|
+
return "设备不存在";
|
|
1213
|
+
if (error.code === "SCAN_IDENTITY_NOT_BOUND_TO_PLAYER")
|
|
1214
|
+
return "玩家未绑定 Aime 卡";
|
|
1215
|
+
if (error.code === "COIN_COMMAND_COOLDOWN_ACTIVE")
|
|
1216
|
+
return "投币冷却中,请稍后再试";
|
|
1217
|
+
return "请稍后再试";
|
|
1218
|
+
}
|
|
1219
|
+
function deviceCommandFailureReason(result) {
|
|
1220
|
+
const action = result?.action;
|
|
1221
|
+
if (!action || (action.status !== "expired" && action.status !== "rejected"))
|
|
1222
|
+
return null;
|
|
1223
|
+
const message = cleanText(action.payload?.executorFailure?.message);
|
|
1224
|
+
if (message.includes("没有在线客户端"))
|
|
1225
|
+
return "设备未连接";
|
|
1226
|
+
if (message.includes("设备配置不存在"))
|
|
1227
|
+
return "设备未配置";
|
|
1228
|
+
return "请稍后再试";
|
|
1229
|
+
}
|
|
1230
|
+
function deviceCommandLabel(result) {
|
|
1231
|
+
return cleanText(result?.action?.payload?.deviceLabel);
|
|
1232
|
+
}
|
|
1136
1233
|
function genericCommandFailure() {
|
|
1137
1234
|
return "操作失败,请稍后再试。";
|
|
1138
1235
|
}
|
|
@@ -1191,9 +1288,9 @@ function sessionStartedAt(session) {
|
|
|
1191
1288
|
const value = Date.parse(session.startedAt ?? "");
|
|
1192
1289
|
return Number.isFinite(value) ? value : 0;
|
|
1193
1290
|
}
|
|
1194
|
-
function formatPlayerGroups(groups, tableSize) {
|
|
1291
|
+
function formatPlayerGroups(groups, tableSize, totalPlayers) {
|
|
1195
1292
|
const populatedGroups = groups.groups.filter((group) => group.players.length > 0);
|
|
1196
|
-
const total = new Set(populatedGroups.flatMap((group) => group.players.map((player) => player.playerId))).size;
|
|
1293
|
+
const total = totalPlayers ?? new Set(populatedGroups.flatMap((group) => group.players.map((player) => player.playerId))).size;
|
|
1197
1294
|
if (total === 0)
|
|
1198
1295
|
return "🫥 窝里目前没有玩家呢";
|
|
1199
1296
|
const lines = [`[总计 ${total} 人]`];
|