koishi-plugin-prism 0.1.5 → 0.1.6
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/lib/index.js +33 -24
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -712,6 +712,15 @@ class PrismKoishiService {
|
|
|
712
712
|
return null;
|
|
713
713
|
}
|
|
714
714
|
}
|
|
715
|
+
async resolvePlayerDisplay(sender, playerId) {
|
|
716
|
+
if (!sender)
|
|
717
|
+
return playerId || "未知玩家";
|
|
718
|
+
const platformName = await this.resolvePlatformName(sender.id);
|
|
719
|
+
const name = platformName
|
|
720
|
+
|| (sender.name && sender.name !== sender.id ? sender.name : playerId)
|
|
721
|
+
|| sender.id;
|
|
722
|
+
return `玩家:${name}(${this.config.provider.toUpperCase()}:${sender.id})`;
|
|
723
|
+
}
|
|
715
724
|
mahjongTableForPlayer(playerId) {
|
|
716
725
|
for (const [tableId, state] of this.mahjongTables) {
|
|
717
726
|
if (state.activeSessions[playerId])
|
|
@@ -755,7 +764,7 @@ class PrismKoishiService {
|
|
|
755
764
|
return "权限不足";
|
|
756
765
|
return null;
|
|
757
766
|
}
|
|
758
|
-
formatCheckoutPreview(result, sender, title = "【结算账单】") {
|
|
767
|
+
async formatCheckoutPreview(result, sender, title = "【结算账单】") {
|
|
759
768
|
if (result?.billing && result?.session) {
|
|
760
769
|
return formatLegacyBilling(result, this.config.currencyName);
|
|
761
770
|
}
|
|
@@ -785,57 +794,57 @@ class PrismKoishiService {
|
|
|
785
794
|
const adjustments = result?.adjustments ?? [];
|
|
786
795
|
const assetHoldings = result?.assetHoldings ?? [];
|
|
787
796
|
const lines = [];
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
const identitySuffix = sender ? `(${this.config.provider.toUpperCase()}:${sender.id})` : "";
|
|
791
|
-
headerParts.push(`玩家ID:${playerId}${identitySuffix}`);
|
|
792
|
-
}
|
|
793
|
-
else if (sender) {
|
|
794
|
-
headerParts.push(`玩家:${sender.name || sender.id}(${this.config.provider.toUpperCase()}:${sender.id})`);
|
|
795
|
-
}
|
|
796
|
-
lines.push(headerParts.join("\n"));
|
|
797
|
+
lines.push(title);
|
|
798
|
+
lines.push(await this.resolvePlayerDisplay(sender, playerId));
|
|
797
799
|
const validStarts = sessionPreviews.map((s) => parseDateTime(s?.startedAt)).filter(Boolean);
|
|
798
800
|
const validEnds = sessionPreviews.map((s) => sessionDisplayEnd(s, previewedAt)).filter(Boolean);
|
|
799
801
|
if (validStarts.length > 0) {
|
|
800
802
|
const overallStart = minDate(validStarts);
|
|
801
803
|
const overallEnd = validEnds.length > 0 ? maxDate(validEnds) : now(this.config);
|
|
802
|
-
lines.push(
|
|
804
|
+
lines.push(`⏰ 游玩时间:${formatHM(overallStart)}–${formatHM(overallEnd)}`);
|
|
803
805
|
}
|
|
804
|
-
lines.push("");
|
|
805
806
|
for (const sPrev of sessionPreviews) {
|
|
806
807
|
const label = sPrev?.label || "计时区间";
|
|
807
808
|
const startDt = parseDateTime(sPrev?.startedAt);
|
|
808
809
|
const endDt = sessionDisplayEnd(sPrev, previewedAt);
|
|
809
810
|
const status = sPrev?.status ?? "active";
|
|
810
811
|
const sTotal = toNumber(sPrev?.total ?? 0);
|
|
812
|
+
lines.push("");
|
|
811
813
|
lines.push(label);
|
|
812
814
|
if (startDt && endDt) {
|
|
815
|
+
const minutes = Math.floor((endDt.getTime() - startDt.getTime()) / 60_000);
|
|
813
816
|
lines.push(`游玩时段:${formatHM(startDt)}-${formatHM(endDt)}`);
|
|
814
|
-
lines.push(`游玩时长:${formatDurationValue(
|
|
817
|
+
lines.push(`游玩时长:${formatDurationValue(minutes)}|消费:${formatNumber(sTotal)}${currency}`);
|
|
815
818
|
}
|
|
816
819
|
else if (startDt) {
|
|
817
820
|
lines.push(`入场:${formatHM(startDt)} (${status === "active" ? "计费中" : "已关闭"})`);
|
|
818
821
|
}
|
|
819
|
-
|
|
822
|
+
const sessionAdjustments = (sPrev?.adjustments ?? []);
|
|
823
|
+
for (const adj of sessionAdjustments) {
|
|
824
|
+
const amount = toNumber(firstDefined(adj ?? {}, "amount", "saved", 0));
|
|
825
|
+
if (amount === 0)
|
|
826
|
+
continue;
|
|
827
|
+
const adjLabel = firstDefined(adj ?? {}, "label", "name", "source") ?? "优惠";
|
|
828
|
+
lines.push(` └ ${adjLabel}:${formatNumber(amount)}${currency}`);
|
|
829
|
+
}
|
|
820
830
|
}
|
|
821
|
-
|
|
822
|
-
|
|
831
|
+
let balance = 0;
|
|
832
|
+
let hasBalance = false;
|
|
823
833
|
for (const holding of assetHoldings) {
|
|
824
|
-
const qty = toNumber(holding?.quantity ?? 0);
|
|
825
834
|
const code = String(holding?.assetCode ?? "").toLowerCase();
|
|
826
835
|
if (code.includes("paid") || code.includes("free") || code.includes("currency")) {
|
|
827
|
-
|
|
836
|
+
balance += toNumber(holding?.quantity ?? 0);
|
|
837
|
+
hasBalance = true;
|
|
828
838
|
}
|
|
829
839
|
}
|
|
830
|
-
|
|
831
|
-
lines.push(`扣款后余额:${balanceParts.join("+")}`);
|
|
840
|
+
lines.push("");
|
|
832
841
|
lines.push(`计费总价:${formatNumber(subtotal)}${currency}`);
|
|
833
|
-
const hasDiscount = adjustments.some((adj) => {
|
|
834
|
-
|
|
835
|
-
return amount !== 0;
|
|
836
|
-
});
|
|
842
|
+
const hasDiscount = adjustments.some((adj) => toNumber(firstDefined(adj ?? {}, "amount", "saved", 0)) !== 0)
|
|
843
|
+
|| sessionPreviews.some((sp) => (sp?.adjustments ?? []).some((adj) => toNumber(firstDefined(adj ?? {}, "amount", "saved", 0)) !== 0));
|
|
837
844
|
if (hasDiscount)
|
|
838
845
|
lines.push(`优惠后价格:${formatNumber(total)}${currency}`);
|
|
846
|
+
if (hasBalance)
|
|
847
|
+
lines.push(`扣款后余额:${formatNumber(balance)}${currency}`);
|
|
839
848
|
return lines.join("\n");
|
|
840
849
|
}
|
|
841
850
|
handleCommandError(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-prism",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "PRiSM Next 计费与设备管理系统的 Koishi 机器人集成插件",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"test": "bun test test",
|
|
49
49
|
"typecheck": "tsc -p tsconfig.json"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|