koishi-plugin-prism 0.3.4 → 0.4.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 +8 -3
- package/lib/index.d.ts +8 -5
- package/lib/index.js +41 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,9 +37,10 @@ Koishi 里只填怎么连到店铺:
|
|
|
37
37
|
| 开关机失败的原因 | 只说玩家该知道的:没有这个设备、设备未连接、设备已关机、设备没有响应;其余情况统一回「操作没有完成,请找店员」,内部原因只写日志。 |
|
|
38
38
|
| 关机仅限店员 | `off` 只允许店员使用(以店员身份越过入场要求);`on` 始终只允许已入场玩家使用。 |
|
|
39
39
|
| 账单私聊店员 | 玩家退场或店员覆盖结账后,把同一份账单私聊给同一聊天平台上的店员。 |
|
|
40
|
-
| 闲置提醒频道、提前分钟 | 闲置自动关机的提醒发到哪里(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`),以及提前几分钟;0 或不填频道则不提醒。 |
|
|
41
40
|
| 门锁 | `lock` 打开的门(带门锁能力的资源);店里只有一扇门时默认就是它。没有门时 `lock` 回复本店还没有设置。 |
|
|
42
|
-
|
|
|
41
|
+
| 入场后自动获取门锁密码 | 默认关闭。打开后 `login`/`入场` 成功时顺带生成一个 8 位 TTLock 临时密码(有效期 3 分钟)一并回复;门锁失败只多一行提示,不会让入场失败。没有门锁时不生效。 |
|
|
42
|
+
| 播报与提醒 | 只有一处设置:**播报群**(Koishi 的 `平台:频道` 格式,如群 `onebot:群号`、私聊 `onebot:private:QQ号`)和**提醒提前量**(分钟)。闲置提醒和店内动态都发到这一处,不再分成两个群。 |
|
|
43
|
+
| 播报这些 | 五个开关,各自默认关闭:设备闲置(关机前提醒,提前量为 0 时不提醒)、开机/关机(含闲置自动关机)、上机(刷卡或投币后开始占用机台)、刷卡、投币。刷卡或投币同时上机时只发一条:开了「上机」按上机播报,否则按刷卡/投币播报。这个 Bot 自己执行的命令已经回复过,不再播报;别的 Bot、网页和机台上发生的照常播报。下机不播报。 |
|
|
43
44
|
|
|
44
45
|
**店员**是在这家店工作、并在网页里绑定了聊天平台身份的人:Bot 按「平台 + 账号」认人,`onebot:114514` 是店员不代表 `telegram:114514` 也是。**货币名称**取店铺的余额资产名,**麻将桌**和**门锁**取店铺的资源,都不需要在 Koishi 里重复填写。店铺没有整店计费开关。Bot 属于一个资源组,`login`/`入场` 开始的是这个资源组(或 Bot 资源专属)的计费方案;平台下发的 `billingEnabled` 只表示通过这个 Bot 入场是否计费。为 `false` 时 Bot 不请求平台,直接回复「这里不计费,无需入场」;平台拒绝时(例如资源组刚改成免费)回复同样的话。钱包、账单、结账、兑换、上下桌、`list` 等命令属于玩家或各自的资源,跟 Bot 所在资源组无关,一律交给平台处理。旧平台整店未启用计费时返回的 `BILLING_DISABLED` 仍提示「本店未启用计费」。
|
|
45
46
|
|
|
@@ -70,7 +71,7 @@ Bot 一直在线,所以平台会优先让 Bot 当店铺的 Home Assistant **
|
|
|
70
71
|
|
|
71
72
|
### 玩家指令
|
|
72
73
|
* `bind <验证码>` - 把网页登录账号绑定到当前平台身份(旧命令 `prism.bind` 仍可用)。玩家第一次绑定时是否自动建档由店铺设置决定,原来的 `register` 命令已移除。
|
|
73
|
-
* `login` / `入场` - 开启当前玩家的计费场次:开始这个 Bot 在 PRiSM 里的计费方案(资源编辑页「计费」一节设置所属资源组或专属方案)。
|
|
74
|
+
* `login` / `入场` - 开启当前玩家的计费场次:开始这个 Bot 在 PRiSM 里的计费方案(资源编辑页「计费」一节设置所属资源组或专属方案)。Bot 设置开了「入场后自动获取门锁密码」时,成功入场后会再回复一条门锁临时密码。
|
|
74
75
|
* `logout` - 结算当前玩家的计费场次。
|
|
75
76
|
玩家在未产生任何费用时退场,机器人会简洁显示“本次未产生费用”和当前余额;存在收费或优惠明细时仍显示完整结算账单。负单价 session 会在区间明细中保留真实的负数计费贡献,只有后端汇总全部 session 后的最终应付金额会限制为不低于 `0`。
|
|
76
77
|
结账成功回执中的余额为后端已经完成扣款后的余额;只有 `/billing` 预览会显示当前余额与预计结账后余额。
|
|
@@ -154,6 +155,10 @@ npm version minor --no-git-tag-version
|
|
|
154
155
|
|
|
155
156
|
绑定支持 Koishi 提供的各适配器标识,身份值保持字符串,不限定数字格式。店员和账单私聊按「平台标识 + 身份值」认人,相同号码的其他平台不会继承权限或通知。管理员代操作使用目标平台标识,禁止通过当前适配器误操作另一个平台。`/list` 只用当前平台的身份查询昵称,缺失时使用后台名称。源码和 npm 发行包需要分别核对版本。
|
|
156
157
|
|
|
158
|
+
### 0.4.0
|
|
159
|
+
|
|
160
|
+
闲置提醒与店内动态合并成一件事:Bot 只有一处「播报群」(`announceChannelIds`),以及五种各自独立的播报开关——设备闲置、开机/关机(含闲置自动关机)、上机、刷卡、投币;频道不再是区分两类消息的依据。投币从「上机」里分出来单独播报,投币同时上机时仍只发一条,按「上机」的措辞。新增 Bot 设置「入场后自动获取门锁密码」(`doorPasswordOnEntry`,默认关闭):打开后 `login`/`入场` 成功后顺带回复门锁临时密码,门锁失败不影响入场。需要配套 PRiSM(平台侧迁移 `0046_bot_announcement_channels.sql`),旧版平台下发的 `idleChannelIds`/`eventChannelIds` 不再被读取,升级平台前不要升级到此版本。
|
|
161
|
+
|
|
157
162
|
### 0.3.0
|
|
158
163
|
|
|
159
164
|
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 升级之前不要升级到此版本。
|
package/lib/index.d.ts
CHANGED
|
@@ -29,15 +29,18 @@ export type BotConfig = {
|
|
|
29
29
|
powerOffStaffOnly: boolean;
|
|
30
30
|
/** Staff on the same platform get checkout receipts privately. */
|
|
31
31
|
receiptsToStaff: boolean;
|
|
32
|
-
/**
|
|
33
|
-
|
|
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[];
|
|
34
36
|
/** How many minutes before an idle power-off to tell them; 0 for never. */
|
|
35
37
|
idleReminderMinutes: number;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
+
/** Which news is told, each on its own. */
|
|
39
|
+
announceIdle: boolean;
|
|
38
40
|
announcePower: boolean;
|
|
39
|
-
announceCards: boolean;
|
|
40
41
|
announceStarts: boolean;
|
|
42
|
+
announceCards: boolean;
|
|
43
|
+
announceCoins: boolean;
|
|
41
44
|
};
|
|
42
45
|
/** Which shop this credential belongs to; the shop code is no longer configured by hand. */
|
|
43
46
|
shop?: {
|
package/lib/index.js
CHANGED
|
@@ -709,8 +709,11 @@ class PrismKoishiService {
|
|
|
709
709
|
name: bot.bot.name,
|
|
710
710
|
// Saying so is what makes the platform consider this bot for the watch.
|
|
711
711
|
...(this.watching ? { ha: true } : {}),
|
|
712
|
-
// Without anywhere to send it,
|
|
713
|
-
|
|
712
|
+
// Without anywhere to send it, or with idle news switched off, the
|
|
713
|
+
// platform need not plan a reminder.
|
|
714
|
+
...(settings.announceIdle && settings.announceChannelIds.length && settings.idleReminderMinutes > 0
|
|
715
|
+
? { reminderLeadSeconds: settings.idleReminderMinutes * 60 }
|
|
716
|
+
: {}),
|
|
714
717
|
};
|
|
715
718
|
}
|
|
716
719
|
/** Whether the sender is one of the shop's staff on this platform. */
|
|
@@ -731,12 +734,13 @@ class PrismKoishiService {
|
|
|
731
734
|
/**
|
|
732
735
|
* Tell the configured channels what happened, if this bot announces that kind
|
|
733
736
|
* of thing. A card that put its owner on the cabinet is one message: a start
|
|
734
|
-
* when starts are announced, otherwise a card
|
|
735
|
-
* did is left out: the bot has answered the
|
|
737
|
+
* when starts are announced, otherwise a card; a coin that did is the same.
|
|
738
|
+
* What this bot's own command did is left out: the bot has answered the
|
|
739
|
+
* command already.
|
|
736
740
|
*/
|
|
737
741
|
async announce(event) {
|
|
738
742
|
const bot = this.bot;
|
|
739
|
-
const channels = bot?.settings.
|
|
743
|
+
const channels = bot?.settings.announceChannelIds ?? [];
|
|
740
744
|
if (!bot || !channels.length || typeof this.ctx.broadcast !== "function")
|
|
741
745
|
return;
|
|
742
746
|
if (event.botId && event.botId === bot.bot.id)
|
|
@@ -777,14 +781,20 @@ class PrismKoishiService {
|
|
|
777
781
|
return `🎮 ${await who()} 在 ${place} 刷卡上机`;
|
|
778
782
|
return settings.announceCards ? `💳 ${await who()} 在 ${place} 刷卡` : null;
|
|
779
783
|
}
|
|
784
|
+
if (event.kind === "coin") {
|
|
785
|
+
if (event.started && settings.announceStarts)
|
|
786
|
+
return `🎮 ${await who()} 在 ${place} 投币上机`;
|
|
787
|
+
return settings.announceCoins ? `🪙 ${await who()} 在 ${place} 投币` : null;
|
|
788
|
+
}
|
|
780
789
|
if (event.kind === "occupancy")
|
|
781
790
|
return settings.announceStarts ? `🎮 ${await who()} 在 ${place} 上机` : null;
|
|
782
791
|
return null;
|
|
783
792
|
}
|
|
784
|
-
/** Tell the configured channels a power-off is coming
|
|
793
|
+
/** Tell the configured channels a power-off is coming, when the shop asks for it. */
|
|
785
794
|
async remindIdle(reminder) {
|
|
786
|
-
const
|
|
787
|
-
|
|
795
|
+
const settings = this.bot?.settings;
|
|
796
|
+
const channels = settings?.announceChannelIds ?? [];
|
|
797
|
+
if (!settings?.announceIdle || !channels.length || typeof this.ctx.broadcast !== "function")
|
|
788
798
|
return;
|
|
789
799
|
const now = (this.options.now?.() ?? new Date()).getTime();
|
|
790
800
|
const minutes = Math.max(1, Math.round((reminder.at - now) / 60_000));
|
|
@@ -827,7 +837,13 @@ class PrismKoishiService {
|
|
|
827
837
|
// Starting the plan may end one it cannot bill together with.
|
|
828
838
|
const stopped = Array.isArray(result?.billing?.stopped) ? result.billing.stopped.filter((name) => typeof name === "string" && name) : [];
|
|
829
839
|
const ended = stopped.length ? `\n结束方案:${stopped.join("、")}` : "";
|
|
830
|
-
|
|
840
|
+
const message = (isTargeted ? `✅ 已为用户 ${formatPlayerReference(sender)} 入场成功` : "✅ 入场成功") + ended;
|
|
841
|
+
// Entering and getting the door code as one command, when the shop asks
|
|
842
|
+
// for it. A door that fails must not undo an entry that succeeded.
|
|
843
|
+
const settings = (await this.config());
|
|
844
|
+
return settings.settings.doorPasswordOnEntry && settings.door
|
|
845
|
+
? `${message}\n${await this.doorCode(sender, settings.door, true)}`
|
|
846
|
+
: message;
|
|
831
847
|
}, bot);
|
|
832
848
|
}
|
|
833
849
|
async withTarget(actor, targetSubject, action, bot) {
|
|
@@ -1093,6 +1109,14 @@ class PrismKoishiService {
|
|
|
1093
1109
|
const door = (await this.config()).door;
|
|
1094
1110
|
if (!door)
|
|
1095
1111
|
return "🔑 本店还没有设置 Bot 开的门";
|
|
1112
|
+
return this.doorCode(sender, door, false);
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* The door code, or why there is none. `onEntry` marks the copy that rides
|
|
1116
|
+
* along with a successful entry: there the failure is said in one line and
|
|
1117
|
+
* never takes the entry down with it.
|
|
1118
|
+
*/
|
|
1119
|
+
async doorCode(sender, door, onEntry) {
|
|
1096
1120
|
try {
|
|
1097
1121
|
const result = await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
|
|
1098
1122
|
type: "door.open",
|
|
@@ -1101,19 +1125,19 @@ class PrismKoishiService {
|
|
|
1101
1125
|
const failure = this.getCommandFailureMessage(result);
|
|
1102
1126
|
if (failure) {
|
|
1103
1127
|
this.logDeviceCommandFailure(result);
|
|
1104
|
-
return `🔑 开门失败,${deviceCommandFailureReason(result)}`;
|
|
1128
|
+
return onEntry ? "🔑 门锁临时密码没有生成,可以在入场后用 lock 再取一次" : `🔑 开门失败,${deviceCommandFailureReason(result)}`;
|
|
1105
1129
|
}
|
|
1106
1130
|
if (result?.action?.executorKind && result.action.executorKind !== "ttlock") {
|
|
1107
1131
|
return "🔑 门锁指令已发送";
|
|
1108
1132
|
}
|
|
1109
1133
|
const password = cleanText(result?.action?.payload?.temporaryPassword);
|
|
1110
1134
|
if (!password)
|
|
1111
|
-
return "🔑 临时门锁密码生成失败,请稍后再试";
|
|
1135
|
+
return onEntry ? "🔑 门锁临时密码没有生成,可以在入场后用 lock 再取一次" : "🔑 临时门锁密码生成失败,请稍后再试";
|
|
1112
1136
|
return `🔑 临时门锁密码:${password}\n有效期:3 分钟`;
|
|
1113
1137
|
}
|
|
1114
1138
|
catch (error) {
|
|
1115
1139
|
this.logCommandError(error);
|
|
1116
|
-
return `🔑 开门失败,${deviceActionFailureReason(error)}`;
|
|
1140
|
+
return onEntry ? "🔑 门锁临时密码没有生成,可以在入场后用 lock 再取一次" : `🔑 开门失败,${deviceActionFailureReason(error)}`;
|
|
1117
1141
|
}
|
|
1118
1142
|
}
|
|
1119
1143
|
async powerOn(sender, rawDeviceRef) {
|
|
@@ -1637,12 +1661,14 @@ function parseBotConfig(value) {
|
|
|
1637
1661
|
staffCommands: settings.staffCommands !== false,
|
|
1638
1662
|
powerOffStaffOnly: settings.powerOffStaffOnly === true,
|
|
1639
1663
|
receiptsToStaff: settings.receiptsToStaff === true,
|
|
1640
|
-
|
|
1664
|
+
doorPasswordOnEntry: settings.doorPasswordOnEntry === true,
|
|
1665
|
+
announceChannelIds: strings(settings.announceChannelIds),
|
|
1641
1666
|
idleReminderMinutes: Math.max(0, Number(settings.idleReminderMinutes ?? 5) || 0),
|
|
1642
|
-
|
|
1667
|
+
announceIdle: settings.announceIdle === true,
|
|
1643
1668
|
announcePower: settings.announcePower === true,
|
|
1644
|
-
announceCards: settings.announceCards === true,
|
|
1645
1669
|
announceStarts: settings.announceStarts === true,
|
|
1670
|
+
announceCards: settings.announceCards === true,
|
|
1671
|
+
announceCoins: settings.announceCoins === true,
|
|
1646
1672
|
},
|
|
1647
1673
|
billingEnabled: record.billingEnabled !== false,
|
|
1648
1674
|
currencyName: cleanText(record.currencyName) || "余额",
|