koishi-plugin-prism 0.1.40 → 0.1.41
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 +29 -12
- package/lib/display-time.d.ts +10 -0
- package/lib/display-time.js +36 -0
- package/lib/index.d.ts +7 -3
- package/lib/index.js +116 -140
- 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>`、`/上桌 <桌号>`、自动识别当前桌位的 `/下桌`,以及用于查看桌名、别名和状态的 `/麻将列表`。`上桌` 仅允许已通过 `login`/`入场`
|
|
11
|
+
* 🀄 **麻将桌位集成**:包含 `/mahjong <tableId>`、`/上桌 <桌号>`、自动识别当前桌位的 `/下桌`,以及用于查看桌名、别名和状态的 `/麻将列表`。`上桌` 仅允许已通过 `login`/`入场` 开启默认入场会话的玩家使用。 Bot 现在把普通入场标记为 `entry: true`,麻将座位计费标记为 `entry: false`;配套服务端必须支持这两个字段,否则有可能把同规则的麻将会话折叠成入场会话。支持在桌位未满但已开局时进行中途补位(直接开始计费上桌),且玩家下桌时会自动显示剩余游玩人数。`list` 按 session 标签分组:有非音乐游戏 session 的玩家归入最新的非音乐标签,纯音乐玩家归入音乐标签;麻将桌额外显示当前人数和容量。已开局桌位会从后端活跃 session 自动恢复,未满桌候座仍由机器人进程暂存,重启后不会保留。
|
|
12
12
|
* 🔌 **硬件设备状态与电源管理**:可直接在聊天中查看设备状态(`/show`)、远程开启/关闭电源(`/on`、`/off`)、远程投币(`/coin`)和模拟刷卡(`/scan`)。
|
|
13
13
|
* 🎟️ **礼物兑换码**:使用 `/redeem <code>` 兑换系统发放的福利礼包。
|
|
14
14
|
* 🛠️ **管理员快捷指令**:允许管理员为指定平台用户增加或扣除余额,并覆盖结账金额后立即结账。
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
| `baseUrl` | `string` | - | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
|
|
25
25
|
| `shopCode` | `string` | - | 统一平台的店铺公开编号;单店兼容部署留空。 |
|
|
26
26
|
| `integrationToken` | `string` | - | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
|
|
27
|
-
| `provider` | `string` | `"qq"` | 当前绑定的账号提供商平台名称(如 `"qq"`,`"discord"`)。 |
|
|
28
27
|
| `autoRegister` | `boolean` | `true` | 当玩家未注册时,是否在首次操作(如入场/查钱包)时自动在 PRiSM 中创建新玩家。 |
|
|
29
28
|
| `loginPricingConfigIds` | `string[]` | `[]` | 默认入场计费规则 ID 列表。 |
|
|
30
29
|
| `loginSessionLabel` | `string` | `"音游区间"` | 默认入场会话的标签文本。后端会按该标签对同一玩家的活跃会话去重,重复入场会被拒绝并提示。留空则不启用去重。 |
|
|
@@ -33,16 +32,20 @@
|
|
|
33
32
|
| `currencyName` | `string` | `"金币"` | 账户货币在显示时的自定义单位名称。 |
|
|
34
33
|
| `resolveDisplayName` | `function` | - | 可选。自定义用于获取群内昵称作为玩家注册名的异步逻辑。 |
|
|
35
34
|
| `enableStaffCommands` | `boolean` | `false` | 是否开启管理员快捷指令。 |
|
|
36
|
-
| `staffUserIds` | `string[]` | `[]` |
|
|
35
|
+
| `staffUserIds` | `string[]` | `[]` | 允许执行管理员快捷指令的平台身份(如 `onebot:114514`、`telegram:114514`)白名单。空列表不授予目标用户操作权限。 |
|
|
37
36
|
| `powerCommandsAdminOnly` | `boolean` | `false` | 关机是否仅允许 `staffUserIds` 中的管理员使用。`/on` 始终只允许已入场玩家使用。 |
|
|
38
|
-
| `
|
|
37
|
+
| `playerCommands` | `"all" \| "readonly"` | `"all"` | 玩家可用的命令。`readonly` 时玩家只能绑定身份(`bind`)、查询(`wallet`、`billing`、`history`、`items`、`list`、`show`、`麻将列表`、`versions`、`api测速`)和兑换(`redeem`);入场、结账、上下桌和设备操作(`login`/`入场`、`logout`、`mahjong`/`上桌`/`下桌`、`lock`、`on`、`off`、`coin`、`scan`)只有 `staffUserIds` 中的管理员能用,包括替其他玩家操作。适合让 Bot 只负责身份绑定与查询、入场结账都在网页或 App Clip 里完成的店。 |
|
|
38
|
+
| `readOnlyNotice` | `string` | `请扫描设备上的二维码或碰 NFC,在网页或 App Clip 里操作` | 只读模式下玩家使用受限命令时 Bot 的回复。 |
|
|
39
|
+
| `logoutNotifyUserIds` | `string[]` | `[]` | 结账成功后额外私聊完整账单的平台身份。通知收件人为该列表与 `staffUserIds` 的去重并集。 |
|
|
39
40
|
| `mahjongTableConfigs` | `object[]` | `[]` | 推荐的结构化麻将桌列表。每项填写显示名称、命令别名列表与计费方案 ID 列表。显示名称同时作为内部桌位锚点与 session 标签。 |
|
|
40
41
|
|
|
41
42
|
### 统一平台
|
|
42
43
|
|
|
43
44
|
配置 `baseUrl`、`shopCode` 和本店的 Integration 令牌后,插件调用 `/api/v1/shops/:shopCode/integration`;单店兼容部署调用 `/api/v1/integration`。
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
玩家在网页取得验证码后,向任意已接入的店铺 Bot 发送 `bind 验证码`(旧命令 `prism.bind` 仍可用)。店家可以在 PRiSM「设置 → Bot 与接入」改写玩家看到的绑定提示。所有命令从消息的 `session.platform` 和 `session.userId` 读取身份,发送 `{ code, provider, subject }`,不接受手填或代填身份;`provider` 配置已移除。例如同一实例的 OneBot 和 Telegram 消息分别使用 `onebot:114514` 和 `telegram:114514`。群/私聊过滤交给 Koishi。网页账号可以跨店使用,平台验证、玩家和余额按店铺隔离;同一网页账号追加平台绑定时复用同一个玩家。
|
|
47
|
+
|
|
48
|
+
店主在 React「设置」控制是否要求平台身份,任意一个验证平台即可满足。默认开启;关闭后登录网页账号即可入场。已有标识不会自动改名,需店主在「平台身份转换」输入原标识与目标标识,预览冲突后主动执行,例如 `qq → onebot`。余额和账单不变,原标识若未转换,OneBot 新身份不会自动认领它。
|
|
46
49
|
|
|
47
50
|
统一平台以店铺的入场规则和注册开关为准。Web 与 Bot 普通入场共享去重;显式的麻将规则继续使用桌位流程。店铺启用入场、出场或机器操作定位时,对应 Bot 操作会返回本店网页地址。玩家余额不足时结账失败并继续计时。
|
|
48
51
|
|
|
@@ -63,7 +66,7 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
63
66
|
## 📝 机器人指令列表
|
|
64
67
|
|
|
65
68
|
### 玩家指令
|
|
66
|
-
* `
|
|
69
|
+
* `bind <验证码>` - 把网页登录账号绑定到当前平台身份(旧命令 `prism.bind` 仍可用)。玩家第一次绑定时是否自动建档由店铺设置决定,原来的 `register` 命令已移除。
|
|
67
70
|
* `login` / `入场` - 开启当前玩家的计费场次。
|
|
68
71
|
* `logout` - 结算当前玩家的计费场次。
|
|
69
72
|
玩家在未产生任何费用时退场,机器人会简洁显示“本次未产生费用”和当前余额;存在收费或优惠明细时仍显示完整结算账单。负单价 session 会在区间明细中保留真实的负数计费贡献,只有后端汇总全部 session 后的最终应付金额会限制为不低于 `0`。
|
|
@@ -71,7 +74,7 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
71
74
|
方案内区间封顶直接计入对应计时费用;全局封顶按后端返回的结构化日期和时段逐条列出,不合并、不截断,并直接形成计费总价,不作为优惠。只作用于整次结账的资产优惠直接列在计费总价下方,不显示额外标题或 emoji,也不会误归属到最后一个 session。
|
|
72
75
|
在玩家退场或管理员覆盖结账成功后,机器人会向 `staffUserIds` 与 `logoutNotifyUserIds` 中的用户私聊同一份账单,账单会明确显示结账玩家身份。
|
|
73
76
|
同一玩家在前一次退场结账尚未完成时重复发送 `/logout` 或 `/退场`,机器人会复用同一次结账请求与账单,避免重复扣款。
|
|
74
|
-
|
|
77
|
+
账单和管理员代操作回执均使用“平台昵称(平台标识:身份值)”称呼玩家;平台暂时无法提供昵称时显示“未知昵称(平台标识:身份值)”,不会显示内部玩家 ID。
|
|
75
78
|
管理员 `/add` 增加免费余额;`/del` 按结账相同的顺序从可用免费余额、再从付费余额扣除,余额不足时会返回余额不足提示。
|
|
76
79
|
* `billing` - 预览当前玩家本场计费的消费费用。
|
|
77
80
|
* `wallet` - 查看当前玩家的钱包余额。
|
|
@@ -118,6 +121,10 @@ Bot 版本直接读取本 npm 包的 `package.json`,后端版本读取无需
|
|
|
118
121
|
bun run test
|
|
119
122
|
```
|
|
120
123
|
|
|
124
|
+
### 提交检查
|
|
125
|
+
|
|
126
|
+
`main` 和 PR 均运行独立的 GitHub Actions `checks`:Bun 类型检查、Bot 命令回归测试与 TypeScript 编译。麻将上桌/下桌与多平台退场去重使用模拟适配器测试,不对线上店铺写入。代码合并后仍需发布新 npm 版本,并确认运行中的 Koishi 实例已经升级;只有合并源码不会自动更新 Bot。
|
|
127
|
+
|
|
121
128
|
### CI 自动发布
|
|
122
129
|
|
|
123
130
|
发布使用 GitHub Actions 的 npm Trusted Publishing。修改版本后推送带 `v` 前缀且与 `package.json` 一致的标签即可自动测试、构建并发布:
|
|
@@ -133,14 +140,24 @@ git push origin main --follow-tags
|
|
|
133
140
|
|
|
134
141
|
[MIT License](LICENSE)
|
|
135
142
|
|
|
136
|
-
统一平台支持
|
|
143
|
+
统一平台支持 平台身份绑定、查人以及原有计费/设备命令。持有有效店铺 Integration 令牌的 Bot 不受玩家定位和扫码入口限制;玩家身份、入场要求、投币冷却及插件员工权限仍保留。查人合并后端持久化麻将名单和旧 Bot 桌位记录。普通入场的 `entry` 标签兼容旧 `loginSessionLabel`,不会误拒绝已入场玩家上桌。
|
|
137
144
|
|
|
138
|
-
2026-09-13 使用 Koishi 4.18.11 实际命令解析和本地 HTTP,对已有 MMW prism-next 快照运行旧新版对比:18 名在店玩家的账单/钱包/资产/历史与查人共 73
|
|
145
|
+
2026-09-13 使用 Koishi 4.18.11 实际命令解析和本地 HTTP,对已有 MMW prism-next 快照运行旧新版对比:18 名在店玩家的账单/钱包/资产/历史与查人共 73 次查询文本一致;另测试入退场、四人麻将、余额调整、兑换、开关机、门锁、投币冷却、重复刷卡、离线和权限拒绝。平台消息本地注入,硬件使用本地模拟服务,不代表真实聊天平台投递或物理硬件验收。
|
|
139
146
|
|
|
140
|
-
###
|
|
147
|
+
### 平台身份绑定与查人验收
|
|
141
148
|
|
|
142
|
-
|
|
149
|
+
绑定支持 Koishi 提供的各适配器标识,身份值保持字符串,不限定数字格式。员工白名单和私聊通知目标使用 `平台标识:身份值`,相同号码的其他平台不会继承权限或通知;旧未带平台的配置只兼容 OneBot。管理员代操作使用目标平台标识,禁止通过当前适配器误操作另一个平台。`/list` 只用当前平台的身份查询昵称,缺失时使用后台名称。源码和 npm 发行包需要分别核对版本。
|
|
143
150
|
|
|
144
151
|
### 0.1.39
|
|
145
152
|
|
|
146
|
-
支持统一平台店铺 API
|
|
153
|
+
支持统一平台店铺 API、平台身份 绑定和麻将查人统计;兼容新版入场标签,修复已入场玩家无法通过 Bot 上桌的问题。
|
|
154
|
+
|
|
155
|
+
### 0.1.41
|
|
156
|
+
|
|
157
|
+
移除手填平台标识;使用消息适配器身份完成绑定、计费和设备指令。支持同实例多适配器,绑定采用 `provider:subject`,员工权限和账单通知按平台隔离。需配套新版 PRiSM 的 `platform-binding` 接口;旧身份由店主主动转换。
|
|
158
|
+
|
|
159
|
+
绑定命令改为 `bind <验证码>`(`prism.bind` 保留为同义命令),移除 `register`(第一次绑定时是否建档由店铺设置决定)。新增 `playerCommands`:设为 `readonly` 时玩家只能绑定、查询和兑换,入场、结账、上下桌和设备操作仅 `staffUserIds` 中的管理员可用,玩家收到 `readOnlyNotice`。
|
|
160
|
+
|
|
161
|
+
## 时间展示
|
|
162
|
+
|
|
163
|
+
账单、历史与资产到期使用 API 时间字符串所带的店铺偏移,例如 `2026-10-03T10:08:00+08:00`,不依赖 Bot 服务器时区,也不手工加八小时。账单注明 UTC 偏移;时间排序及游玩时长按绝对时间计算,兼容旧 `Z` 时间戳。网页/Swift 的个人时间可按玩家设备时区展示,因此跨地区使用时显示时钟不同,但时长和金额一致。
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Parsing preserves the absolute instant; formatting preserves the API's explicit offset. */
|
|
2
|
+
export declare function parseDateTime(value: unknown): Date | null;
|
|
3
|
+
export declare function apiOffsetLabel(value: unknown): string;
|
|
4
|
+
export declare function dateParts(value: unknown): {
|
|
5
|
+
date: string;
|
|
6
|
+
time: string;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare const formatHM: (value: unknown) => string;
|
|
9
|
+
export declare const formatMD: (value: unknown) => string;
|
|
10
|
+
export declare function formatDateTime(value: unknown): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatMD = exports.formatHM = void 0;
|
|
4
|
+
exports.parseDateTime = parseDateTime;
|
|
5
|
+
exports.apiOffsetLabel = apiOffsetLabel;
|
|
6
|
+
exports.dateParts = dateParts;
|
|
7
|
+
exports.formatDateTime = formatDateTime;
|
|
8
|
+
/** Parsing preserves the absolute instant; formatting preserves the API's explicit offset. */
|
|
9
|
+
function parseDateTime(value) {
|
|
10
|
+
if (value instanceof Date)
|
|
11
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
12
|
+
if (typeof value !== "string" || !value.trim())
|
|
13
|
+
return null;
|
|
14
|
+
const text = value.trim();
|
|
15
|
+
const normalized = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?$/.test(text) ? `${text.replace(" ", "T")}Z` : text;
|
|
16
|
+
const date = new Date(normalized);
|
|
17
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
18
|
+
}
|
|
19
|
+
function apiOffsetLabel(value) {
|
|
20
|
+
return `UTC${typeof value === "string" ? value.match(/[+-]\d{2}:\d{2}$/)?.[0] ?? "+00:00" : "+00:00"}`;
|
|
21
|
+
}
|
|
22
|
+
function dateParts(value) {
|
|
23
|
+
const date = parseDateTime(value);
|
|
24
|
+
if (!date)
|
|
25
|
+
return null;
|
|
26
|
+
const text = typeof value === "string" && /[+-]\d{2}:\d{2}$/.test(value) ? value : date.toISOString();
|
|
27
|
+
return { date: text.slice(0, 10), time: text.slice(11, 19) };
|
|
28
|
+
}
|
|
29
|
+
const formatHM = (value) => dateParts(value)?.time.slice(0, 5) ?? "—";
|
|
30
|
+
exports.formatHM = formatHM;
|
|
31
|
+
const formatMD = (value) => dateParts(value)?.date.slice(5) ?? "—";
|
|
32
|
+
exports.formatMD = formatMD;
|
|
33
|
+
function formatDateTime(value) {
|
|
34
|
+
const parts = dateParts(value);
|
|
35
|
+
return parts ? `${parts.date.replaceAll("-", "/")} ${parts.time}(${apiOffsetLabel(value)})` : value ? "时间无效" : "永不过期";
|
|
36
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -18,8 +18,10 @@ export type MahjongTableConfig = {
|
|
|
18
18
|
};
|
|
19
19
|
export type MahjongTableConfigInput = Omit<MahjongTableConfig, "tableId">;
|
|
20
20
|
export type PrismKoishiPluginConfig = {
|
|
21
|
-
provider: string;
|
|
22
21
|
autoRegister: boolean;
|
|
22
|
+
/** "readonly" leaves players binding, lookups and redeeming; staff keep every command. */
|
|
23
|
+
playerCommands?: "all" | "readonly";
|
|
24
|
+
readOnlyNotice?: string;
|
|
23
25
|
loginPricingConfigIds?: string[];
|
|
24
26
|
loginSessionLabel?: string;
|
|
25
27
|
defaultDoorDeviceId: string;
|
|
@@ -34,11 +36,11 @@ export type PrismKoishiPluginConfig = {
|
|
|
34
36
|
powerOffInterval?: number;
|
|
35
37
|
/**
|
|
36
38
|
* Used by /list to resolve player display names from the chat platform.
|
|
37
|
-
* For Koishi, this
|
|
39
|
+
* For Koishi, this maps an adapter subject and provider to a nickname (e.g. the
|
|
38
40
|
* member list of the current group). If not provided, the plugin will fall
|
|
39
41
|
* back to `playerDisplayName` from the backend.
|
|
40
42
|
*/
|
|
41
|
-
resolveDisplayName?: (subject: string) => Promise<string | null | undefined> | string | null | undefined;
|
|
43
|
+
resolveDisplayName?: (subject: string, provider: string) => Promise<string | null | undefined> | string | null | undefined;
|
|
42
44
|
/** Get a stable current ISO timestamp; mainly for tests. */
|
|
43
45
|
now?: () => Date;
|
|
44
46
|
shopCode?: string;
|
|
@@ -70,6 +72,7 @@ export type KoishiActionContext = {
|
|
|
70
72
|
senderName?: string;
|
|
71
73
|
username?: string;
|
|
72
74
|
bot?: {
|
|
75
|
+
platform?: string;
|
|
73
76
|
getUser?(id: string): Promise<{
|
|
74
77
|
name?: string;
|
|
75
78
|
}>;
|
|
@@ -81,6 +84,7 @@ export declare function applyPrismKoishiPlugin(ctx: KoishiLikeContext, config: P
|
|
|
81
84
|
export type Sender = {
|
|
82
85
|
id: string;
|
|
83
86
|
name: string;
|
|
87
|
+
provider: string;
|
|
84
88
|
};
|
|
85
89
|
export declare function humanReadableBotError(error: PrismBotClientError): string;
|
|
86
90
|
export declare function resolveMahjongTableConfigs(structured: readonly MahjongTableConfigInput[]): Map<string, MahjongTableConfig>;
|
package/lib/index.js
CHANGED
|
@@ -8,12 +8,12 @@ exports.apply = apply;
|
|
|
8
8
|
exports.applyPrismKoishiPlugin = applyPrismKoishiPlugin;
|
|
9
9
|
exports.humanReadableBotError = humanReadableBotError;
|
|
10
10
|
exports.resolveMahjongTableConfigs = resolveMahjongTableConfigs;
|
|
11
|
+
const display_time_js_1 = require("./display-time.js");
|
|
11
12
|
const koishi_1 = require("koishi");
|
|
12
13
|
const package_json_1 = __importDefault(require("../package.json"));
|
|
13
14
|
exports.name = "prism";
|
|
14
15
|
exports.version = package_json_1.default.version;
|
|
15
16
|
exports.Config = koishi_1.Schema.object({
|
|
16
|
-
provider: koishi_1.Schema.string().required().description("平台提供商 (如 qq)"),
|
|
17
17
|
autoRegister: koishi_1.Schema.boolean().default(true).description("是否自动注册"),
|
|
18
18
|
shopCode: koishi_1.Schema.string().description("统一平台店铺编号(单店兼容模式留空)"),
|
|
19
19
|
baseUrl: koishi_1.Schema.string().description("PRiSM 后端 API Base URL"),
|
|
@@ -24,9 +24,14 @@ exports.Config = koishi_1.Schema.object({
|
|
|
24
24
|
loginPricingConfigIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("默认入场绑定的计费策略ID"),
|
|
25
25
|
loginSessionLabel: koishi_1.Schema.string().default("音游区间").description("默认入场场次标签 (防重复入场)"),
|
|
26
26
|
enableStaffCommands: koishi_1.Schema.boolean().default(false).description("是否启用管理员指令"),
|
|
27
|
-
staffUserIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("
|
|
27
|
+
staffUserIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("允许执行管理员指令的平台身份列表(如 onebot:123456、telegram:123456)"),
|
|
28
28
|
powerCommandsAdminOnly: koishi_1.Schema.boolean().default(false).description("关机是否仅允许管理员使用;开机始终仅已入场玩家可用"),
|
|
29
|
-
|
|
29
|
+
playerCommands: koishi_1.Schema.union([
|
|
30
|
+
koishi_1.Schema.const("all").description("全部:玩家可以在 Bot 里入场、结账、上下桌和操作设备"),
|
|
31
|
+
koishi_1.Schema.const("readonly").description("只读:玩家只能绑定身份、查询和兑换;入场、结账、上下桌和设备操作仅管理员可用"),
|
|
32
|
+
]).default("all").description("玩家可用的命令"),
|
|
33
|
+
readOnlyNotice: koishi_1.Schema.string().default("请扫描设备上的二维码或碰 NFC,在网页或 App Clip 里操作").description("只读模式下玩家使用受限命令时的回复"),
|
|
34
|
+
logoutNotifyUserIds: koishi_1.Schema.array(koishi_1.Schema.string()).default([]).description("结账账单私聊通知的平台身份列表(如 onebot:123456)"),
|
|
30
35
|
powerOffInterval: koishi_1.Schema.number().default(0).description("无人自动关机等待秒数 (0为禁用)"),
|
|
31
36
|
mahjongTableConfigs: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
32
37
|
displayName: koishi_1.Schema.string().required().description("桌位显示名称和 session 标签"),
|
|
@@ -53,7 +58,6 @@ class PrismBotClientError extends Error {
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
exports.PrismBotClientError = PrismBotClientError;
|
|
56
|
-
const LOCAL_TZ_OFFSET_MINUTES = 8 * 60;
|
|
57
61
|
const USAGE = {
|
|
58
62
|
mahjong_join: "/上桌 <桌号>",
|
|
59
63
|
mahjong_leave: "/下桌",
|
|
@@ -79,28 +83,35 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
79
83
|
return context.session?.messageId ? `${(0, koishi_1.h)("quote", { id: context.session.messageId })}${message}` : message;
|
|
80
84
|
}
|
|
81
85
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return "请使用 QQ 身份发送验证码";
|
|
85
|
-
if (!/^[1-9]\d{4,19}$/.test(context.session.userId ?? ""))
|
|
86
|
-
return "无法获取发送人的 QQ 号";
|
|
86
|
+
const bind = wrap(async (context, code) => {
|
|
87
|
+
const sender = await service.sender(context);
|
|
87
88
|
if (!config.shopCode || !config.baseUrl || !config.integrationToken)
|
|
88
89
|
return "请店家配置统一平台店铺编号与 Bot 凭据";
|
|
89
|
-
const response = await fetch(`${config.baseUrl.replace(/\/+$/, "")}/api/v1/shops/${encodeURIComponent(config.shopCode)}/integration/
|
|
90
|
+
const response = await fetch(`${config.baseUrl.replace(/\/+$/, "")}/api/v1/shops/${encodeURIComponent(config.shopCode)}/integration/platform-binding/confirm`, {
|
|
90
91
|
method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${config.integrationToken}` },
|
|
91
|
-
body: JSON.stringify({ code,
|
|
92
|
+
body: JSON.stringify({ code, provider: sender.provider, subject: sender.id }),
|
|
92
93
|
});
|
|
93
94
|
const body = await response.json();
|
|
94
95
|
return response.ok ? "绑定成功,请返回网页继续操作" : body.error?.message ?? "绑定失败,请重新生成验证码";
|
|
95
|
-
})
|
|
96
|
-
ctx.command("
|
|
97
|
-
|
|
98
|
-
ctx.command("
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
});
|
|
97
|
+
ctx.command("bind <code:string>", "绑定网页登录账号到当前平台身份").action(bind);
|
|
98
|
+
// Instructions already handed to players may still say prism.bind.
|
|
99
|
+
ctx.command("prism.bind <code:string>", "绑定网页登录账号到当前平台身份(旧命令,同 bind)").action(bind);
|
|
100
|
+
// In read-only mode a player may look things up and redeem, but anything that
|
|
101
|
+
// starts billing, settles a bill or drives a device is left to staff.
|
|
102
|
+
const effect = (handler) => wrap(async (context, ...args) => {
|
|
103
|
+
if (config.playerCommands === "readonly" && !matchesPlatformIdentity(config.staffUserIds ?? [], await service.sender(context))) {
|
|
104
|
+
return config.readOnlyNotice || "请扫描设备上的二维码或碰 NFC,在网页或 App Clip 里操作";
|
|
105
|
+
}
|
|
106
|
+
return handler(context, ...args);
|
|
107
|
+
});
|
|
108
|
+
ctx.command("login [target:user]", "开启玩家计费场次").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
109
|
+
ctx.command("入场 [target:user]", "入场").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
110
|
+
ctx.command("mahjong <tableId>", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
111
|
+
ctx.command("上桌 [tableId]", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
112
|
+
ctx.command("下桌", "离开当前所在麻将桌").action(effect(async (context) => service.mahjongLeave(await service.sender(context))));
|
|
102
113
|
ctx.command("麻将列表", "查看麻将机状态与别名").action(wrap(async () => service.listMahjongTables()));
|
|
103
|
-
ctx.command("logout [target:user]", "结算玩家计费场次").action(
|
|
114
|
+
ctx.command("logout [target:user]", "结算玩家计费场次").action(effect(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.logout(sender, context.session?.bot), context.session?.bot)));
|
|
104
115
|
ctx.command("billing [target:user]", "预览玩家结账费用").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.billing(sender), context.session?.bot)));
|
|
105
116
|
ctx.command("wallet [target:user]", "查看玩家钱包").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.wallet(sender), context.session?.bot)));
|
|
106
117
|
ctx.command("api测速 [count:number]", "测试 Bot 到 PRiSM API 的钱包查询延迟").action(wrap(async (context, count) => service.benchmarkApi(await service.sender(context), count)));
|
|
@@ -109,11 +120,11 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
109
120
|
ctx.command("list", "查看当前在线玩家列表").action(wrap(async (context) => service.listActiveSessions(await service.sender(context))));
|
|
110
121
|
ctx.command("show [deviceId]", "查看设备电源状态").action(wrap(async (context, deviceId) => service.listDeviceStates(deviceId)));
|
|
111
122
|
ctx.command("history [target:user]", "查看玩家历史").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.history(sender), context.session?.bot)));
|
|
112
|
-
ctx.command("lock", "向默认门锁设备发送开门指令").action(
|
|
113
|
-
ctx.command("on <deviceRef>", "请求启动指定设备电源").action(
|
|
114
|
-
ctx.command("off <deviceRef>", "请求关闭指定设备电源").action(
|
|
115
|
-
ctx.command("coin <deviceRef> [count]", "请求向指定设备投币").action(
|
|
116
|
-
ctx.command("scan <deviceRef>", "使用当前玩家绑定的 Aime 卡刷卡").action(
|
|
123
|
+
ctx.command("lock", "向默认门锁设备发送开门指令").action(effect(async (context) => service.lock(await service.sender(context))));
|
|
124
|
+
ctx.command("on <deviceRef>", "请求启动指定设备电源").action(effect(async (context, deviceRef) => service.powerOn(await service.sender(context), deviceRef)));
|
|
125
|
+
ctx.command("off <deviceRef>", "请求关闭指定设备电源").action(effect(async (context, deviceRef) => service.powerOff(await service.sender(context), deviceRef)));
|
|
126
|
+
ctx.command("coin <deviceRef> [count]", "请求向指定设备投币").action(effect(async (context, deviceRef, count) => service.coin(await service.sender(context), deviceRef, count)));
|
|
127
|
+
ctx.command("scan <deviceRef>", "使用当前玩家绑定的 Aime 卡刷卡").action(effect(async (context, deviceRef) => service.scan(await service.sender(context), deviceRef)));
|
|
117
128
|
ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(await service.sender(context), code)));
|
|
118
129
|
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)));
|
|
119
130
|
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)));
|
|
@@ -370,7 +381,10 @@ class PrismKoishiService {
|
|
|
370
381
|
}
|
|
371
382
|
}
|
|
372
383
|
async sender(context) {
|
|
373
|
-
const id = context.session?.
|
|
384
|
+
const id = cleanText(context.session?.userId);
|
|
385
|
+
const provider = cleanText(context.session?.platform || context.session?.bot?.platform).toLowerCase();
|
|
386
|
+
if (!id || !/^[a-z][a-z0-9_-]{0,63}$/.test(provider))
|
|
387
|
+
throw new PrismBotClientError("无法获取发送人的平台身份", "INVALID_PLATFORM_IDENTITY", 400, null);
|
|
374
388
|
let name = context.session?.username || context.session?.senderName || id;
|
|
375
389
|
try {
|
|
376
390
|
if (context.session?.bot?.getUser) {
|
|
@@ -381,7 +395,7 @@ class PrismKoishiService {
|
|
|
381
395
|
}
|
|
382
396
|
}
|
|
383
397
|
catch { }
|
|
384
|
-
return { id, name };
|
|
398
|
+
return { id, name, provider };
|
|
385
399
|
}
|
|
386
400
|
async register(sender) {
|
|
387
401
|
await this.client.resolveOrRegisterIdentity(this.identity(sender));
|
|
@@ -390,7 +404,7 @@ class PrismKoishiService {
|
|
|
390
404
|
async loginForTarget(actor, targetSubject, bot) {
|
|
391
405
|
return this.withTarget(actor, targetSubject, async (sender, isTargeted) => {
|
|
392
406
|
await this.client.startSessionByIdentity(this.identity(sender), this.loginSessionBody());
|
|
393
|
-
return isTargeted ? `✅ 已为用户 ${formatPlayerReference(sender
|
|
407
|
+
return isTargeted ? `✅ 已为用户 ${formatPlayerReference(sender)} 入场成功` : "✅ 入场成功";
|
|
394
408
|
}, bot);
|
|
395
409
|
}
|
|
396
410
|
async login(sender) {
|
|
@@ -410,7 +424,7 @@ class PrismKoishiService {
|
|
|
410
424
|
return "金额必须大于 0";
|
|
411
425
|
const isAddition = direction === 1;
|
|
412
426
|
await this.client.adjustWalletByIdentity(this.identity(sender), amount * direction, isAddition ? "Koishi 管理员增加余额" : "Koishi 管理员扣除余额");
|
|
413
|
-
return `✅ 已为用户 ${formatPlayerReference(sender
|
|
427
|
+
return `✅ 已为用户 ${formatPlayerReference(sender)}${isAddition ? "增加" : "扣除"} ${formatNumber(amount)} ${this.config.currencyName}`;
|
|
414
428
|
}, bot);
|
|
415
429
|
}
|
|
416
430
|
async overwriteTargetCheckout(actor, targetSubject, rawAmount, rawReason, bot) {
|
|
@@ -458,6 +472,7 @@ class PrismKoishiService {
|
|
|
458
472
|
const result = (await this.client.startSessionByIdentity(this.identity(sender), {
|
|
459
473
|
pricingConfigIds: tableConfig.pricingConfigIds,
|
|
460
474
|
label,
|
|
475
|
+
entry: false,
|
|
461
476
|
}));
|
|
462
477
|
const session = (result?.session ?? {});
|
|
463
478
|
const sessionId = String(session.id ?? "");
|
|
@@ -482,6 +497,7 @@ class PrismKoishiService {
|
|
|
482
497
|
const result = (await this.client.startSessionByIdentity(seat.identity, {
|
|
483
498
|
pricingConfigIds: tableConfig.pricingConfigIds,
|
|
484
499
|
label,
|
|
500
|
+
entry: false,
|
|
485
501
|
}));
|
|
486
502
|
const session = (result?.session ?? {});
|
|
487
503
|
const sessionId = String(session.id ?? "");
|
|
@@ -511,10 +527,12 @@ class PrismKoishiService {
|
|
|
511
527
|
const sessionId = state.activeSessions[playerId];
|
|
512
528
|
if (!sessionId)
|
|
513
529
|
return "你当前未在任何麻将桌上。";
|
|
530
|
+
// Do not show an available seat while the backend session is still running.
|
|
531
|
+
// Failed stop requests must preserve the table state for safe retry.
|
|
532
|
+
await this.client.stopSessionByIdentity(this.identity(sender), sessionId);
|
|
514
533
|
delete state.activeSessions[playerId];
|
|
515
534
|
const remainingCount = Object.keys(state.activeSessions).length;
|
|
516
535
|
const tableSize = this.config.mahjongTableSize ?? 4;
|
|
517
|
-
await this.client.stopSessionByIdentity(this.identity(sender), sessionId);
|
|
518
536
|
return `已离开 ${tableSubject},麻将计费已停止。当前还剩 ${remainingCount}/${tableSize} 人。`;
|
|
519
537
|
}
|
|
520
538
|
async listMahjongTables() {
|
|
@@ -542,17 +560,20 @@ class PrismKoishiService {
|
|
|
542
560
|
return this.formatCheckoutPreview(result, sender, "【结算账单】", true);
|
|
543
561
|
}
|
|
544
562
|
async logout(sender, bot) {
|
|
545
|
-
|
|
563
|
+
// A Koishi instance can receive identical userId values from different adapters.
|
|
564
|
+
// In-flight settlement coalescing must use the same composite identity as Bot RPC.
|
|
565
|
+
const key = `${sender.provider}:${sender.id}`;
|
|
566
|
+
const existing = this.logoutInFlight.get(key);
|
|
546
567
|
if (existing)
|
|
547
568
|
return existing;
|
|
548
569
|
const task = this.performLogout(sender, bot);
|
|
549
|
-
this.logoutInFlight.set(
|
|
570
|
+
this.logoutInFlight.set(key, task);
|
|
550
571
|
try {
|
|
551
572
|
return await task;
|
|
552
573
|
}
|
|
553
574
|
finally {
|
|
554
|
-
if (this.logoutInFlight.get(
|
|
555
|
-
this.logoutInFlight.delete(
|
|
575
|
+
if (this.logoutInFlight.get(key) === task)
|
|
576
|
+
this.logoutInFlight.delete(key);
|
|
556
577
|
}
|
|
557
578
|
}
|
|
558
579
|
async performLogout(sender, bot) {
|
|
@@ -605,10 +626,15 @@ class PrismKoishiService {
|
|
|
605
626
|
};
|
|
606
627
|
const receipt = await this.formatCheckoutPreview(synthetic, sender, title, false);
|
|
607
628
|
const recipients = [...new Set([...(this.config.staffUserIds ?? []), ...(this.config.logoutNotifyUserIds ?? [])])];
|
|
608
|
-
|
|
609
|
-
|
|
629
|
+
const channelIds = recipients.flatMap(identity => {
|
|
630
|
+
if (identity.startsWith(`${sender.provider}:`))
|
|
631
|
+
return [`private:${identity.slice(sender.provider.length + 1)}`];
|
|
632
|
+
if (sender.provider === "onebot" && (!identity.includes(":") || identity.startsWith("private:")))
|
|
633
|
+
return [identity.startsWith("private:") ? identity : `private:${identity}`];
|
|
634
|
+
return [];
|
|
635
|
+
});
|
|
636
|
+
if (channelIds.length > 0 && bot?.broadcast)
|
|
610
637
|
await bot.broadcast(channelIds, receipt);
|
|
611
|
-
}
|
|
612
638
|
return receipt;
|
|
613
639
|
}
|
|
614
640
|
async wallet(sender) {
|
|
@@ -763,7 +789,7 @@ class PrismKoishiService {
|
|
|
763
789
|
table,
|
|
764
790
|
]));
|
|
765
791
|
const players = groupSessionsByPlayer(sessions);
|
|
766
|
-
const groups = await this.buildPlayerGroups(players, tableByLabel);
|
|
792
|
+
const groups = await this.buildPlayerGroups(players, tableByLabel, sender.provider);
|
|
767
793
|
this.mergeWaitingSeats(groups);
|
|
768
794
|
const tables = result.mahjongTables;
|
|
769
795
|
if (!tables)
|
|
@@ -810,14 +836,14 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
810
836
|
const anyOn = states.some((d) => normalizeDeviceState(d.state) === "on");
|
|
811
837
|
if (!anyOn)
|
|
812
838
|
return;
|
|
813
|
-
const dummySender = { id: "system", name: "system" };
|
|
839
|
+
const dummySender = { id: "system", name: "system", provider: "system" };
|
|
814
840
|
await this.power(dummySender, "all", "off", true);
|
|
815
841
|
}
|
|
816
842
|
/* ---------------------------- helpers ---------------------------------- */
|
|
817
843
|
async power(sender, deviceRef, state, systemOverride = false) {
|
|
818
844
|
const operation = state === "on" ? "启动" : "关闭";
|
|
819
845
|
const staffOverride = systemOverride || (state === "off" && this.config.powerCommandsAdminOnly === true);
|
|
820
|
-
if (!systemOverride && staffOverride && !(this.config.staffUserIds ?? []
|
|
846
|
+
if (!systemOverride && staffOverride && !matchesPlatformIdentity(this.config.staffUserIds ?? [], sender)) {
|
|
821
847
|
return `${operation}失败,权限不足`;
|
|
822
848
|
}
|
|
823
849
|
try {
|
|
@@ -846,24 +872,24 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
846
872
|
}
|
|
847
873
|
return null;
|
|
848
874
|
}
|
|
849
|
-
async resolvePlatformName(subject) {
|
|
875
|
+
async resolvePlatformName(subject, provider) {
|
|
850
876
|
if (!this.config.resolveDisplayName)
|
|
851
877
|
return null;
|
|
852
878
|
try {
|
|
853
|
-
return (await this.config.resolveDisplayName(subject)) ?? null;
|
|
879
|
+
return (await this.config.resolveDisplayName(subject, provider)) ?? null;
|
|
854
880
|
}
|
|
855
881
|
catch {
|
|
856
882
|
return null;
|
|
857
883
|
}
|
|
858
884
|
}
|
|
859
|
-
async displayNameForPlayer(player) {
|
|
885
|
+
async displayNameForPlayer(player, provider) {
|
|
860
886
|
let identitySubject;
|
|
861
887
|
for (const session of player.sessions) {
|
|
862
|
-
const subject = findSubjectForSession(session,
|
|
888
|
+
const subject = findSubjectForSession(session, provider);
|
|
863
889
|
if (!subject)
|
|
864
890
|
continue;
|
|
865
891
|
identitySubject ??= subject;
|
|
866
|
-
const platformName = await this.resolvePlatformName(subject);
|
|
892
|
+
const platformName = await this.resolvePlatformName(subject, provider);
|
|
867
893
|
if (platformName)
|
|
868
894
|
return platformName;
|
|
869
895
|
}
|
|
@@ -873,12 +899,12 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
873
899
|
|| player.playerId
|
|
874
900
|
|| "未知玩家";
|
|
875
901
|
}
|
|
876
|
-
async buildPlayerGroups(players, tableByLabel) {
|
|
902
|
+
async buildPlayerGroups(players, tableByLabel, provider) {
|
|
877
903
|
const groups = { groups: [] };
|
|
878
904
|
const groupByLabel = new Map();
|
|
879
905
|
const musicLabel = this.config.loginSessionLabel?.trim() || "音游区间";
|
|
880
906
|
for (const player of players.values()) {
|
|
881
|
-
player.displayName = await this.displayNameForPlayer(player);
|
|
907
|
+
player.displayName = await this.displayNameForPlayer(player, provider);
|
|
882
908
|
const nonMusic = player.sessions.filter((session) => Boolean(session.label) && session.label !== "entry" && session.label !== musicLabel);
|
|
883
909
|
const source = nonMusic.length > 0 ? nonMusic : player.sessions;
|
|
884
910
|
const selected = source.reduce((latest, session) => !latest || sessionStartedAt(session) > sessionStartedAt(latest) ? session : latest, undefined);
|
|
@@ -920,11 +946,11 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
920
946
|
async resolvePlayerDisplay(sender, playerId) {
|
|
921
947
|
if (!sender)
|
|
922
948
|
return playerId || "未知玩家";
|
|
923
|
-
const platformName = await this.resolvePlatformName(sender.id);
|
|
949
|
+
const platformName = await this.resolvePlatformName(sender.id, sender.provider);
|
|
924
950
|
const name = platformName
|
|
925
951
|
|| (sender.name && sender.name !== sender.id ? sender.name : "")
|
|
926
952
|
|| "未知昵称";
|
|
927
|
-
return `玩家:${name}(${
|
|
953
|
+
return `玩家:${name}(${sender.provider}:${sender.id})`;
|
|
928
954
|
}
|
|
929
955
|
mahjongTableForPlayer(playerId) {
|
|
930
956
|
for (const [tableId, state] of this.mahjongTables) {
|
|
@@ -984,25 +1010,32 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
984
1010
|
}
|
|
985
1011
|
identity(sender) {
|
|
986
1012
|
return {
|
|
987
|
-
provider:
|
|
1013
|
+
provider: sender.provider,
|
|
988
1014
|
subject: sender.id,
|
|
989
1015
|
autoRegister: this.config.autoRegister,
|
|
990
|
-
displayName: sender.name || `${
|
|
1016
|
+
displayName: sender.name || `${sender.provider} ${sender.id}`,
|
|
991
1017
|
};
|
|
992
1018
|
}
|
|
993
1019
|
async targetSender(actor, targetSubject, bot) {
|
|
994
|
-
const
|
|
995
|
-
if (!
|
|
1020
|
+
const raw = cleanText(targetSubject);
|
|
1021
|
+
if (!raw)
|
|
996
1022
|
return actor;
|
|
1023
|
+
const separator = raw.indexOf(":");
|
|
1024
|
+
const provider = separator > 0 ? raw.slice(0, separator).toLowerCase() : actor.provider;
|
|
1025
|
+
const subject = separator > 0 ? raw.slice(separator + 1) : raw;
|
|
1026
|
+
if (provider !== actor.provider)
|
|
1027
|
+
return "请在目标平台使用该命令";
|
|
1028
|
+
if (!subject)
|
|
1029
|
+
return "无法获取目标平台身份";
|
|
997
1030
|
const denied = this.targetStaffDenied(actor);
|
|
998
1031
|
if (denied)
|
|
999
1032
|
return denied;
|
|
1000
1033
|
try {
|
|
1001
1034
|
const user = await bot?.getUser?.(subject);
|
|
1002
|
-
return { id: subject, name: user?.name || subject };
|
|
1035
|
+
return { id: subject, name: user?.name || subject, provider };
|
|
1003
1036
|
}
|
|
1004
1037
|
catch {
|
|
1005
|
-
return { id: subject, name: subject };
|
|
1038
|
+
return { id: subject, name: subject, provider };
|
|
1006
1039
|
}
|
|
1007
1040
|
}
|
|
1008
1041
|
loginSessionBody() {
|
|
@@ -1010,9 +1043,8 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1010
1043
|
.map((id) => id.trim())
|
|
1011
1044
|
.filter(Boolean);
|
|
1012
1045
|
const label = this.config.loginSessionLabel?.trim();
|
|
1013
|
-
if (pricingConfigIds.length === 0 && !label)
|
|
1014
|
-
return undefined;
|
|
1015
1046
|
return {
|
|
1047
|
+
entry: true,
|
|
1016
1048
|
...(pricingConfigIds.length === 0 ? {} : { pricingConfigIds }),
|
|
1017
1049
|
...(label ? { label } : {}),
|
|
1018
1050
|
};
|
|
@@ -1021,7 +1053,7 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1021
1053
|
if (!this.config.enableStaffCommands)
|
|
1022
1054
|
return "员工命令未启用";
|
|
1023
1055
|
const allowed = this.config.staffUserIds ?? [];
|
|
1024
|
-
if (allowed.length > 0 && !allowed
|
|
1056
|
+
if (allowed.length > 0 && !matchesPlatformIdentity(allowed, sender))
|
|
1025
1057
|
return "权限不足";
|
|
1026
1058
|
return null;
|
|
1027
1059
|
}
|
|
@@ -1029,7 +1061,7 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1029
1061
|
if (!this.config.enableStaffCommands)
|
|
1030
1062
|
return "员工命令未启用";
|
|
1031
1063
|
const allowed = this.config.staffUserIds ?? [];
|
|
1032
|
-
if (!allowed
|
|
1064
|
+
if (!matchesPlatformIdentity(allowed, sender))
|
|
1033
1065
|
return "权限不足";
|
|
1034
1066
|
return null;
|
|
1035
1067
|
}
|
|
@@ -1039,7 +1071,7 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1039
1071
|
const playerId = preview.playerId;
|
|
1040
1072
|
const subtotal = preview.subtotal;
|
|
1041
1073
|
const total = preview.total;
|
|
1042
|
-
const previewedAt = parseDateTime(preview.previewedAt);
|
|
1074
|
+
const previewedAt = (0, display_time_js_1.parseDateTime)(preview.previewedAt);
|
|
1043
1075
|
const sessionPreviews = result.sessionPreviews;
|
|
1044
1076
|
const pricingCapAdjustments = result.pricingCapAdjustments;
|
|
1045
1077
|
const checkoutAdjustments = result.checkoutAdjustments;
|
|
@@ -1057,16 +1089,17 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1057
1089
|
lines.push(`余额:${formatNumber(isPreview ? balanceBefore : balanceAfter)}${currency}`);
|
|
1058
1090
|
return lines.join("\n");
|
|
1059
1091
|
}
|
|
1060
|
-
const validStarts = sessionPreviews.map(
|
|
1061
|
-
const validEnds = sessionPreviews.map(
|
|
1092
|
+
const validStarts = sessionPreviews.map(s => s.startedAt).filter(value => (0, display_time_js_1.parseDateTime)(value));
|
|
1093
|
+
const validEnds = sessionPreviews.map(s => s.endedAt || (s.status === "active" ? preview.previewedAt : null)).filter(value => (0, display_time_js_1.parseDateTime)(value));
|
|
1062
1094
|
if (validStarts.length > 0) {
|
|
1063
|
-
const overallStart =
|
|
1064
|
-
const overallEnd = validEnds.length > 0 ?
|
|
1065
|
-
|
|
1095
|
+
const overallStart = validStarts.reduce((a, b) => Date.parse(a) < Date.parse(b) ? a : b);
|
|
1096
|
+
const overallEnd = validEnds.length > 0 ? validEnds.reduce((a, b) => Date.parse(a) > Date.parse(b) ? a : b) : now(this.config).toISOString();
|
|
1097
|
+
const offsets = [...new Set([(0, display_time_js_1.apiOffsetLabel)(overallStart), (0, display_time_js_1.apiOffsetLabel)(overallEnd)])].join(" / ");
|
|
1098
|
+
lines.push(`⏰ 游玩时间:${(0, display_time_js_1.formatHM)(overallStart)}–${(0, display_time_js_1.formatHM)(overallEnd)}(${offsets})`);
|
|
1066
1099
|
}
|
|
1067
1100
|
for (const sPrev of sessionPreviews) {
|
|
1068
1101
|
const label = sPrev?.label === "entry" ? this.config.loginSessionLabel?.trim() || "音游区间" : sPrev?.label || "计时区间";
|
|
1069
|
-
const startDt = parseDateTime(sPrev?.startedAt);
|
|
1102
|
+
const startDt = (0, display_time_js_1.parseDateTime)(sPrev?.startedAt);
|
|
1070
1103
|
const endDt = sessionDisplayEnd(sPrev, previewedAt);
|
|
1071
1104
|
const status = sPrev?.status ?? "active";
|
|
1072
1105
|
const sTotal = toNumber(sPrev?.total ?? 0);
|
|
@@ -1074,11 +1107,11 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1074
1107
|
lines.push(label);
|
|
1075
1108
|
if (startDt && endDt) {
|
|
1076
1109
|
const minutes = Math.floor((endDt.getTime() - startDt.getTime()) / 60_000);
|
|
1077
|
-
lines.push(`游玩时段:${formatHM(
|
|
1110
|
+
lines.push(`游玩时段:${(0, display_time_js_1.formatHM)(sPrev.startedAt)}-${(0, display_time_js_1.formatHM)(sPrev.endedAt || preview.previewedAt || endDt.toISOString())}`);
|
|
1078
1111
|
lines.push(`游玩时长:${formatDurationValue(minutes)}|计价:${formatNumber(sTotal)}${currency}`);
|
|
1079
1112
|
}
|
|
1080
1113
|
else if (startDt) {
|
|
1081
|
-
lines.push(`入场:${formatHM(
|
|
1114
|
+
lines.push(`入场:${(0, display_time_js_1.formatHM)(sPrev.startedAt)} (${status === "active" ? "计费中" : "已关闭"})`);
|
|
1082
1115
|
}
|
|
1083
1116
|
const sessionAdjustments = (sPrev?.adjustments ?? []);
|
|
1084
1117
|
for (const adj of sessionAdjustments) {
|
|
@@ -1095,8 +1128,8 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1095
1128
|
lines.push("封顶:");
|
|
1096
1129
|
for (const window of cappedWindows) {
|
|
1097
1130
|
const label = window.ruleLabel || "封顶时段";
|
|
1098
|
-
const startedAt = parseDateTime(window.windowStartedAt);
|
|
1099
|
-
const datedLabel = startedAt ? `${formatMD(
|
|
1131
|
+
const startedAt = (0, display_time_js_1.parseDateTime)(window.windowStartedAt);
|
|
1132
|
+
const datedLabel = startedAt ? `${(0, display_time_js_1.formatMD)(window.windowStartedAt)} ${label}` : label;
|
|
1100
1133
|
const currentAmount = toNumber(window.currentAmount);
|
|
1101
1134
|
const amountApplied = toNumber(window.amountApplied);
|
|
1102
1135
|
const priceCap = toNumber(window.priceCap);
|
|
@@ -1161,6 +1194,8 @@ ${table.players.map(player => player.name).join("、")}`),
|
|
|
1161
1194
|
}
|
|
1162
1195
|
}
|
|
1163
1196
|
function humanReadableBotError(error) {
|
|
1197
|
+
if (error.code === "INVALID_PLATFORM_IDENTITY")
|
|
1198
|
+
return error.message;
|
|
1164
1199
|
if (error.code === "DUPLICATE_SESSION_LABEL") {
|
|
1165
1200
|
return "❌ 您已经处于入场状态,请勿重复发送入场命令。";
|
|
1166
1201
|
}
|
|
@@ -1330,14 +1365,14 @@ function formatReleaseVersion(value) {
|
|
|
1330
1365
|
const revision = cleanText(record.revision);
|
|
1331
1366
|
return !revision || revision === "unknown" ? release : `${release} (${revision})`;
|
|
1332
1367
|
}
|
|
1333
|
-
function
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1368
|
+
function matchesPlatformIdentity(identities, sender) {
|
|
1369
|
+
return identities.includes(`${sender.provider}:${sender.id}`)
|
|
1370
|
+
// Legacy unqualified staff lists belong to the original adapter only.
|
|
1371
|
+
|| (sender.provider === "onebot" && identities.includes(sender.id));
|
|
1337
1372
|
}
|
|
1338
|
-
function formatPlayerReference(sender
|
|
1373
|
+
function formatPlayerReference(sender) {
|
|
1339
1374
|
const name = sender.name && sender.name !== sender.id ? sender.name : "未知昵称";
|
|
1340
|
-
return `${name}(${provider
|
|
1375
|
+
return `${name}(${sender.provider}:${sender.id})`;
|
|
1341
1376
|
}
|
|
1342
1377
|
function adjustmentKey(adjustment) {
|
|
1343
1378
|
const id = cleanText(adjustment?.id);
|
|
@@ -1387,63 +1422,6 @@ function formatNumber(value) {
|
|
|
1387
1422
|
}
|
|
1388
1423
|
return String(value);
|
|
1389
1424
|
}
|
|
1390
|
-
function parseDateTime(value) {
|
|
1391
|
-
if (!value)
|
|
1392
|
-
return null;
|
|
1393
|
-
if (value instanceof Date) {
|
|
1394
|
-
return ensureLocal(value);
|
|
1395
|
-
}
|
|
1396
|
-
const text = String(value).trim();
|
|
1397
|
-
if (!text)
|
|
1398
|
-
return null;
|
|
1399
|
-
let normalized = text;
|
|
1400
|
-
if (normalized.endsWith("Z"))
|
|
1401
|
-
normalized = `${normalized.slice(0, -1)}+00:00`;
|
|
1402
|
-
const dt = new Date(normalized);
|
|
1403
|
-
if (!Number.isNaN(dt.getTime()))
|
|
1404
|
-
return ensureLocal(dt);
|
|
1405
|
-
return null;
|
|
1406
|
-
}
|
|
1407
|
-
function ensureLocal(dt) {
|
|
1408
|
-
const offsetMs = LOCAL_TZ_OFFSET_MINUTES * 60_000;
|
|
1409
|
-
const local = new Date(dt.getTime() + offsetMs);
|
|
1410
|
-
void local;
|
|
1411
|
-
return dt;
|
|
1412
|
-
}
|
|
1413
|
-
function formatHM(dt) {
|
|
1414
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
1415
|
-
return `${pad(dt.getHours())}:${pad(dt.getMinutes())}`;
|
|
1416
|
-
}
|
|
1417
|
-
function formatMD(dt) {
|
|
1418
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
1419
|
-
return `${pad(dt.getMonth() + 1)}-${pad(dt.getDate())}`;
|
|
1420
|
-
}
|
|
1421
|
-
function formatDateTime(value) {
|
|
1422
|
-
const dt = parseDateTime(value);
|
|
1423
|
-
if (!dt)
|
|
1424
|
-
return "永不过期";
|
|
1425
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
1426
|
-
return `${dt.getFullYear()}/${pad(dt.getMonth() + 1)}/${pad(dt.getDate())} ${pad(dt.getHours())}:${pad(dt.getMinutes())}:${pad(dt.getSeconds())}`;
|
|
1427
|
-
}
|
|
1428
|
-
function formatTimeRange(start, end) {
|
|
1429
|
-
const startDt = parseDateTime(start);
|
|
1430
|
-
const endDt = parseDateTime(end);
|
|
1431
|
-
if (!startDt || !endDt)
|
|
1432
|
-
return `${formatDateTime(start)} - ${formatDateTime(end)}`;
|
|
1433
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
1434
|
-
const startTime = `${pad(startDt.getHours())}:${pad(startDt.getMinutes())}:${pad(startDt.getSeconds())}`;
|
|
1435
|
-
const endTime = `${pad(endDt.getHours())}:${pad(endDt.getMinutes())}:${pad(endDt.getSeconds())}`;
|
|
1436
|
-
if (startDt.toDateString() === endDt.toDateString())
|
|
1437
|
-
return `${startTime} - ${endTime}`;
|
|
1438
|
-
return `${startDt.getMonth() + 1}/${startDt.getDate()} ${startTime} - ${endDt.getMonth() + 1}/${endDt.getDate()} ${endTime}`;
|
|
1439
|
-
}
|
|
1440
|
-
function formatDurationMinutes(start, end) {
|
|
1441
|
-
const startDt = parseDateTime(start);
|
|
1442
|
-
const endDt = parseDateTime(end);
|
|
1443
|
-
if (!startDt || !endDt)
|
|
1444
|
-
return "0分钟";
|
|
1445
|
-
return formatDurationValue(Math.floor((endDt.getTime() - startDt.getTime()) / 60_000));
|
|
1446
|
-
}
|
|
1447
1425
|
function formatDurationValue(minutes) {
|
|
1448
1426
|
const total = Math.floor(toNumber(minutes));
|
|
1449
1427
|
if (total >= 60) {
|
|
@@ -1454,7 +1432,7 @@ function formatDurationValue(minutes) {
|
|
|
1454
1432
|
return `${total}分钟`;
|
|
1455
1433
|
}
|
|
1456
1434
|
function sessionDisplayEnd(session, previewedAt) {
|
|
1457
|
-
const endedAt = parseDateTime(session?.endedAt);
|
|
1435
|
+
const endedAt = (0, display_time_js_1.parseDateTime)(session?.endedAt);
|
|
1458
1436
|
if (endedAt)
|
|
1459
1437
|
return endedAt;
|
|
1460
1438
|
if (session?.status === "active")
|
|
@@ -1473,7 +1451,7 @@ function maxDate(dates) {
|
|
|
1473
1451
|
function formatInventoryItem(row) {
|
|
1474
1452
|
let line = `- ${row.assetName || row.assetCode || "资产"} (x${formatNumber(row.quantity)})`;
|
|
1475
1453
|
if (row.expiresAt)
|
|
1476
|
-
line += `\n 到期: ${formatDateTime(row.expiresAt)}`;
|
|
1454
|
+
line += `\n 到期: ${(0, display_time_js_1.formatDateTime)(row.expiresAt)}`;
|
|
1477
1455
|
return line;
|
|
1478
1456
|
}
|
|
1479
1457
|
function formatRedeemedItem(row) {
|
|
@@ -1505,9 +1483,9 @@ function formatHistory(sessions, currency) {
|
|
|
1505
1483
|
return "暂无历史记录";
|
|
1506
1484
|
const lines = [`📜 最近 ${sessions.length} 条记录:`];
|
|
1507
1485
|
for (const session of sessions) {
|
|
1508
|
-
const end = session.endedAt ? formatDateTime(session.endedAt) : "进行中";
|
|
1486
|
+
const end = session.endedAt ? (0, display_time_js_1.formatDateTime)(session.endedAt) : "进行中";
|
|
1509
1487
|
const cost = session.total == null ? "未结算" : `${formatNumber(session.total)} ${currency}`;
|
|
1510
|
-
lines.push(`- [${session.sessionId}] ${formatDateTime(session.startedAt)} -> ${end} (${cost})`);
|
|
1488
|
+
lines.push(`- [${session.sessionId}] ${(0, display_time_js_1.formatDateTime)(session.startedAt)} -> ${end} (${cost})`);
|
|
1511
1489
|
}
|
|
1512
1490
|
return lines.join("\n");
|
|
1513
1491
|
}
|
|
@@ -1515,10 +1493,8 @@ function findSubjectForSession(session, provider) {
|
|
|
1515
1493
|
const identities = session.identities ?? [];
|
|
1516
1494
|
if (identities.length === 0)
|
|
1517
1495
|
return null;
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
return qq.subject;
|
|
1521
|
-
return identities[0].subject ?? null;
|
|
1496
|
+
const identity = provider ? identities.find((id) => id.provider === provider) : identities[0];
|
|
1497
|
+
return identity?.subject ?? null;
|
|
1522
1498
|
}
|
|
1523
1499
|
exports.default = {
|
|
1524
1500
|
name: exports.name,
|