koishi-plugin-prism 0.1.20 → 0.1.22
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 -0
- package/lib/index.js +31 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
57
57
|
* `logout` - 结算当前玩家的计费场次。
|
|
58
58
|
玩家在未产生任何费用时退场,机器人会简洁显示“本次未产生费用”和当前余额;存在收费或优惠明细时仍显示完整结算账单。
|
|
59
59
|
结账成功后,机器人会向 `staffUserIds` 与 `logoutNotifyUserIds` 中的用户私聊同一份账单,账单会明确显示结账玩家身份。
|
|
60
|
+
同一玩家在前一次退场结账尚未完成时重复发送 `/logout` 或 `/退场`,机器人会复用同一次结账请求与账单,避免重复扣款。
|
|
60
61
|
账单和管理员代操作回执均使用“平台昵称(QQ:号码)”称呼玩家;平台暂时无法提供昵称时显示“未知昵称(QQ:号码)”,不会显示内部玩家 ID。
|
|
61
62
|
管理员 `/add` 增加免费余额;`/del` 按结账相同的顺序从可用免费余额、再从付费余额扣除,余额不足时会返回余额不足提示。
|
|
62
63
|
* `billing` - 预览当前玩家本场计费的消费费用。
|
package/lib/index.js
CHANGED
|
@@ -217,10 +217,10 @@ class PrismApiClient {
|
|
|
217
217
|
body: this.identityBody(identity),
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
async confirmCheckoutByIdentity(identity) {
|
|
220
|
+
async confirmCheckoutByIdentity(identity, closeSessionsBeforeBalanceCheck = true) {
|
|
221
221
|
return this.request("POST", "/rpc/integration/players/by-identity/checkout/confirm", {
|
|
222
222
|
token: this.config.integrationToken,
|
|
223
|
-
body: this.identityBody(identity),
|
|
223
|
+
body: { ...this.identityBody(identity), closeSessionsBeforeBalanceCheck },
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
async redeemCodeByIdentity(identity, code) {
|
|
@@ -297,6 +297,7 @@ class PrismApiClient {
|
|
|
297
297
|
class PrismKoishiService {
|
|
298
298
|
config;
|
|
299
299
|
mahjongTables = new Map();
|
|
300
|
+
logoutInFlight = new Map();
|
|
300
301
|
client;
|
|
301
302
|
constructor(ctx, config) {
|
|
302
303
|
this.config = config;
|
|
@@ -490,7 +491,21 @@ class PrismKoishiService {
|
|
|
490
491
|
return this.formatCheckoutPreview(result, sender);
|
|
491
492
|
}
|
|
492
493
|
async logout(sender, bot) {
|
|
493
|
-
const
|
|
494
|
+
const existing = this.logoutInFlight.get(sender.id);
|
|
495
|
+
if (existing)
|
|
496
|
+
return existing;
|
|
497
|
+
const task = this.performLogout(sender, bot);
|
|
498
|
+
this.logoutInFlight.set(sender.id, task);
|
|
499
|
+
try {
|
|
500
|
+
return await task;
|
|
501
|
+
}
|
|
502
|
+
finally {
|
|
503
|
+
if (this.logoutInFlight.get(sender.id) === task)
|
|
504
|
+
this.logoutInFlight.delete(sender.id);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
async performLogout(sender, bot) {
|
|
508
|
+
const result = (await this.client.confirmCheckoutByIdentity(this.identity(sender), false));
|
|
494
509
|
const settlement = result?.playerSettlement ?? result?.settlement ?? {};
|
|
495
510
|
const records = result?.settlements ?? [];
|
|
496
511
|
const sessionPreviews = records.map((rec) => {
|
|
@@ -914,8 +929,19 @@ class PrismKoishiService {
|
|
|
914
929
|
lines.push(`计费总价:${formatNumber(subtotal)}${currency}`);
|
|
915
930
|
if (hasNonZeroAdjustment)
|
|
916
931
|
lines.push(`优惠后价格:${formatNumber(total)}${currency}`);
|
|
917
|
-
if (hasBalance)
|
|
918
|
-
|
|
932
|
+
if (hasBalance) {
|
|
933
|
+
const isPreview = result?.settlementPreview != null && result?.settlement == null;
|
|
934
|
+
if (isPreview) {
|
|
935
|
+
const projectedBalance = balance - toNumber(total);
|
|
936
|
+
lines.push(`当前余额:${formatNumber(balance)}${currency}`);
|
|
937
|
+
lines.push(projectedBalance >= 0
|
|
938
|
+
? `预计结账后余额:${formatNumber(projectedBalance)}${currency}`
|
|
939
|
+
: `预计结账后余额:余额不足(还差 ${formatNumber(-projectedBalance)}${currency})`);
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
lines.push(`扣款后余额:${formatNumber(balance)}${currency}`);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
919
945
|
return lines.join("\n");
|
|
920
946
|
}
|
|
921
947
|
handleCommandError(error) {
|