koishi-plugin-prism 0.5.2 → 0.6.0
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 +20 -13
- package/lib/index.d.ts +104 -116
- package/lib/index.js +412 -1539
- package/package.json +1 -1
- package/lib/display-time.d.ts +0 -10
- package/lib/display-time.js +0 -36
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Koishi 里只填怎么连到店铺:
|
|
|
26
26
|
| `baseUrl` | `string` | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
|
|
27
27
|
| `shopCode` | `string` | 可选。店铺公开编号;接入凭据已经指明店铺,**不需要填**。旧配置保留也能用。 |
|
|
28
28
|
| `integrationToken` | `string` | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
|
|
29
|
+
| `syncNames` | `boolean` | 可选,默认开。连上后约一分钟、之后每 6 小时读 Bot 所在每个群的成员昵称发给 PRiSM,补全本店玩家的名字;关掉后只在玩家自己发命令时更新。 |
|
|
29
30
|
|
|
30
31
|
其余一切都在 PRiSM 网页里设置:每个令牌对应一个 Bot,Bot 在店铺里是一个**资源**。在**商户工作台 → 资源 → 这个 Bot → Bot 设置**里可以改:
|
|
31
32
|
|
|
@@ -41,8 +42,8 @@ Koishi 里只填怎么连到店铺:
|
|
|
41
42
|
| 账单私聊店员 | 玩家退场或店员覆盖结账后,把同一份账单私聊给同一聊天平台上的店员。 |
|
|
42
43
|
| 门锁 | `lock` 打开的门(带门锁能力的资源);店里只有一扇门时默认就是它。没有门时 `lock` 回复本店还没有设置。 |
|
|
43
44
|
| 入场后自动获取门锁密码 | 默认关闭。打开后 `login`/`入场` 成功时顺带生成一个 8 位 TTLock 临时密码(有效期 3 分钟)一并回复;门锁失败只多一行提示,不会让入场失败。没有门锁时不生效。 |
|
|
44
|
-
| 播报与提醒 |
|
|
45
|
-
| 播报这些 |
|
|
45
|
+
| 播报与提醒 | 在后台 Bot 设置的「播报」里建**播报组**:每组是一种听众,有自己的目的地(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`,私聊店员也这样写),以及一整张事件表:每个事件播不播、只听哪些来源、用什么文案。没有播报组就什么都不播。另有闲置关机提醒的**提前量**(分钟),为 0 时不提醒。 |
|
|
46
|
+
| 播报这些 | 平台按播报组决定发什么、发到哪里,并按那一组的文案写好要说的话,插件直接发出(其中的玩家由插件换成群里的称呼)。事件按话题分组,每个话题里分**尝试**(有人要求做某件事以及结果:已发出、被拒绝、失败,比如开机、投币、虚拟刷卡、结账)和**事实**(真的发生了的事,比如设备开机、游戏读到卡、结账完成),另有闲置关机提醒和系统维护两种**提醒**。这个 Bot 自己执行的命令已经回复过,不再播报。 |
|
|
46
47
|
|
|
47
48
|
播报与闲置提醒直接通过对应平台的第一个在线机器人发送,不依赖 Koishi 的数据库、频道分配或 silent 标记,是否播报由 PRiSM 设置决定。群聊填写 `平台:频道`,私聊填写 `平台:private:用户ID`;频道 ID 内的冒号保持原样。连续播报不会修改缓存的频道列表,单个目标发送失败会记录目标及错误并继续其他目标和后续播报。相同平台有多个机器人时,第一个在线账号须能访问目标群;离线时不缓存补发。
|
|
48
49
|
|
|
@@ -50,13 +51,13 @@ HA 监听的健康心跳与 HA ping 均为每 60 秒一次,与机台 IO 对齐
|
|
|
50
51
|
|
|
51
52
|
**店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi 里重复填写。店铺没有整店计费开关。Bot 属于一个资源组,`login`/`入场` 开始的是这个资源组(或 Bot 资源专属)的计费方案;平台下发的 `billingEnabled` 只表示通过这个 Bot 入场是否计费。为 `false` 时 Bot 不请求平台,直接回复「这里不计费,无需入场」;平台拒绝时(例如资源组刚改成免费)回复同样的话。钱包、账单、结账、兑换、上下桌、`list` 等命令属于玩家或各自的资源,跟 Bot 所在资源组无关,一律交给平台处理。旧平台整店未启用计费时返回的 `BILLING_DISABLED` 仍提示「本店未启用计费」。
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
这些设置由平台自己读、自己判断,插件不读取;网页里改了设置、店员绑定了新身份、增删了麻将桌或门锁时立即生效,**不需要重启 Koishi**。
|
|
54
55
|
|
|
55
56
|
旧版的 `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 回复「您已在「方案名」中」。
|
|
56
57
|
|
|
57
58
|
### 统一平台
|
|
58
59
|
|
|
59
|
-
配置 `baseUrl` 和本店的 Integration 令牌后(店铺编号可选),插件直接连 `/integration/ws`:凭据在握手时解析出店铺,和机台连 `/io/ws` 一样,地址里没有店铺编号。插件与 PRiSM 只保持**一条 WebSocket
|
|
60
|
+
配置 `baseUrl` 和本店的 Integration 令牌后(店铺编号可选),插件直接连 `/integration/ws`:凭据在握手时解析出店铺,和机台连 `/io/ws` 一样,地址里没有店铺编号。插件与 PRiSM 只保持**一条 WebSocket 连接**,玩家的命令原样(命令名和参数)转给平台,平台执行后告诉插件说什么:第一句作为命令的回复(引用原消息),其余的(如私聊店员的账单)照平台说的地方发出;店内动态和闲置提醒也是平台写好、指定发到哪个群。插件里没有命令的业务逻辑,也不再自己判断权限和措辞。30 秒没有回音时回复「服务器没有及时回应,请稍后确认结果」。连接断开时命令直接回复「操作失败,暂时连不上服务器。」,不排队、不自动重发;插件在后台自动重连。需要 Koishi 的 `http` 服务(`ctx.http.ws`)。不再支持不填 `shopCode` 的单店兼容部署。
|
|
60
61
|
|
|
61
62
|
玩家在网页取得验证码后,向任意已接入的店铺 Bot 发送 `bind 验证码`(旧命令 `prism.bind` 仍可用)。店家可以在 PRiSM「设置 → 玩家与身份 → 绑定提示」改写玩家看到的绑定提示。所有命令从消息的 `session.platform` 和 `session.userId` 读取身份,发送 `{ code, provider, subject }`,不接受手填或代填身份;`provider` 配置已移除。例如同一实例的 OneBot 和 Telegram 消息分别使用 `onebot:114514` 和 `telegram:114514`。群/私聊过滤交给 Koishi。网页账号可以跨店使用,平台验证、玩家和余额按店铺隔离;同一网页账号追加平台绑定时复用同一个玩家。
|
|
62
63
|
|
|
@@ -105,9 +106,9 @@ Bot 设置开启「账单私聊店员」时,玩家退场或店员覆盖结账
|
|
|
105
106
|
* `麻将列表` - 查看店里麻将桌的桌名、别名,以及空闲、等位或游玩中状态。
|
|
106
107
|
* `api测速 [次数]` - 走 HTTP 连续查询自己的钱包:首次(含建立连接)单独列出,之后显示最小、平均与最大延迟,并给出服务端处理时间和经过的 Cloudflare 节点(默认 5 次,最多 10 次)。
|
|
107
108
|
* `ws测速 [次数]` - 走 Bot 的 WebSocket 连接:心跳往返(纯网络)和同样的钱包查询,并给出服务端处理时间(默认 5 次,最多 10 次)。两者对比可以看出延迟在网络还是在服务端,以及长连接能省下多少。
|
|
108
|
-
* `versions` - 显示当前 Bot npm
|
|
109
|
+
* `versions` - 显示当前 Bot npm 包版本,以及后端是哪次部署(Worker 名称和提交号的前 12 位,如 `prism-link-beta (df66f121da54)`);后端不可达时仍会显示 Bot 版本。
|
|
109
110
|
|
|
110
|
-
Bot 版本直接读取本 npm 包的 `package.json
|
|
111
|
+
Bot 版本直接读取本 npm 包的 `package.json`,后端的部署读取无需认证的 `GET /version`(`{ worker, revision }`;后端没有发布版本号)。插件发布遵循 SemVer;修复使用 patch、兼容新增功能使用 minor、不兼容改动使用 major,发布前通过 `npm version <patch|minor|major>` 自动更新包版本。
|
|
111
112
|
|
|
112
113
|
### 店员快捷指令
|
|
113
114
|
|
|
@@ -166,6 +167,18 @@ npm version minor --no-git-tag-version
|
|
|
166
167
|
|
|
167
168
|
绑定支持 Koishi 提供的各适配器标识,身份值保持字符串,不限定数字格式。店员和账单私聊按「平台标识 + 身份值」认人,相同号码的其他平台不会继承权限或通知。管理员代操作使用目标平台标识,禁止通过当前适配器误操作另一个平台。`/list` 只用当前平台的身份查询昵称,缺失时使用后台名称。源码和 npm 发行包需要分别核对版本。
|
|
168
169
|
|
|
170
|
+
### 0.6.0
|
|
171
|
+
|
|
172
|
+
- 玩家的名字按平台分开存:说到一个玩家时用他在本平台的名字(平台在每个身份上保存的称呼),一个人绑了两个平台也不会被来回改名。
|
|
173
|
+
- 批量补名:连上平台约一分钟后、之后每 6 小时,读 Bot 所在每个群的成员列表,把成员的昵称分批发给平台,让从旧系统导入的「Player 75」这类占位名、以及从没用过 Bot 命令的玩家也有名字。平台只保留本店玩家的名字。配置 `syncNames: false` 可关闭。
|
|
174
|
+
- 需要支持 `names` 帧和身份名字(迁移 `0057`)的 PRiSM。
|
|
175
|
+
|
|
176
|
+
### 0.5.3
|
|
177
|
+
|
|
178
|
+
插件改为只转发命令:`login`、`logout`、`wallet` 等命令连同参数原样发给平台(`command` 帧),平台执行、判断权限(只读模式、店员、计费)、写好回复,插件照发(`say` 帧);账单私聊店员、入场附带的门锁密码也由平台决定发到哪。店内动态和闲置提醒同样由平台写好、按 Bot 的监听规则发到规则指定的群或个人,插件不再读取 Bot 设置,也不再收 `shop.event`。插件自己只保留 `versions`、`api测速`、`ws测速` 和 Home Assistant 监听。播报新增机台投币、开局扣币、投币计数清零(需要机台 IO 开启 `cabinetMonitor`),以及来自 Home Assistant 的开机、关机;刷卡改为在游戏取到卡时播报,网页刷卡和实体卡一样只说一次;`下桌` 不必再指定桌号。需要支持命令协议的 PRiSM,店铺所在的 PRiSM 升级之前不要升级到此版本。
|
|
179
|
+
|
|
180
|
+
`versions` 按平台现在的 `GET /version` 显示后端:Worker 名称和提交号,不再有发布版本号。
|
|
181
|
+
|
|
169
182
|
### 0.5.2
|
|
170
183
|
|
|
171
184
|
完整恢复 0.4.1/0.4.2 的修复:HA 心跳与 ping 每 60 秒一次;店内动态和闲置预告直接通过适配器发送,不依赖 Koishi 数据库,不修改频道列表,支持群聊/私聊及逐目标失败隔离。电源播报继续由平台根据 HA 事件分发。同时支持店员 `/上桌 a @玩家`、`/下桌 a @玩家`,保留 0.5.1 的兑换提示修复。
|
|
@@ -198,10 +211,4 @@ Koishi 配置只剩 `baseUrl` 和 `integrationToken`(`shopCode` 可选、已
|
|
|
198
211
|
|
|
199
212
|
## 时间展示
|
|
200
213
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
当前上下桌功能使用平台 `integration/players/by-identity/mahjong`;平台不再兼容旧 Bot 通过指定方案的 `session/start` 模拟麻将计费。
|
|
204
|
-
|
|
205
|
-
### 0.4.1 / 0.4.2 修复恢复
|
|
206
|
-
|
|
207
|
-
回退 0.4.0 后发布的 0.5.1 漏带了两组修复:0.4.1 的 60 秒 HA 心跳和 ping,以及 0.4.2 的无数据库播报发送、群聊/私聊、逐目标失败隔离和连续播报回归测试。现已完整恢复,保留后续兑换与管理员上下桌改动。Bot 本地判断 HA 电源变化的已撤回实现不属于这些修复。
|
|
214
|
+
账单、历史与资产到期的时间由平台按店铺时区写好,例如「⏰ 游玩时间:18:00–19:00(UTC+08:00)」,不依赖 Bot 服务器时区。
|
package/lib/index.d.ts
CHANGED
|
@@ -10,83 +10,32 @@ export declare class PrismBotClientError extends Error {
|
|
|
10
10
|
readonly code: string;
|
|
11
11
|
readonly status: number;
|
|
12
12
|
readonly body: unknown;
|
|
13
|
-
|
|
14
|
-
constructor(message: string, code: string, status: number, body: unknown, originalError?: unknown | undefined);
|
|
13
|
+
constructor(message: string, code: string, status: number, body: unknown);
|
|
15
14
|
}
|
|
16
|
-
/** What the bot is told about itself and the shop by `GET integration/bot`. */
|
|
17
|
-
export type BotConfig = {
|
|
18
|
-
bot: {
|
|
19
|
-
id: string;
|
|
20
|
-
name: string;
|
|
21
|
-
};
|
|
22
|
-
settings: {
|
|
23
|
-
/** "readonly" leaves players binding, lookups and redeeming; staff keep every command. */
|
|
24
|
-
playerCommands: "all" | "readonly";
|
|
25
|
-
readOnlyNotice: string;
|
|
26
|
-
/** Staff may act for other players. */
|
|
27
|
-
staffCommands: boolean;
|
|
28
|
-
/** Only staff may switch machines off. */
|
|
29
|
-
powerOffStaffOnly: boolean;
|
|
30
|
-
/** Staff on the same platform get checkout receipts privately. */
|
|
31
|
-
receiptsToStaff: boolean;
|
|
32
|
-
/** `login`/`入场` also hands out the door code. */
|
|
33
|
-
doorPasswordOnEntry: boolean;
|
|
34
|
-
/** Channels (`platform:channelId`) the shop says everything in: idle warnings and what happens. */
|
|
35
|
-
announceChannelIds: string[];
|
|
36
|
-
/** How many minutes before an idle power-off to tell them; 0 for never. */
|
|
37
|
-
idleReminderMinutes: number;
|
|
38
|
-
/** Which news is told, each on its own. */
|
|
39
|
-
announceIdle: boolean;
|
|
40
|
-
announcePower: boolean;
|
|
41
|
-
announceStarts: boolean;
|
|
42
|
-
announceCards: boolean;
|
|
43
|
-
announceCoins: boolean;
|
|
44
|
-
};
|
|
45
|
-
/** Which shop this credential belongs to; the shop code is no longer configured by hand. */
|
|
46
|
-
shop?: {
|
|
47
|
-
code: string;
|
|
48
|
-
name: string;
|
|
49
|
-
};
|
|
50
|
-
/** Whether entering through this bot bills: its own plan, otherwise its resource group's. */
|
|
51
|
-
billingEnabled: boolean;
|
|
52
|
-
currencyName: string;
|
|
53
|
-
/** Staff are these platform identities. */
|
|
54
|
-
staff: Array<{
|
|
55
|
-
provider: string;
|
|
56
|
-
subject: string;
|
|
57
|
-
}>;
|
|
58
|
-
/** The door `lock`/开门 opens. */
|
|
59
|
-
door: {
|
|
60
|
-
id: string;
|
|
61
|
-
name: string;
|
|
62
|
-
} | null;
|
|
63
|
-
mahjongTables: Array<{
|
|
64
|
-
id: string;
|
|
65
|
-
name: string;
|
|
66
|
-
aliases: string[];
|
|
67
|
-
capacity: number;
|
|
68
|
-
}>;
|
|
69
|
-
};
|
|
70
15
|
export type PrismKoishiPluginConfig = {
|
|
71
16
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* back to `playerDisplayName` from the backend.
|
|
17
|
+
* How the chat names a player: an adapter subject and provider to a nickname
|
|
18
|
+
* (e.g. from the current group's member list). Without it, the platform's
|
|
19
|
+
* display name is used.
|
|
76
20
|
*/
|
|
77
21
|
resolveDisplayName?: (subject: string, provider: string) => Promise<string | null | undefined> | string | null | undefined;
|
|
78
|
-
/** Get a stable current ISO timestamp; mainly for tests. */
|
|
79
|
-
now?: () => Date;
|
|
80
22
|
shopCode?: string;
|
|
81
23
|
baseUrl?: string;
|
|
82
24
|
integrationToken?: string;
|
|
83
|
-
client?: any;
|
|
84
25
|
/** Opens the platform connection; defaults to Koishi's `ctx.http.ws`. Mainly for tests. */
|
|
85
26
|
socket?: SocketFactory;
|
|
86
27
|
/** Plain HTTP POST, used only by `api测速`; defaults to Koishi's `ctx.http`. Mainly for tests. */
|
|
87
28
|
httpPost?: HttpPost;
|
|
88
29
|
/** Opens connections to Home Assistant; defaults to Koishi's `ctx.http.ws`. Mainly for tests. */
|
|
89
30
|
haSocket?: SocketFactory;
|
|
31
|
+
/**
|
|
32
|
+
* Read the members of every group the bots are in and tell the platform what
|
|
33
|
+
* each is called, so a shop's players get their chat names even when they
|
|
34
|
+
* never send the bot a command. On by default; `false` turns it off.
|
|
35
|
+
*/
|
|
36
|
+
syncNames?: boolean;
|
|
37
|
+
/** When the first name read runs after starting; a minute by default. Mainly for tests. */
|
|
38
|
+
nameSyncFirstMs?: number;
|
|
90
39
|
};
|
|
91
40
|
/** A plain HTTP POST answering with its status, headers and decoded body. */
|
|
92
41
|
export type HttpPost = (url: string, headers: Record<string, string>, body: unknown) => Promise<{
|
|
@@ -108,12 +57,8 @@ export type SocketLike = {
|
|
|
108
57
|
addEventListener(type: "open" | "message" | "close" | "error", listener: (event: any) => void): void;
|
|
109
58
|
};
|
|
110
59
|
export type SocketFactory = (url: string, headers: Record<string, string>) => SocketLike;
|
|
111
|
-
export type KoishiCommandRegistration = {
|
|
112
|
-
description: string;
|
|
113
|
-
action: (context: KoishiActionContext, ...args: string[]) => Promise<string> | string;
|
|
114
|
-
};
|
|
115
60
|
export type KoishiCommandBuilder = {
|
|
116
|
-
action(handler:
|
|
61
|
+
action(handler: (context: KoishiActionContext, ...args: any[]) => Promise<string> | string): KoishiCommandBuilder;
|
|
117
62
|
};
|
|
118
63
|
export type KoishiLikeContext = {
|
|
119
64
|
command(name: string, description: string): KoishiCommandBuilder;
|
|
@@ -125,6 +70,17 @@ export type KoishiLikeContext = {
|
|
|
125
70
|
isActive: boolean;
|
|
126
71
|
sendMessage(channelId: string, content: string): Promise<unknown>;
|
|
127
72
|
sendPrivateMessage(userId: string, content: string): Promise<unknown>;
|
|
73
|
+
/** Koishi's paged lists: the groups the bot is in, and a group's members. */
|
|
74
|
+
getGuildList?(next?: string): Promise<{
|
|
75
|
+
data: Array<{
|
|
76
|
+
id: string;
|
|
77
|
+
}>;
|
|
78
|
+
next?: string;
|
|
79
|
+
}>;
|
|
80
|
+
getGuildMemberList?(guildId: string, next?: string): Promise<{
|
|
81
|
+
data: GuildMember[];
|
|
82
|
+
next?: string;
|
|
83
|
+
}>;
|
|
128
84
|
}>;
|
|
129
85
|
on?(event: "dispose", listener: () => void): void;
|
|
130
86
|
};
|
|
@@ -133,8 +89,8 @@ export type KoishiActionContext = {
|
|
|
133
89
|
platform?: string;
|
|
134
90
|
isDirect?: boolean;
|
|
135
91
|
userId: string;
|
|
92
|
+
channelId?: string;
|
|
136
93
|
messageId?: string;
|
|
137
|
-
senderId?: string;
|
|
138
94
|
senderName?: string;
|
|
139
95
|
username?: string;
|
|
140
96
|
bot?: {
|
|
@@ -142,33 +98,81 @@ export type KoishiActionContext = {
|
|
|
142
98
|
getUser?(id: string): Promise<{
|
|
143
99
|
name?: string;
|
|
144
100
|
}>;
|
|
145
|
-
|
|
101
|
+
/** Send to this bot's channels by id; `private:<user>` for a private chat. */
|
|
102
|
+
broadcast?(channels: string[], content: string): Promise<unknown>;
|
|
146
103
|
};
|
|
147
104
|
};
|
|
148
105
|
};
|
|
149
106
|
export declare function applyPrismKoishiPlugin(ctx: KoishiLikeContext, config: PrismKoishiPluginConfig): void;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
107
|
+
/** A player as the platform names one in what it says; `name` on an identity is what that platform calls them. */
|
|
108
|
+
type MessagePlayer = {
|
|
109
|
+
playerId: string;
|
|
110
|
+
displayName: string | null;
|
|
111
|
+
identities: Array<{
|
|
112
|
+
provider: string;
|
|
113
|
+
subject: string;
|
|
114
|
+
name?: string;
|
|
115
|
+
}>;
|
|
116
|
+
};
|
|
117
|
+
/** A group member as a Koishi adapter lists one. */
|
|
118
|
+
type GuildMember = {
|
|
119
|
+
user?: {
|
|
120
|
+
id?: string;
|
|
121
|
+
name?: string;
|
|
122
|
+
nick?: string;
|
|
123
|
+
};
|
|
124
|
+
nick?: string;
|
|
125
|
+
name?: string;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* What the platform writes for a bot to say (PRiSM's core `bot-message.ts`):
|
|
129
|
+
* text, and players the bot names as its chat knows them. A segment of a kind
|
|
130
|
+
* this version does not know is said by its `text`, if it has one.
|
|
131
|
+
*/
|
|
132
|
+
type BotMessage = Array<{
|
|
133
|
+
text?: string;
|
|
134
|
+
player?: MessagePlayer;
|
|
135
|
+
}>;
|
|
136
|
+
/** `say`: something to say, the answer to a command (`replyTo`) or the shop's news. */
|
|
137
|
+
export type SayFrame = {
|
|
138
|
+
type: "say";
|
|
139
|
+
message: BotMessage;
|
|
140
|
+
replyTo?: string;
|
|
141
|
+
to?: string;
|
|
142
|
+
done?: boolean;
|
|
143
|
+
};
|
|
144
|
+
type ChatIdentity = {
|
|
145
|
+
provider: string;
|
|
146
|
+
subject: string;
|
|
147
|
+
name?: string;
|
|
148
|
+
};
|
|
149
|
+
/** A player's command as the platform runs it. */
|
|
150
|
+
type CommandFrame = {
|
|
151
|
+
name: string;
|
|
152
|
+
args: string[];
|
|
153
|
+
from: ChatIdentity;
|
|
154
|
+
target?: ChatIdentity;
|
|
155
|
+
channel: string;
|
|
156
|
+
};
|
|
157
|
+
type SocketReply = {
|
|
158
|
+
status: number;
|
|
159
|
+
body: any;
|
|
160
|
+
serverMs?: number | null;
|
|
153
161
|
};
|
|
154
162
|
/**
|
|
155
|
-
* The one connection to PRiSM.
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
163
|
+
* The one connection to PRiSM. Commands go out as `command` frames and the
|
|
164
|
+
* platform answers with `say` frames naming them; the shop's news comes as
|
|
165
|
+
* `say` frames naming none. While it is down a command fails at once:
|
|
166
|
+
* queueing a checkout or a top-up to run later would make players repeat it.
|
|
159
167
|
*/
|
|
160
168
|
export declare class PrismSocket {
|
|
161
169
|
private readonly open;
|
|
162
|
-
/** Resolved at each connection: the shop is learned from the credential first. */
|
|
163
170
|
private readonly url;
|
|
164
171
|
private readonly token;
|
|
165
|
-
/**
|
|
166
|
-
* What to say in hello, read afresh each time: the bot's settings live on
|
|
167
|
-
* the platform, so they are fetched over this connection before it is
|
|
168
|
-
* sent. Null when they could not be read.
|
|
169
|
-
*/
|
|
172
|
+
/** What to say in hello besides that this bot sends commands. */
|
|
170
173
|
private readonly hello;
|
|
171
|
-
|
|
174
|
+
/** The shop's news: something to say that answers no command. */
|
|
175
|
+
private readonly onNews;
|
|
172
176
|
private readonly logger?;
|
|
173
177
|
/**
|
|
174
178
|
* `onWatch`: the platform asked this bot to watch Home Assistant, or with null to stop.
|
|
@@ -177,24 +181,20 @@ export declare class PrismSocket {
|
|
|
177
181
|
private readonly hooks?;
|
|
178
182
|
private socket;
|
|
179
183
|
private readonly pending;
|
|
184
|
+
/** Commands still being answered, by id. */
|
|
185
|
+
private readonly listening;
|
|
180
186
|
private retryMs;
|
|
181
187
|
private retryTimer;
|
|
182
188
|
private pingTimer;
|
|
183
189
|
private lastHeard;
|
|
184
190
|
private stopped;
|
|
185
191
|
private sequence;
|
|
186
|
-
/** Bumped by every hello being prepared, so only the newest one is sent. */
|
|
187
|
-
private greeting;
|
|
188
192
|
private readonly pongWaiters;
|
|
189
|
-
constructor(open: SocketFactory,
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
* the platform, so they are fetched over this connection before it is
|
|
195
|
-
* sent. Null when they could not be read.
|
|
196
|
-
*/
|
|
197
|
-
hello: () => Promise<Record<string, unknown> | null>, onEvent: (event: PlatformEvent) => void, logger?: {
|
|
193
|
+
constructor(open: SocketFactory, url: string, token: string,
|
|
194
|
+
/** What to say in hello besides that this bot sends commands. */
|
|
195
|
+
hello: () => Record<string, unknown>,
|
|
196
|
+
/** The shop's news: something to say that answers no command. */
|
|
197
|
+
onNews: (say: SayFrame) => void, logger?: {
|
|
198
198
|
warn(...args: unknown[]): void;
|
|
199
199
|
} | undefined,
|
|
200
200
|
/**
|
|
@@ -208,45 +208,33 @@ export declare class PrismSocket {
|
|
|
208
208
|
/** 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. */
|
|
209
209
|
send(frame: Record<string, unknown>): void;
|
|
210
210
|
start(): void;
|
|
211
|
-
/** Connect again with what the platform has just told us, such as the shop. */
|
|
212
|
-
reconnect(): void;
|
|
213
211
|
stop(): void;
|
|
214
212
|
private connect;
|
|
215
|
-
/**
|
|
216
|
-
* Read the bot's settings and say hello with them: on connecting, and again
|
|
217
|
-
* when the platform says they changed. A connection that cannot read them
|
|
218
|
-
* at all is closed and tried again later, without resetting the backoff, so
|
|
219
|
-
* a platform that keeps failing is not asked every second.
|
|
220
|
-
*/
|
|
213
|
+
/** Hello: on connecting, and again when the platform says the bot's settings changed, so it rereads them. */
|
|
221
214
|
private greet;
|
|
222
215
|
private reconnectLater;
|
|
223
216
|
private failPending;
|
|
224
217
|
private receive;
|
|
218
|
+
private nextId;
|
|
219
|
+
/**
|
|
220
|
+
* Send a command; `onSay` hears each thing the platform says for it, or
|
|
221
|
+
* null once the connection is gone. False while the connection is down.
|
|
222
|
+
*/
|
|
223
|
+
command(frame: CommandFrame, onSay: (say: SayFrame | null) => void): boolean;
|
|
225
224
|
/** One heartbeat round trip in milliseconds: the network to the platform and nothing else. */
|
|
226
225
|
ping(): Promise<number>;
|
|
226
|
+
/** A platform route over the connection: the version and the speed tests, which measure exactly that. */
|
|
227
227
|
request(frame: {
|
|
228
|
-
method: "GET" | "POST"
|
|
228
|
+
method: "GET" | "POST";
|
|
229
229
|
path: string;
|
|
230
|
-
query?: Record<string, unknown>;
|
|
231
230
|
body?: unknown;
|
|
232
231
|
}): Promise<SocketReply>;
|
|
233
232
|
}
|
|
234
|
-
type SocketReply = {
|
|
235
|
-
status: number;
|
|
236
|
-
body: any;
|
|
237
|
-
serverMs?: number | null;
|
|
238
|
-
};
|
|
239
233
|
/**
|
|
240
234
|
* The platform connection URL. The credential names the shop, as a device's
|
|
241
235
|
* token names its machine at `/io/ws`, so nothing identifying is in the path.
|
|
242
236
|
*/
|
|
243
237
|
export declare function platformSocketUrl(baseUrl: string): string;
|
|
244
|
-
export type Sender = {
|
|
245
|
-
id: string;
|
|
246
|
-
name: string;
|
|
247
|
-
provider: string;
|
|
248
|
-
};
|
|
249
|
-
export declare function humanReadableBotError(error: PrismBotClientError): string;
|
|
250
238
|
declare const _default: {
|
|
251
239
|
name: string;
|
|
252
240
|
Config: Schema<PrismKoishiPluginConfig>;
|