koishi-plugin-prism 0.1.38 → 0.1.40
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 +32 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +42 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
| 配置项 | 类型 | 默认值 | 描述 |
|
|
23
23
|
| :--- | :---: | :---: | :--- |
|
|
24
24
|
| `baseUrl` | `string` | - | **必填**。PRiSM Next Server 的访问基准 URL(如 `https://prism-mmw.neri.moe`)。 |
|
|
25
|
+
| `shopCode` | `string` | - | 统一平台的店铺公开编号;单店兼容部署留空。 |
|
|
25
26
|
| `integrationToken` | `string` | - | **必填**。从 PRiSM 网页后台生成的 Integration API 令牌。 |
|
|
26
27
|
| `provider` | `string` | `"qq"` | 当前绑定的账号提供商平台名称(如 `"qq"`,`"discord"`)。 |
|
|
27
28
|
| `autoRegister` | `boolean` | `true` | 当玩家未注册时,是否在首次操作(如入场/查钱包)时自动在 PRiSM 中创建新玩家。 |
|
|
@@ -37,6 +38,14 @@
|
|
|
37
38
|
| `logoutNotifyUserIds` | `string[]` | `[]` | 结账成功后额外私聊完整账单的平台用户 ID。通知收件人为该列表与 `staffUserIds` 的去重并集。 |
|
|
38
39
|
| `mahjongTableConfigs` | `object[]` | `[]` | 推荐的结构化麻将桌列表。每项填写显示名称、命令别名列表与计费方案 ID 列表。显示名称同时作为内部桌位锚点与 session 标签。 |
|
|
39
40
|
|
|
41
|
+
### 统一平台
|
|
42
|
+
|
|
43
|
+
配置 `baseUrl`、`shopCode` 和本店的 Integration 令牌后,插件调用 `/api/v1/shops/:shopCode/integration`;单店兼容部署调用 `/api/v1/integration`。
|
|
44
|
+
|
|
45
|
+
玩家在网页取得验证码后,向 Bot 发送 `prism.bind 验证码`。绑定使用消息发送人的 QQ,不接受代填 QQ。允许哪些群或私聊使用此指令,由店家在 Bot 框架中配置过滤;后端和插件不再维护群白名单或群聊/私聊限制。网页账号可以跨店使用,QQ 验证和余额分别属于各店;默认只允许绑定本店已有玩家,店主可以开启新玩家注册。
|
|
46
|
+
|
|
47
|
+
统一平台以店铺的入场规则和注册开关为准。Web 与 Bot 普通入场共享去重;显式的麻将规则继续使用桌位流程。店铺启用入场、出场或机器操作定位时,对应 Bot 操作会返回本店网页地址。玩家余额不足时结账失败并继续计时。
|
|
48
|
+
|
|
40
49
|
### 麻将桌配置
|
|
41
50
|
|
|
42
51
|
在 Koishi 配置页的 `mahjongTableConfigs` 中新增桌位,每一项填写:
|
|
@@ -109,6 +118,29 @@ Bot 版本直接读取本 npm 包的 `package.json`,后端版本读取无需
|
|
|
109
118
|
bun run test
|
|
110
119
|
```
|
|
111
120
|
|
|
121
|
+
### CI 自动发布
|
|
122
|
+
|
|
123
|
+
发布使用 GitHub Actions 的 npm Trusted Publishing。修改版本后推送带 `v` 前缀且与 `package.json` 一致的标签即可自动测试、构建并发布:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm version patch
|
|
127
|
+
git push origin main --follow-tags
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
首次使用前,在 npm 包设置的 Trusted Publisher 中选择 GitHub Actions,填写仓库 `nerimoe/koishi-plugin-prism` 和工作流文件名 `publish.yml`,并允许 `npm publish`。
|
|
131
|
+
|
|
112
132
|
## 📄 开源协议
|
|
113
133
|
|
|
114
134
|
[MIT License](LICENSE)
|
|
135
|
+
|
|
136
|
+
统一平台支持 QQ 绑定、查人以及原有计费/设备命令。持有有效店铺 Integration 令牌的 Bot 不受玩家定位和扫码入口限制;玩家身份、入场要求、投币冷却及插件员工权限仍保留。查人合并后端持久化麻将名单和旧 Bot 桌位记录。普通入场的 `entry` 标签兼容旧 `loginSessionLabel`,不会误拒绝已入场玩家上桌。
|
|
137
|
+
|
|
138
|
+
2026-09-13 使用 Koishi 4.18.11 实际命令解析和本地 HTTP,对已有 MMW prism-next 快照运行旧新版对比:18 名在店玩家的账单/钱包/资产/历史与查人共 73 次查询文本一致;另测试入退场、四人麻将、余额调整、兑换、开关机、门锁、投币冷却、重复刷卡、离线和权限拒绝。QQ 消息本地注入,硬件使用本地模拟服务,不代表真实 QQ 投递或物理硬件验收。
|
|
139
|
+
|
|
140
|
+
### QQ 绑定与查人验收
|
|
141
|
+
|
|
142
|
+
QQ 绑定支持 Koishi 的 `qq` 和 `onebot` 平台,发送人 ID 必须是 QQ 号码;群/私聊过滤仍交给 Koishi。`/list` 使用店铺作用域接口并兼容 data 响应封装,人数统计包括尚未开局的麻将等待玩家,按玩家 ID 去重。只通过源码测试不能证明运行中的 Bot 已更新;npm 发行版与分支提交需要分别核对。
|
|
143
|
+
|
|
144
|
+
### 0.1.39
|
|
145
|
+
|
|
146
|
+
支持统一平台店铺 API、QQ/OneBot 绑定和麻将查人统计;兼容新版入场标签,修复已入场玩家无法通过 Bot 上桌的问题。
|
package/lib/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type PrismKoishiPluginConfig = {
|
|
|
41
41
|
resolveDisplayName?: (subject: string) => Promise<string | null | undefined> | string | null | undefined;
|
|
42
42
|
/** Get a stable current ISO timestamp; mainly for tests. */
|
|
43
43
|
now?: () => Date;
|
|
44
|
+
shopCode?: string;
|
|
44
45
|
baseUrl?: string;
|
|
45
46
|
integrationToken?: string;
|
|
46
47
|
client?: any;
|
|
@@ -61,6 +62,8 @@ export type KoishiLikeContext = {
|
|
|
61
62
|
};
|
|
62
63
|
export type KoishiActionContext = {
|
|
63
64
|
session: {
|
|
65
|
+
platform?: string;
|
|
66
|
+
isDirect?: boolean;
|
|
64
67
|
userId: string;
|
|
65
68
|
messageId?: string;
|
|
66
69
|
senderId?: string;
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.version = package_json_1.default.version;
|
|
|
15
15
|
exports.Config = koishi_1.Schema.object({
|
|
16
16
|
provider: koishi_1.Schema.string().required().description("平台提供商 (如 qq)"),
|
|
17
17
|
autoRegister: koishi_1.Schema.boolean().default(true).description("是否自动注册"),
|
|
18
|
+
shopCode: koishi_1.Schema.string().description("统一平台店铺编号(单店兼容模式留空)"),
|
|
18
19
|
baseUrl: koishi_1.Schema.string().description("PRiSM 后端 API Base URL"),
|
|
19
20
|
integrationToken: koishi_1.Schema.string().role("secret").description("集成 API Token"),
|
|
20
21
|
currencyName: koishi_1.Schema.string().default("猫粮").description("代币名称"),
|
|
@@ -78,6 +79,20 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
78
79
|
return context.session?.messageId ? `${(0, koishi_1.h)("quote", { id: context.session.messageId })}${message}` : message;
|
|
79
80
|
}
|
|
80
81
|
};
|
|
82
|
+
ctx.command("prism.bind <code:string>", "绑定网页登录账号到本店 QQ 身份").action(wrap(async (context, code) => {
|
|
83
|
+
if (!["qq", "onebot"].includes(context.session.platform ?? ""))
|
|
84
|
+
return "请使用 QQ 身份发送验证码";
|
|
85
|
+
if (!/^[1-9]\d{4,19}$/.test(context.session.userId ?? ""))
|
|
86
|
+
return "无法获取发送人的 QQ 号";
|
|
87
|
+
if (!config.shopCode || !config.baseUrl || !config.integrationToken)
|
|
88
|
+
return "请店家配置统一平台店铺编号与 Bot 凭据";
|
|
89
|
+
const response = await fetch(`${config.baseUrl.replace(/\/+$/, "")}/api/v1/shops/${encodeURIComponent(config.shopCode)}/integration/qq-binding/confirm`, {
|
|
90
|
+
method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${config.integrationToken}` },
|
|
91
|
+
body: JSON.stringify({ code, qq: context.session.userId }),
|
|
92
|
+
});
|
|
93
|
+
const body = await response.json();
|
|
94
|
+
return response.ok ? "绑定成功,请返回网页继续操作" : body.error?.message ?? "绑定失败,请重新生成验证码";
|
|
95
|
+
}));
|
|
81
96
|
ctx.command("register", "绑定或注册当前平台用户到 PRiSM").action(wrap(async (context) => service.register(await service.sender(context))));
|
|
82
97
|
ctx.command("login [target:user]", "开启玩家计费场次").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
83
98
|
ctx.command("入场 [target:user]", "入场").action(wrap(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot)));
|
|
@@ -126,7 +141,7 @@ class PrismApiClient {
|
|
|
126
141
|
};
|
|
127
142
|
}
|
|
128
143
|
async request(method, path, options) {
|
|
129
|
-
let url = path;
|
|
144
|
+
let url = path.replace(/^\/rpc\//, this.config.shopCode ? `/api/v1/shops/${encodeURIComponent(this.config.shopCode)}/` : "/api/v1/");
|
|
130
145
|
if (options.params) {
|
|
131
146
|
for (const [key, value] of Object.entries(options.params)) {
|
|
132
147
|
url = url.replace(`:${key}`, encodeURIComponent(String(value)));
|
|
@@ -154,7 +169,7 @@ class PrismApiClient {
|
|
|
154
169
|
else {
|
|
155
170
|
throw new Error(`Unsupported method ${method}`);
|
|
156
171
|
}
|
|
157
|
-
return response;
|
|
172
|
+
return response && typeof response === "object" && Object.hasOwn(response, "data") ? response.data : response;
|
|
158
173
|
}
|
|
159
174
|
catch (error) {
|
|
160
175
|
if (error?.response) {
|
|
@@ -349,6 +364,7 @@ class PrismKoishiService {
|
|
|
349
364
|
};
|
|
350
365
|
this.client = new PrismApiClient(http, {
|
|
351
366
|
baseUrl: config.baseUrl,
|
|
367
|
+
shopCode: config.shopCode,
|
|
352
368
|
integrationToken: config.integrationToken,
|
|
353
369
|
});
|
|
354
370
|
}
|
|
@@ -749,7 +765,20 @@ class PrismKoishiService {
|
|
|
749
765
|
const players = groupSessionsByPlayer(sessions);
|
|
750
766
|
const groups = await this.buildPlayerGroups(players, tableByLabel);
|
|
751
767
|
this.mergeWaitingSeats(groups);
|
|
752
|
-
|
|
768
|
+
const tables = result.mahjongTables;
|
|
769
|
+
if (!tables)
|
|
770
|
+
return formatPlayerGroups(groups, this.config.mahjongTableSize ?? 4);
|
|
771
|
+
const seated = new Set(tables.flatMap(table => table.players.map(player => player.id)));
|
|
772
|
+
for (const group of groups.groups)
|
|
773
|
+
group.players = group.players.filter(player => !seated.has(player.playerId));
|
|
774
|
+
return [
|
|
775
|
+
formatPlayerGroups(groups, this.config.mahjongTableSize ?? 4, new Set([
|
|
776
|
+
...seated, ...groups.groups.flatMap(group => group.players.map(player => player.playerId)),
|
|
777
|
+
]).size),
|
|
778
|
+
...tables.map(table => `
|
|
779
|
+
${table.name}(${table.players.length}/${table.capacity}):
|
|
780
|
+
${table.players.map(player => player.name).join("、")}`),
|
|
781
|
+
].filter(Boolean).join("\n");
|
|
753
782
|
}
|
|
754
783
|
async listDeviceStates(rawAlias) {
|
|
755
784
|
const alias = cleanText(rawAlias);
|
|
@@ -758,7 +787,7 @@ class PrismKoishiService {
|
|
|
758
787
|
if (states.length === 0)
|
|
759
788
|
return "没有找到任何设备状态。";
|
|
760
789
|
if (alias) {
|
|
761
|
-
const matched = states.find((d) => d.deviceId === alias || d.label === alias);
|
|
790
|
+
const matched = states.find((d) => d.deviceId === alias || d.label === alias || d.aliases?.some((value) => value.trim().toLowerCase() === alias.toLowerCase()));
|
|
762
791
|
if (!matched)
|
|
763
792
|
return `找不到设备: ${alias}`;
|
|
764
793
|
const stateVal = normalizeDeviceState(matched.state);
|
|
@@ -850,10 +879,10 @@ class PrismKoishiService {
|
|
|
850
879
|
const musicLabel = this.config.loginSessionLabel?.trim() || "音游区间";
|
|
851
880
|
for (const player of players.values()) {
|
|
852
881
|
player.displayName = await this.displayNameForPlayer(player);
|
|
853
|
-
const nonMusic = player.sessions.filter((session) => Boolean(session.label) && session.label !== musicLabel);
|
|
882
|
+
const nonMusic = player.sessions.filter((session) => Boolean(session.label) && session.label !== "entry" && session.label !== musicLabel);
|
|
854
883
|
const source = nonMusic.length > 0 ? nonMusic : player.sessions;
|
|
855
884
|
const selected = source.reduce((latest, session) => !latest || sessionStartedAt(session) > sessionStartedAt(latest) ? session : latest, undefined);
|
|
856
|
-
const label = selected?.label || musicLabel;
|
|
885
|
+
const label = selected?.label === "entry" ? musicLabel : selected?.label || musicLabel;
|
|
857
886
|
let group = groupByLabel.get(label);
|
|
858
887
|
if (!group) {
|
|
859
888
|
group = { label, table: tableByLabel.get(label), players: [] };
|
|
@@ -951,7 +980,7 @@ class PrismKoishiService {
|
|
|
951
980
|
}
|
|
952
981
|
hasEntrySession(playerId, sessions) {
|
|
953
982
|
const label = this.config.loginSessionLabel?.trim();
|
|
954
|
-
return sessions.some((session) => session.playerId === playerId && (label ? session.label === label : true));
|
|
983
|
+
return sessions.some((session) => session.playerId === playerId && (session.label === "entry" || (label ? session.label === label : true)));
|
|
955
984
|
}
|
|
956
985
|
identity(sender) {
|
|
957
986
|
return {
|
|
@@ -1036,7 +1065,7 @@ class PrismKoishiService {
|
|
|
1036
1065
|
lines.push(`⏰ 游玩时间:${formatHM(overallStart)}–${formatHM(overallEnd)}`);
|
|
1037
1066
|
}
|
|
1038
1067
|
for (const sPrev of sessionPreviews) {
|
|
1039
|
-
const label = sPrev?.label || "计时区间";
|
|
1068
|
+
const label = sPrev?.label === "entry" ? this.config.loginSessionLabel?.trim() || "音游区间" : sPrev?.label || "计时区间";
|
|
1040
1069
|
const startDt = parseDateTime(sPrev?.startedAt);
|
|
1041
1070
|
const endDt = sessionDisplayEnd(sPrev, previewedAt);
|
|
1042
1071
|
const status = sPrev?.status ?? "active";
|
|
@@ -1114,6 +1143,9 @@ class PrismKoishiService {
|
|
|
1114
1143
|
handleCommandError(error) {
|
|
1115
1144
|
this.logCommandError(error);
|
|
1116
1145
|
if (error instanceof PrismBotClientError) {
|
|
1146
|
+
if (error.code?.startsWith("LOCATION_") && this.config.shopCode && this.config.baseUrl) {
|
|
1147
|
+
return `请在网页完成到店校验:${this.config.baseUrl.replace(/\/+$/, "")}/t/${encodeURIComponent(this.config.shopCode)}`;
|
|
1148
|
+
}
|
|
1117
1149
|
return humanReadableBotError(error);
|
|
1118
1150
|
}
|
|
1119
1151
|
return genericCommandFailure();
|
|
@@ -1256,9 +1288,9 @@ function sessionStartedAt(session) {
|
|
|
1256
1288
|
const value = Date.parse(session.startedAt ?? "");
|
|
1257
1289
|
return Number.isFinite(value) ? value : 0;
|
|
1258
1290
|
}
|
|
1259
|
-
function formatPlayerGroups(groups, tableSize) {
|
|
1291
|
+
function formatPlayerGroups(groups, tableSize, totalPlayers) {
|
|
1260
1292
|
const populatedGroups = groups.groups.filter((group) => group.players.length > 0);
|
|
1261
|
-
const total = new Set(populatedGroups.flatMap((group) => group.players.map((player) => player.playerId))).size;
|
|
1293
|
+
const total = totalPlayers ?? new Set(populatedGroups.flatMap((group) => group.players.map((player) => player.playerId))).size;
|
|
1262
1294
|
if (total === 0)
|
|
1263
1295
|
return "🫥 窝里目前没有玩家呢";
|
|
1264
1296
|
const lines = [`[总计 ${total} 人]`];
|