koishi-plugin-prism 0.3.1 → 0.3.2
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 +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +24 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Koishi 里只填怎么连到店铺:
|
|
|
40
40
|
| 闲置提醒频道、提前分钟 | 闲置自动关机的提醒发到哪里(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`),以及提前几分钟;0 或不填频道则不提醒。 |
|
|
41
41
|
| 门锁 | `lock` 打开的门(带门锁能力的资源);店里只有一扇门时默认就是它。没有门时 `lock` 回复本店还没有设置。 |
|
|
42
42
|
|
|
43
|
-
**店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi
|
|
43
|
+
**店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi 里重复填写。店铺没有整店计费开关。Bot 属于一个资源组,`login`/`入场` 开始的是这个资源组(或 Bot 资源专属)的计费方案;平台下发的 `billingEnabled` 只表示通过这个 Bot 入场是否计费。为 `false` 时 Bot 不请求平台,直接回复「这里不计费,无需入场」;平台拒绝时(例如资源组刚改成免费)回复同样的话。钱包、账单、结账、兑换、上下桌、`list` 等命令属于玩家或各自的资源,跟 Bot 所在资源组无关,一律交给平台处理。旧平台整店未启用计费时返回的 `BILLING_DISABLED` 仍提示「本店未启用计费」。
|
|
44
44
|
|
|
45
45
|
Bot 连上平台后先读取这些设置,再向平台打招呼;网页里改了设置、店员绑定了新身份、增删了麻将桌或门锁时,平台会通知 Bot 重新读取,**不需要重启 Koishi**。
|
|
46
46
|
|
package/lib/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type BotConfig = {
|
|
|
39
39
|
code: string;
|
|
40
40
|
name: string;
|
|
41
41
|
};
|
|
42
|
+
/** Whether entering through this bot bills: its own plan, otherwise its resource group's. */
|
|
42
43
|
billingEnabled: boolean;
|
|
43
44
|
currencyName: string;
|
|
44
45
|
/** Staff are these platform identities. */
|
package/lib/index.js
CHANGED
|
@@ -68,8 +68,8 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
68
68
|
if (gate.effect && bot.settings.playerCommands === "readonly" && !service.isStaff(bot, await service.sender(context))) {
|
|
69
69
|
return quoted(bot.settings.readOnlyNotice || DEFAULT_READ_ONLY_NOTICE);
|
|
70
70
|
}
|
|
71
|
-
if (gate.
|
|
72
|
-
return quoted(
|
|
71
|
+
if (gate.entry && !bot.billingEnabled)
|
|
72
|
+
return quoted(RESOURCE_NOT_BILLED_NOTICE);
|
|
73
73
|
}
|
|
74
74
|
return quoted(await handler(context, ...args));
|
|
75
75
|
}
|
|
@@ -78,28 +78,28 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
const effect = (handler, gate = {}) => wrap(handler, { ...gate, effect: true });
|
|
81
|
-
const
|
|
81
|
+
const entry = { entry: true };
|
|
82
82
|
const bind = wrap(async (context, code) => service.bind(await service.sender(context), code));
|
|
83
83
|
ctx.command("bind <code:string>", "绑定网页登录账号到当前平台身份").action(bind);
|
|
84
84
|
// Instructions already handed to players may still say prism.bind.
|
|
85
85
|
ctx.command("prism.bind <code:string>", "绑定网页登录账号到当前平台身份(旧命令,同 bind)").action(bind);
|
|
86
|
-
ctx.command("login [target:user]", "开启玩家计费场次").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot),
|
|
87
|
-
ctx.command("入场 [target:user]", "入场").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot),
|
|
88
|
-
ctx.command("mahjong <tableId>", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)
|
|
89
|
-
ctx.command("上桌 [tableId]", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)
|
|
90
|
-
ctx.command("下桌 [tableId]", "离开当前所在麻将桌").action(effect(async (context, tableId) => service.mahjongLeave(await service.sender(context), tableId)
|
|
91
|
-
ctx.command("麻将列表", "查看麻将机状态与别名").action(wrap(async () => service.listMahjongTables()
|
|
92
|
-
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)
|
|
93
|
-
ctx.command("billing [target:user]", "预览玩家结账费用").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.billing(sender), context.session?.bot)
|
|
94
|
-
ctx.command("wallet [target:user]", "查看玩家钱包").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.wallet(sender), context.session?.bot)
|
|
86
|
+
ctx.command("login [target:user]", "开启玩家计费场次").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot), entry));
|
|
87
|
+
ctx.command("入场 [target:user]", "入场").action(effect(async (context, target) => service.loginForTarget(await service.sender(context), target, context.session?.bot), entry));
|
|
88
|
+
ctx.command("mahjong <tableId>", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
89
|
+
ctx.command("上桌 [tableId]", "加入指定麻将桌").action(effect(async (context, tableId) => service.mahjongJoin(await service.sender(context), tableId)));
|
|
90
|
+
ctx.command("下桌 [tableId]", "离开当前所在麻将桌").action(effect(async (context, tableId) => service.mahjongLeave(await service.sender(context), tableId)));
|
|
91
|
+
ctx.command("麻将列表", "查看麻将机状态与别名").action(wrap(async () => service.listMahjongTables()));
|
|
92
|
+
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)));
|
|
93
|
+
ctx.command("billing [target:user]", "预览玩家结账费用").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.billing(sender), context.session?.bot)));
|
|
94
|
+
ctx.command("wallet [target:user]", "查看玩家钱包").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.wallet(sender), context.session?.bot)));
|
|
95
95
|
ctx.command("api测速 [count:number]", "测试 Bot 走 HTTP 到 PRiSM 的延迟").action(wrap(async (context, count) => service.benchmarkApi(await service.sender(context), count)));
|
|
96
96
|
ctx.command("ws测速 [count:number]", "测试 Bot 走 WebSocket 到 PRiSM 的延迟").action(wrap(async (context, count) => service.benchmarkWs(await service.sender(context), count)));
|
|
97
97
|
// The Bot's own version stays visible while the platform is out of reach.
|
|
98
98
|
ctx.command("versions", "查看 Bot 与 PRiSM 后端版本").action(wrap(async () => service.versions(), { offline: true }));
|
|
99
|
-
ctx.command("items [target:user]", "查看玩家资产").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.items(sender), context.session?.bot)
|
|
100
|
-
ctx.command("list [name:text]", "查看在店玩家,或某个资源、某个计费方案上的玩家").action(wrap(async (context, name) => service.listActiveSessions(await service.sender(context), name)
|
|
99
|
+
ctx.command("items [target:user]", "查看玩家资产").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.items(sender), context.session?.bot)));
|
|
100
|
+
ctx.command("list [name:text]", "查看在店玩家,或某个资源、某个计费方案上的玩家").action(wrap(async (context, name) => service.listActiveSessions(await service.sender(context), name)));
|
|
101
101
|
ctx.command("show [deviceId]", "查看设备电源状态").action(wrap(async (context, deviceId) => service.listDeviceStates(deviceId)));
|
|
102
|
-
ctx.command("history [target:user]", "查看玩家历史").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.history(sender), context.session?.bot)
|
|
102
|
+
ctx.command("history [target:user]", "查看玩家历史").action(wrap(async (context, target) => service.withTarget(await service.sender(context), target, (sender) => service.history(sender), context.session?.bot)));
|
|
103
103
|
ctx.command("lock", "向本店门锁发送开门指令").action(effect(async (context) => service.lock(await service.sender(context))));
|
|
104
104
|
ctx.command("on <deviceRef>", "请求启动指定设备电源").action(effect(async (context, deviceRef) => service.powerOn(await service.sender(context), deviceRef)));
|
|
105
105
|
ctx.command("off <deviceRef>", "请求关闭指定设备电源").action(effect(async (context, deviceRef) => service.powerOff(await service.sender(context), deviceRef)));
|
|
@@ -108,14 +108,17 @@ function applyPrismKoishiPlugin(ctx, config) {
|
|
|
108
108
|
ctx.command("keep <deviceRef>", "延迟闲置设备的自动关机").action(wrap(async (context, deviceRef) => service.keep(await service.sender(context), deviceRef)));
|
|
109
109
|
ctx.command("coin <deviceRef> [count]", "请求向指定设备投币").action(effect(async (context, deviceRef, count) => service.coin(await service.sender(context), deviceRef, count)));
|
|
110
110
|
ctx.command("scan <deviceRef>", "使用当前玩家绑定的 Aime 卡刷卡").action(effect(async (context, deviceRef) => service.scan(await service.sender(context), deviceRef)));
|
|
111
|
-
ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(await service.sender(context), code)
|
|
112
|
-
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)
|
|
113
|
-
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)
|
|
114
|
-
ctx.command("overwrite <target:user> <amount:number> [reason:text]", "覆盖结账金额并立即结账").action(wrap(async (context, target, amount, reason) => service.overwriteTargetCheckout(await service.sender(context), target, amount, reason, context.session?.bot)
|
|
111
|
+
ctx.command("redeem <code>", "兑换 PRiSM 礼物码").action(wrap(async (context, code) => service.redeem(await service.sender(context), code)));
|
|
112
|
+
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)));
|
|
113
|
+
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)));
|
|
114
|
+
ctx.command("overwrite <target:user> <amount:number> [reason:text]", "覆盖结账金额并立即结账").action(wrap(async (context, target, amount, reason) => service.overwriteTargetCheckout(await service.sender(context), target, amount, reason, context.session?.bot)));
|
|
115
115
|
ctx.on?.("dispose", () => service.dispose());
|
|
116
116
|
}
|
|
117
117
|
const DEFAULT_READ_ONLY_NOTICE = "请扫描店内二维码或碰 NFC,在网页或 App Clip 里入场、结账和操作设备。";
|
|
118
|
+
/** Platforms before per-resource billing refused billing commands shop-wide. */
|
|
118
119
|
const BILLING_DISABLED_NOTICE = "本店未启用计费";
|
|
120
|
+
/** The bot's resource has no plan, so there is nothing to enter. */
|
|
121
|
+
const RESOURCE_NOT_BILLED_NOTICE = "这里不计费,无需入场";
|
|
119
122
|
/* --------------------------- platform connection --------------------------- */
|
|
120
123
|
const SOCKET_OPEN = 1;
|
|
121
124
|
const REQUEST_TIMEOUT_MS = 30_000;
|
|
@@ -1435,6 +1438,8 @@ function humanReadableBotError(error) {
|
|
|
1435
1438
|
return "Bot 已被店铺停用";
|
|
1436
1439
|
if (error.code === "BILLING_DISABLED")
|
|
1437
1440
|
return BILLING_DISABLED_NOTICE;
|
|
1441
|
+
if (error.code === "RESOURCE_NOT_BILLED")
|
|
1442
|
+
return RESOURCE_NOT_BILLED_NOTICE;
|
|
1438
1443
|
if (error.code === "PLAYER_HAS_NO_UNSETTLED_SESSIONS") {
|
|
1439
1444
|
return "您当前没有未结算的账单,无需结账。";
|
|
1440
1445
|
}
|