koishi-plugin-prism 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nerimoe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # koishi-plugin-prism
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-prism.svg)](https://www.npmjs.com/package/koishi-plugin-prism)
4
+
5
+ **koishi-plugin-prism** 是用于连接 **PRiSM Next** 计费与设备管理系统的 Koishi 机器人插件。它可以替代旧版 `plugin-prism-neo-koishi`,为玩家和店员提供便捷的群内与私聊机器人交互指令。
6
+
7
+ ## 🌟 功能特性
8
+
9
+ * 🎮 **玩家入场与结算**:通过 `/login` 和 `/logout` 指令开启或结算计费场次,支持 `/入场` 别名。
10
+ * 💳 **账户钱包与资产管理**:支持查询钱包余额(`/wallet`)和持有的道具资产(`/items`)。
11
+ * 🀄 **麻将桌位集成**:包含 `/mahjong <tableId>` 以及便捷的 `/上桌` / `/下桌` 控制。
12
+ * 🔌 **硬件设备状态与电源管理**:可直接在聊天中查看设备状态(`/show`)、远程开启/关闭电源(`/on`、`/off`)、远程投币(`/coin`)和模拟刷卡(`/scan`)。
13
+ * 🎟️ **礼物兑换码**:使用 `/redeem <code>` 兑换系统发放的福利礼包。
14
+ * 🛠️ **管理员高级指令**:允许管理员在聊天中查看玩家(`/admin.players`)、创建新玩家账户(`/admin.create-player`)、充值余额(`/admin.grant-balance`)、手动结账(`/admin.checkout`)以及制作礼包兑换码(`/admin.redeem-code`)。
15
+
16
+ ## ⚙️ 配置说明
17
+
18
+ 在 Koishi WebUI 的插件配置页面中,填入以下选项:
19
+
20
+ | 配置项 | 类型 | 默认值 | 描述 |
21
+ | :--- | :---: | :---: | :--- |
22
+ | `baseUrl` | `string` | - | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
23
+ | `integrationToken` | `string` | - | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
24
+ | `provider` | `string` | `"qq"` | 当前绑定的账号提供商平台名称(如 `"qq"`,`"discord"`)。 |
25
+ | `autoRegister` | `boolean` | `true` | 当玩家未注册时,是否在首次操作(如入场/查钱包)时自动在 PRiSM 中创建新玩家。 |
26
+ | `loginPricingConfigIds` | `string[]` | `[]` | 默认入场计费规则 ID 列表。 |
27
+ | `loginSessionLabel` | `string` | - | 默认入场会话的备注文本(如 `"音游区间"`)。 |
28
+ | `defaultDoorDeviceId` | `string` | - | 默认门锁设备的 ID,用于开门指令。 |
29
+ | `defaultScanProvider` | `string` | `"aime"` | 默认模拟刷卡时的读卡器协议提供商(如 `"aime"`)。 |
30
+ | `currencyName` | `string` | `"金币"` | 账户货币在显示时的自定义单位名称。 |
31
+ | `resolveDisplayName` | `function` | - | 可选。自定义用于获取群内昵称作为玩家注册名的异步逻辑。 |
32
+ | `enableStaffCommands` | `boolean` | `false` | 是否开启管理员/店员的高级控制指令。 |
33
+ | `staffUserIds` | `string[]` | `[]` | 允许执行管理员指令的平台用户 ID(如 QQ 号)白名单。 |
34
+
35
+ ## 📝 机器人指令列表
36
+
37
+ ### 玩家指令
38
+ * `register` - 绑定或注册当前平台账号到 PRiSM 账户。
39
+ * `login` / `入场` - 开启当前玩家的计费场次。
40
+ * `logout` - 结算当前玩家的计费场次。
41
+ * `billing` - 预览当前玩家本场计费的消费费用。
42
+ * `wallet` - 查看当前玩家的钱包余额。
43
+ * `items` - 查看当前玩家持有的道具或资产。
44
+ * `list` - 查看当前在线/在店游玩玩家的列表。
45
+ * `show [deviceId]` - 查看设备电源与连接状态。
46
+ * `history` - 查看自己的历史游玩记录。
47
+ * `lock` - 发送开门指令。
48
+ * `on <deviceId>` - 请求启动指定设备电源。
49
+ * `off <deviceId>` - 请求关闭指定设备电源。
50
+ * `coin <deviceId> [count]` - 请求向指定设备投币指定枚数。
51
+ * `scan <deviceId> <subject>` - 请求向设备发送模拟刷卡。
52
+ * `redeem <code>` - 兑换礼物码。
53
+ * `mahjong <tableId>` / `上桌 <tableId>` - 加入指定麻将桌。
54
+ * `下桌 <tableId>` - 离开指定麻将桌。
55
+
56
+ ### 管理员指令 (需在白名单内并开启)
57
+ * `admin.players` - 列出系统内注册的所有玩家。
58
+ * `admin.create-player <displayName>` - 创建一个新的 PRiSM 玩家。
59
+ * `admin.grant-balance <playerId> <amount>` - 为指定玩家发放充值余额。
60
+ * `admin.redeem-code <code> <presentId>` - 快速创建单次使用的兑换码。
61
+ * `admin.checkout <playerId>` - 代替并强制为指定玩家结账。
62
+
63
+ ## 🛠️ 本地开发与构建
64
+
65
+ 1. 确保已安装 Node.js 和 `bun`。
66
+ 2. 克隆本仓库:
67
+ ```bash
68
+ git clone https://github.com/nerimoe/koishi-plugin-prism.git
69
+ cd koishi-plugin-prism
70
+ ```
71
+ 3. 安装依赖并执行编译:
72
+ ```bash
73
+ bun install
74
+ bun run build
75
+ ```
76
+ 4. 运行单元测试:
77
+ ```bash
78
+ bun run test
79
+ ```
80
+
81
+ ## 📄 开源协议
82
+
83
+ [MIT License](LICENSE)
@@ -0,0 +1,69 @@
1
+ import { Schema } from "koishi";
2
+ export declare const name = "prism";
3
+ export declare const Config: Schema<PrismKoishiPluginConfig>;
4
+ export declare function apply(ctx: any, config: PrismKoishiPluginConfig): void;
5
+ export declare class PrismBotClientError extends Error {
6
+ readonly code: string;
7
+ readonly status: number;
8
+ readonly body: unknown;
9
+ constructor(message: string, code: string, status: number, body: unknown);
10
+ }
11
+ export type MahjongTableConfig = {
12
+ tableId: string;
13
+ displayName: string;
14
+ aliases: string[];
15
+ pricingConfigIds: string[];
16
+ };
17
+ export type PrismKoishiPluginConfig = {
18
+ provider: string;
19
+ autoRegister: boolean;
20
+ loginPricingConfigIds?: string[];
21
+ loginSessionLabel?: string;
22
+ defaultDoorDeviceId: string;
23
+ defaultScanProvider: string;
24
+ currencyName: string;
25
+ enableStaffCommands?: boolean;
26
+ staffUserIds?: string[];
27
+ mahjongTables?: string;
28
+ mahjongTableSize?: number;
29
+ mahjongLabelPrefix?: string;
30
+ powerOffInterval?: number;
31
+ /**
32
+ * Used by /list to resolve player display names from the chat platform.
33
+ * For Koishi, this should map a QQ subject string to a nickname (e.g. the
34
+ * member list of the current group). If not provided, the plugin will fall
35
+ * back to `playerDisplayName` from the backend.
36
+ */
37
+ resolveDisplayName?: (subject: string) => Promise<string | null | undefined> | string | null | undefined;
38
+ /** Get a stable current ISO timestamp; mainly for tests. */
39
+ now?: () => Date;
40
+ baseUrl?: string;
41
+ integrationToken?: string;
42
+ staffSessionToken?: string;
43
+ client?: any;
44
+ };
45
+ export type KoishiCommandRegistration = {
46
+ description: string;
47
+ action: (context: KoishiActionContext, ...args: string[]) => Promise<string> | string;
48
+ };
49
+ export type KoishiCommandBuilder = {
50
+ action(handler: KoishiCommandRegistration["action"]): KoishiCommandBuilder;
51
+ };
52
+ export type KoishiLikeContext = {
53
+ command(name: string, description: string): KoishiCommandBuilder;
54
+ setInterval?(handler: () => Promise<void> | void, intervalMs: number): void;
55
+ };
56
+ export type KoishiActionContext = {
57
+ session: {
58
+ userId: string;
59
+ senderId?: string;
60
+ senderName?: string;
61
+ };
62
+ };
63
+ export declare function applyPrismKoishiPlugin(ctx: KoishiLikeContext, config: PrismKoishiPluginConfig): void;
64
+ export type Sender = {
65
+ id: string;
66
+ name: string;
67
+ };
68
+ export declare function humanReadableBotError(error: PrismBotClientError): string;
69
+ export declare function parseMahjongTables(value: string, labelPrefix: string): Map<string, MahjongTableConfig>;