koishi-plugin-prism 0.3.0 → 0.3.1
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 +6 -6
- package/lib/index.d.ts +16 -5
- package/lib/index.js +54 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Koishi 里只填怎么连到店铺:
|
|
|
22
22
|
| 配置项 | 类型 | 描述 |
|
|
23
23
|
| :--- | :---: | :--- |
|
|
24
24
|
| `baseUrl` | `string` | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
|
|
25
|
-
| `shopCode` | `string` |
|
|
25
|
+
| `shopCode` | `string` | 可选。店铺公开编号;接入凭据已经指明店铺,**不需要填**。旧配置保留也能用。 |
|
|
26
26
|
| `integrationToken` | `string` | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
|
|
27
27
|
|
|
28
28
|
其余一切都在 PRiSM 网页里设置:每个令牌对应一个 Bot,Bot 在店铺里是一个**资源**。在**商户工作台 → 资源 → 这个 Bot → Bot 设置**里可以改:
|
|
@@ -34,21 +34,21 @@ Koishi 里只填怎么连到店铺:
|
|
|
34
34
|
| 玩家可用的命令 | `全部` 或 `只读`。只读时玩家只能绑定身份(`bind`)、查询(`wallet`、`billing`、`history`、`items`、`list`、`show`、`麻将列表`、`versions`、`api测速`、`ws测速`)、兑换(`redeem`)和延迟关机(`keep`);入场、结账、上下桌和设备操作(`login`/`入场`、`logout`、`mahjong`/`上桌`/`下桌`、`lock`、`on`、`off`、`coin`、`scan`)只有店员能用,包括替其他玩家操作。 |
|
|
35
35
|
| 只读提示 | 只读模式下玩家使用受限命令时 Bot 的回复。 |
|
|
36
36
|
| 店员命令 | 店员可以替其他玩家入场、结账、查询,以及 `add`、`del`、`overwrite`。 |
|
|
37
|
+
| 开关机失败的原因 | 只说玩家该知道的:没有这个设备、设备未连接、设备已关机、设备没有响应;其余情况统一回「操作没有完成,请找店员」,内部原因只写日志。 |
|
|
37
38
|
| 关机仅限店员 | `off` 只允许店员使用(以店员身份越过入场要求);`on` 始终只允许已入场玩家使用。 |
|
|
38
39
|
| 账单私聊店员 | 玩家退场或店员覆盖结账后,把同一份账单私聊给同一聊天平台上的店员。 |
|
|
39
40
|
| 闲置提醒频道、提前分钟 | 闲置自动关机的提醒发到哪里(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`),以及提前几分钟;0 或不填频道则不提醒。 |
|
|
40
41
|
| 门锁 | `lock` 打开的门(带门锁能力的资源);店里只有一扇门时默认就是它。没有门时 `lock` 回复本店还没有设置。 |
|
|
41
|
-
| 监听 Home Assistant | 见下文「监听 Home Assistant」。 |
|
|
42
42
|
|
|
43
43
|
**店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi 里重复填写。店铺没有开启计费时,入场、结账、钱包、上下桌、`list` 等计费命令直接回复「本店未启用计费」。
|
|
44
44
|
|
|
45
45
|
Bot 连上平台后先读取这些设置,再向平台打招呼;网页里改了设置、店员绑定了新身份、增删了麻将桌或门锁时,平台会通知 Bot 重新读取,**不需要重启 Koishi**。
|
|
46
46
|
|
|
47
|
-
旧版的 `autoRegister`、`currencyName`、`defaultDoorDeviceId`、`defaultScanProvider`(刷卡固定使用 Aime)、`loginPricingConfigIds`、`loginSessionLabel`、`enableStaffCommands`、`staffUserIds`、`powerCommandsAdminOnly`、`playerCommands`、`readOnlyNotice`、`logoutNotifyUserIds`、`idleNotifyChannelIds`、`idleReminderMinutes`、`watchHomeAssistant
|
|
47
|
+
旧版的 `autoRegister`、`currencyName`、`defaultDoorDeviceId`、`defaultScanProvider`(刷卡固定使用 Aime)、`loginPricingConfigIds`、`loginSessionLabel`、`enableStaffCommands`、`staffUserIds`、`powerCommandsAdminOnly`、`playerCommands`、`readOnlyNotice`、`logoutNotifyUserIds`、`idleNotifyChannelIds`、`idleReminderMinutes`、`watchHomeAssistant`(改由平台调度)、`botName`、`mahjongTableConfigs`、`mahjongTableSize` 已全部移除;升级后请到 Bot 的资源页重新设置。玩家首次使用时是否自动建档由店铺自己的注册开关决定。入场开始这个 Bot 在 PRiSM 里的计费方案:Bot 资源的专属方案,否则它所属资源组的方案;没改过的 Bot 在默认资源组,即店铺默认计费方案。已经在计费时 Bot 回复「您已在「方案名」中」。
|
|
48
48
|
|
|
49
49
|
### 统一平台
|
|
50
50
|
|
|
51
|
-
配置 `baseUrl
|
|
51
|
+
配置 `baseUrl` 和本店的 Integration 令牌后(店铺编号可选),插件直接连 `/integration/ws`:凭据在握手时解析出店铺,和机台连 `/io/ws` 一样,地址里没有店铺编号。插件与 PRiSM 只保持**一条 WebSocket 连接**,所有命令都作为请求帧走这条连接,平台也通过它推送闲置关机提醒。连接断开时命令直接回复「操作失败,暂时连不上服务器。」,不排队、不自动重发;插件在后台自动重连。需要 Koishi 的 `http` 服务(`ctx.http.ws`)。不再支持不填 `shopCode` 的单店兼容部署。
|
|
52
52
|
|
|
53
53
|
玩家在网页取得验证码后,向任意已接入的店铺 Bot 发送 `bind 验证码`(旧命令 `prism.bind` 仍可用)。店家可以在 PRiSM「设置 → 玩家与身份 → 绑定提示」改写玩家看到的绑定提示。所有命令从消息的 `session.platform` 和 `session.userId` 读取身份,发送 `{ code, provider, subject }`,不接受手填或代填身份;`provider` 配置已移除。例如同一实例的 OneBot 和 Telegram 消息分别使用 `onebot:114514` 和 `telegram:114514`。群/私聊过滤交给 Koishi。网页账号可以跨店使用,平台验证、玩家和余额按店铺隔离;同一网页账号追加平台绑定时复用同一个玩家。
|
|
54
54
|
|
|
@@ -60,7 +60,7 @@ Bot 连上平台后先读取这些设置,再向平台打招呼;网页里改
|
|
|
60
60
|
|
|
61
61
|
Bot 一直在线,所以平台会优先让 Bot 当店铺的 Home Assistant **监听器**:连上平台后 Bot 在握手里声明自己能监听,平台把 Home Assistant 的地址、一个**只读令牌**和要关心的设备实体发给它,Bot 订阅这些实体,把每次变化通过同一条连接报给平台。玩家页和商户后台因此能实时看到电源、空调状态,不必再临时去问 Home Assistant。店里的 HINATA IO 机台也能做同样的事;一家店同时监听的数量默认 2 个(由平台管理员按店铺调整),Bot 排在机台前面:一个 Bot 在线就占一个名额,两个 Bot 就占满,机台只补空位,Bot 上线时机台会在 Bot 交出完整状态之后让位,中间没有空窗。商户后台设备页的「HA 监听器」会显示现在是谁在监听。
|
|
62
62
|
|
|
63
|
-
-
|
|
63
|
+
- **谁在监听由平台决定**:能连上 Home Assistant 的 Bot 都会在 hello 里声明,平台按店铺的监听名额挑选和轮换;店家没有开关,也不能指定。不想要某个 Bot 参与,停用这个 Bot 资源即可。
|
|
64
64
|
- **地址**:平台给的地址列表按顺序尝试(店内地址在前、外部地址在后),不区分 Bot 在哪、Home Assistant 在哪,哪个通就用哪个。每个地址最多等 10 秒连接,一轮全部失败才向平台报断开,上次连上的地址下次排第一。
|
|
65
65
|
- **名字**:设备页显示的是 Bot 资源的名字,多个 Bot 请在资源页分别起名。
|
|
66
66
|
- 需要 Koishi 的 `http` 服务(`ctx.http.ws`),和与平台的连接用同一个。
|
|
@@ -155,7 +155,7 @@ npm version minor --no-git-tag-version
|
|
|
155
155
|
|
|
156
156
|
### 0.3.0
|
|
157
157
|
|
|
158
|
-
Koishi 配置只剩 `baseUrl
|
|
158
|
+
Koishi 配置只剩 `baseUrl` 和 `integrationToken`(`shopCode` 可选、已不需要)。Bot 在 PRiSM 里是一个资源,其余设置(只读模式、店员命令、关机权限、账单私聊、闲置提醒、门锁、名字、启用)都在商户工作台的「Bot 设置」里改,连接后读取、修改后由平台通知重新读取。店员改为网页里绑定了平台身份的店员,货币名称、门锁和麻将桌取自店铺。麻将改由平台完成(不必先入场,满桌开局),`下桌` 可指明桌号;`list` 按平台的在店名单输出(每人一处,资源带人数/容量),`list <资源或方案>` 只列这一项;下桌后回复还在计费的方案;入场开始 Bot 所在资源组的方案(或 Bot 的专属方案),重复入场回复「已在「方案名」中」,入场结束了互斥方案时列出被结束的方案。移除插件自己的麻将桌状态与所有旧配置项。需要配套支持 `integration/bot`、`integration/mahjong-tables`、`integration/roster` 和 `config.changed` 的 PRiSM(1.1.0 起);店铺所在的 PRiSM 升级之前不要升级到此版本。
|
|
159
159
|
|
|
160
160
|
### 0.1.39
|
|
161
161
|
|
package/lib/index.d.ts
CHANGED
|
@@ -33,8 +33,11 @@ export type BotConfig = {
|
|
|
33
33
|
idleChannelIds: string[];
|
|
34
34
|
/** How many minutes before an idle power-off to tell them; 0 for never. */
|
|
35
35
|
idleReminderMinutes: number;
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
};
|
|
37
|
+
/** Which shop this credential belongs to; the shop code is no longer configured by hand. */
|
|
38
|
+
shop?: {
|
|
39
|
+
code: string;
|
|
40
|
+
name: string;
|
|
38
41
|
};
|
|
39
42
|
billingEnabled: boolean;
|
|
40
43
|
currencyName: string;
|
|
@@ -143,6 +146,7 @@ type PlatformEvent = {
|
|
|
143
146
|
*/
|
|
144
147
|
export declare class PrismSocket {
|
|
145
148
|
private readonly open;
|
|
149
|
+
/** Resolved at each connection: the shop is learned from the credential first. */
|
|
146
150
|
private readonly url;
|
|
147
151
|
private readonly token;
|
|
148
152
|
/**
|
|
@@ -169,7 +173,9 @@ export declare class PrismSocket {
|
|
|
169
173
|
/** Bumped by every hello being prepared, so only the newest one is sent. */
|
|
170
174
|
private greeting;
|
|
171
175
|
private readonly pongWaiters;
|
|
172
|
-
constructor(open: SocketFactory,
|
|
176
|
+
constructor(open: SocketFactory,
|
|
177
|
+
/** Resolved at each connection: the shop is learned from the credential first. */
|
|
178
|
+
url: string | (() => string), token: string,
|
|
173
179
|
/**
|
|
174
180
|
* What to say in hello, read afresh each time: the bot's settings live on
|
|
175
181
|
* the platform, so they are fetched over this connection before it is
|
|
@@ -189,6 +195,8 @@ export declare class PrismSocket {
|
|
|
189
195
|
/** Send a frame if the connection is up; a report made while it is down is dropped, as the platform has forgotten the watch by then. */
|
|
190
196
|
send(frame: Record<string, unknown>): void;
|
|
191
197
|
start(): void;
|
|
198
|
+
/** Connect again with what the platform has just told us, such as the shop. */
|
|
199
|
+
reconnect(): void;
|
|
192
200
|
stop(): void;
|
|
193
201
|
private connect;
|
|
194
202
|
/**
|
|
@@ -215,8 +223,11 @@ type SocketReply = {
|
|
|
215
223
|
body: any;
|
|
216
224
|
serverMs?: number | null;
|
|
217
225
|
};
|
|
218
|
-
/**
|
|
219
|
-
|
|
226
|
+
/**
|
|
227
|
+
* The platform connection URL. The credential names the shop, as a device's
|
|
228
|
+
* token names its machine at `/io/ws`, so nothing identifying is in the path.
|
|
229
|
+
*/
|
|
230
|
+
export declare function platformSocketUrl(baseUrl: string): string;
|
|
220
231
|
export type Sender = {
|
|
221
232
|
id: string;
|
|
222
233
|
name: string;
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,7 @@ exports.version = package_json_1.default.version;
|
|
|
21
21
|
// resource page in PRiSM, read from the platform when the bot connects.
|
|
22
22
|
exports.Config = koishi_1.Schema.object({
|
|
23
23
|
baseUrl: koishi_1.Schema.string().required().description("PRiSM 后端地址,例如 https://link.neri.moe"),
|
|
24
|
-
shopCode: koishi_1.Schema.string().
|
|
24
|
+
shopCode: koishi_1.Schema.string().description("可选:店铺编号。接入凭据已经指明店铺,无需填写;旧配置仍认。"),
|
|
25
25
|
integrationToken: koishi_1.Schema.string().role("secret").required().description("集成 API Token;其余设置在 PRiSM 商户工作台 → 资源 → 这个 Bot → Bot 设置"),
|
|
26
26
|
});
|
|
27
27
|
function apply(ctx, config) {
|
|
@@ -147,7 +147,9 @@ class PrismSocket {
|
|
|
147
147
|
/** Bumped by every hello being prepared, so only the newest one is sent. */
|
|
148
148
|
greeting = 0;
|
|
149
149
|
pongWaiters = [];
|
|
150
|
-
constructor(open,
|
|
150
|
+
constructor(open,
|
|
151
|
+
/** Resolved at each connection: the shop is learned from the credential first. */
|
|
152
|
+
url, token,
|
|
151
153
|
/**
|
|
152
154
|
* What to say in hello, read afresh each time: the bot's settings live on
|
|
153
155
|
* the platform, so they are fetched over this connection before it is
|
|
@@ -183,6 +185,12 @@ class PrismSocket {
|
|
|
183
185
|
this.stopped = false;
|
|
184
186
|
this.connect();
|
|
185
187
|
}
|
|
188
|
+
/** Connect again with what the platform has just told us, such as the shop. */
|
|
189
|
+
reconnect() {
|
|
190
|
+
this.socket?.close(1000, "shop known");
|
|
191
|
+
this.socket = null;
|
|
192
|
+
this.connect();
|
|
193
|
+
}
|
|
186
194
|
stop() {
|
|
187
195
|
this.stopped = true;
|
|
188
196
|
if (this.retryTimer)
|
|
@@ -196,7 +204,7 @@ class PrismSocket {
|
|
|
196
204
|
connect() {
|
|
197
205
|
let socket;
|
|
198
206
|
try {
|
|
199
|
-
socket = this.open(this.url, { Authorization: `Bearer ${this.token}` });
|
|
207
|
+
socket = this.open(typeof this.url === "function" ? this.url() : this.url, { Authorization: `Bearer ${this.token}` });
|
|
200
208
|
}
|
|
201
209
|
catch (error) {
|
|
202
210
|
this.logger?.warn("PRiSM connection failed", error);
|
|
@@ -383,10 +391,13 @@ function serverLine(timings) {
|
|
|
383
391
|
return [];
|
|
384
392
|
return [`服务端处理:平均 ${Math.round(known.reduce((sum, value) => sum + value, 0) / known.length)} ms`];
|
|
385
393
|
}
|
|
386
|
-
/**
|
|
387
|
-
|
|
394
|
+
/**
|
|
395
|
+
* The platform connection URL. The credential names the shop, as a device's
|
|
396
|
+
* token names its machine at `/io/ws`, so nothing identifying is in the path.
|
|
397
|
+
*/
|
|
398
|
+
function platformSocketUrl(baseUrl) {
|
|
388
399
|
const base = baseUrl.trim().replace(/\/+$/, "").replace(/^http/i, "ws");
|
|
389
|
-
return `${base}/
|
|
400
|
+
return `${base}/integration/ws`;
|
|
390
401
|
}
|
|
391
402
|
/* ----------------------------- api client ---------------------------------- */
|
|
392
403
|
class PrismApiClient {
|
|
@@ -423,6 +434,9 @@ class PrismApiClient {
|
|
|
423
434
|
...(identity.displayName === undefined ? {} : { displayName: identity.displayName }),
|
|
424
435
|
};
|
|
425
436
|
}
|
|
437
|
+
/** The shop this credential belongs to, read before the shop code is known. */
|
|
438
|
+
setShopCode(code) { if (this.http)
|
|
439
|
+
this.http.shopCode = code; }
|
|
426
440
|
/** The bot's own settings and what it needs to know about the shop. */
|
|
427
441
|
async getBotConfig() {
|
|
428
442
|
return this.request("GET", "/rpc/integration/bot", {});
|
|
@@ -475,6 +489,8 @@ class PrismApiClient {
|
|
|
475
489
|
if (!this.http)
|
|
476
490
|
throw new PrismBotClientError("HTTP 测速不可用", "HTTP_UNAVAILABLE", 0, {});
|
|
477
491
|
const { post, baseUrl, shopCode, token } = this.http;
|
|
492
|
+
if (!shopCode)
|
|
493
|
+
throw new PrismBotClientError("店铺尚未读取", "SHOP_UNKNOWN", 0, {});
|
|
478
494
|
const url = `${baseUrl.trim().replace(/\/+$/, "")}/api/v1/shops/${encodeURIComponent(shopCode)}/integration/players/by-identity/wallet`;
|
|
479
495
|
const startedAt = performance.now();
|
|
480
496
|
const response = await post(url, { authorization: `Bearer ${token}`, "content-type": "application/json" }, this.identityBody(identity));
|
|
@@ -585,8 +601,8 @@ class PrismKoishiService {
|
|
|
585
601
|
this.client = options.client;
|
|
586
602
|
return;
|
|
587
603
|
}
|
|
588
|
-
if (!options.
|
|
589
|
-
throw new Error("PRiSM Koishi plugin requires '
|
|
604
|
+
if (!options.baseUrl || !options.integrationToken) {
|
|
605
|
+
throw new Error("PRiSM Koishi plugin requires 'baseUrl' and 'integrationToken'.");
|
|
590
606
|
}
|
|
591
607
|
const open = options.socket ?? ((url, headers) => {
|
|
592
608
|
const http = ctx.http;
|
|
@@ -599,7 +615,7 @@ class PrismKoishiService {
|
|
|
599
615
|
const haOpen = options.haSocket ?? (options.socket ? null : open);
|
|
600
616
|
if (haOpen)
|
|
601
617
|
this.watcher = new ha_watch_js_1.HaWatcher(haOpen, (frame) => this.socket?.send(frame), this.logger);
|
|
602
|
-
this.socket = new PrismSocket(open, platformSocketUrl(options.baseUrl
|
|
618
|
+
this.socket = new PrismSocket(open, platformSocketUrl(options.baseUrl), options.integrationToken, () => this.hello(), (event) => {
|
|
603
619
|
if (event.event === "idle.reminder")
|
|
604
620
|
void this.remindIdle(event.data);
|
|
605
621
|
}, this.logger, this.watcher
|
|
@@ -618,7 +634,7 @@ class PrismKoishiService {
|
|
|
618
634
|
});
|
|
619
635
|
return { status: response.status, headers: response.headers, data: response.data };
|
|
620
636
|
});
|
|
621
|
-
this.client = new PrismApiClient(this.socket, { post, baseUrl: options.baseUrl,
|
|
637
|
+
this.client = new PrismApiClient(this.socket, { post, baseUrl: options.baseUrl, token: options.integrationToken, ...(options.shopCode ? { shopCode: options.shopCode } : {}) });
|
|
622
638
|
this.socket.start();
|
|
623
639
|
}
|
|
624
640
|
dispose() {
|
|
@@ -636,8 +652,11 @@ class PrismKoishiService {
|
|
|
636
652
|
this.reading = (async () => {
|
|
637
653
|
try {
|
|
638
654
|
const bot = parseBotConfig(await this.client.getBotConfig());
|
|
639
|
-
if (read === this.reads)
|
|
655
|
+
if (read === this.reads) {
|
|
640
656
|
this.bot = bot;
|
|
657
|
+
if (bot.shop?.code)
|
|
658
|
+
this.client.setShopCode(bot.shop.code);
|
|
659
|
+
}
|
|
641
660
|
return bot;
|
|
642
661
|
}
|
|
643
662
|
catch (error) {
|
|
@@ -669,8 +688,9 @@ class PrismKoishiService {
|
|
|
669
688
|
return {};
|
|
670
689
|
}
|
|
671
690
|
const { settings } = bot;
|
|
672
|
-
|
|
673
|
-
//
|
|
691
|
+
// Watching is the platform's to schedule: every bot that can offers, and the
|
|
692
|
+
// hub picks among them. A bot with no Home Assistant connection cannot.
|
|
693
|
+
this.watching = this.watcher !== null;
|
|
674
694
|
if (!this.watching)
|
|
675
695
|
this.watcher?.stop();
|
|
676
696
|
return {
|
|
@@ -1199,9 +1219,11 @@ class PrismKoishiService {
|
|
|
1199
1219
|
return `${operation}失败,${powerFailureReason(error)}`;
|
|
1200
1220
|
}
|
|
1201
1221
|
}
|
|
1222
|
+
/** Whether the action failed; the message itself is logged, never shown as it is. */
|
|
1202
1223
|
getCommandFailureMessage(result) {
|
|
1203
1224
|
const action = result?.action;
|
|
1204
|
-
|
|
1225
|
+
// `pending` here is an unanswered request (a timeout): it counts as not done.
|
|
1226
|
+
if (action?.status === "expired" || action?.status === "rejected" || action?.status === "pending") {
|
|
1205
1227
|
return action.payload?.executorFailure?.message || "命令执行被拒绝或超时";
|
|
1206
1228
|
}
|
|
1207
1229
|
return null;
|
|
@@ -1388,8 +1410,9 @@ class PrismKoishiService {
|
|
|
1388
1410
|
handleCommandError(error) {
|
|
1389
1411
|
this.logCommandError(error);
|
|
1390
1412
|
if (error instanceof PrismBotClientError) {
|
|
1391
|
-
|
|
1392
|
-
|
|
1413
|
+
const shopCode = this.options.shopCode ?? this.bot?.shop?.code;
|
|
1414
|
+
if (error.code?.startsWith("LOCATION_") && shopCode && this.options.baseUrl) {
|
|
1415
|
+
return `请在网页完成到店校验:${this.options.baseUrl.replace(/\/+$/, "")}/t/${encodeURIComponent(shopCode)}`;
|
|
1393
1416
|
}
|
|
1394
1417
|
return humanReadableBotError(error);
|
|
1395
1418
|
}
|
|
@@ -1451,7 +1474,8 @@ function powerFailureReason(error) {
|
|
|
1451
1474
|
return "玩家未注册";
|
|
1452
1475
|
if (error.code === "BILLING_DISABLED")
|
|
1453
1476
|
return BILLING_DISABLED_NOTICE;
|
|
1454
|
-
|
|
1477
|
+
if (error.code === "DEVICE_NOT_FOUND")
|
|
1478
|
+
return "没有这个设备";
|
|
1455
1479
|
}
|
|
1456
1480
|
return "请稍后再试";
|
|
1457
1481
|
}
|
|
@@ -1470,16 +1494,23 @@ function deviceActionFailureReason(error) {
|
|
|
1470
1494
|
return BILLING_DISABLED_NOTICE;
|
|
1471
1495
|
return "请稍后再试";
|
|
1472
1496
|
}
|
|
1497
|
+
/**
|
|
1498
|
+
* What a player may be told about a device that would not act. Only facts about
|
|
1499
|
+
* the device itself — whether it exists, is connected, is off, answered — never
|
|
1500
|
+
* how the shop configured it or what went wrong inside the platform.
|
|
1501
|
+
*/
|
|
1502
|
+
const DEVICE_REASONS = [
|
|
1503
|
+
[/设备不存在|没有找到这个资源/, "没有这个设备"],
|
|
1504
|
+
[/机台未在线|没有在线客户端|设备未连接|直连中继尚未配置/, "设备未连接"],
|
|
1505
|
+
[/设备已关机/, "设备已关机"],
|
|
1506
|
+
[/设备未响应|机台未响应/, "设备没有响应"],
|
|
1507
|
+
];
|
|
1473
1508
|
function deviceCommandFailureReason(result) {
|
|
1474
1509
|
const action = result?.action;
|
|
1475
|
-
if (!action || (action.status !== "expired" && action.status !== "rejected"))
|
|
1510
|
+
if (!action || (action.status !== "expired" && action.status !== "rejected" && action.status !== "pending"))
|
|
1476
1511
|
return null;
|
|
1477
1512
|
const message = cleanText(action.payload?.executorFailure?.message);
|
|
1478
|
-
|
|
1479
|
-
return "设备未连接";
|
|
1480
|
-
if (message.includes("设备配置不存在"))
|
|
1481
|
-
return "设备未配置";
|
|
1482
|
-
return "请稍后再试";
|
|
1513
|
+
return DEVICE_REASONS.find(([pattern]) => pattern.test(message))?.[1] ?? "操作没有完成,请找店员";
|
|
1483
1514
|
}
|
|
1484
1515
|
function deviceCommandLabel(result) {
|
|
1485
1516
|
return cleanText(result?.action?.payload?.deviceLabel);
|
|
@@ -1535,7 +1566,6 @@ function parseBotConfig(value) {
|
|
|
1535
1566
|
receiptsToStaff: settings.receiptsToStaff === true,
|
|
1536
1567
|
idleChannelIds: strings(settings.idleChannelIds),
|
|
1537
1568
|
idleReminderMinutes: Math.max(0, Number(settings.idleReminderMinutes ?? 5) || 0),
|
|
1538
|
-
watchHomeAssistant: settings.watchHomeAssistant !== false,
|
|
1539
1569
|
},
|
|
1540
1570
|
billingEnabled: record.billingEnabled !== false,
|
|
1541
1571
|
currencyName: cleanText(record.currencyName) || "余额",
|