koishi-plugin-prism 0.1.30 → 0.1.32

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.
Files changed (2) hide show
  1. package/lib/index.js +26 -6
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -388,7 +388,7 @@ class PrismKoishiService {
388
388
  const total = Number(rawAmount);
389
389
  if (!Number.isFinite(total) || total < 0)
390
390
  return "金额必须为非负数";
391
- const reason = cleanText(rawReason) || "Koishi 管理员手动调价";
391
+ const reason = cleanText(rawReason) || "管理员调价";
392
392
  const result = (await this.client.checkoutWithOverrideByIdentity(this.identity(sender), total, reason));
393
393
  const playerId = String(result?.playerSettlement?.playerId ?? result?.settlement?.playerId ?? "");
394
394
  if (playerId)
@@ -641,11 +641,14 @@ class PrismKoishiService {
641
641
  const { value, error } = parsePositiveInt(rawCount, "prism_coin", "数量", 1);
642
642
  if (error)
643
643
  return error;
644
- await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
644
+ const result = await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
645
645
  type: "coin",
646
646
  target: { kind: "game_machine", id: deviceId },
647
647
  payload: { count: value },
648
648
  });
649
+ const failure = this.getCommandFailureMessage(result);
650
+ if (failure)
651
+ return `❌ 执行失败:${failure}`;
649
652
  return `🪙 已为 ${deviceId} 投入 ${value} 个币`;
650
653
  }
651
654
  async scan(sender, rawDeviceId, rawSubject) {
@@ -653,11 +656,14 @@ class PrismKoishiService {
653
656
  const subject = cleanText(rawSubject);
654
657
  if (!deviceId || !subject)
655
658
  return commandUsage("prism_scan");
656
- await this.client.requestScanByIdentity(this.identity(sender), {
659
+ const result = await this.client.requestScanByIdentity(this.identity(sender), {
657
660
  deviceId,
658
661
  provider: this.config.defaultScanProvider || "aime",
659
662
  subject,
660
663
  });
664
+ const failure = this.getCommandFailureMessage(result);
665
+ if (failure)
666
+ return `❌ 执行失败:${failure}`;
661
667
  return `💳 使用尾号为 ${subject.slice(-4)} 的卡刷卡成功`;
662
668
  }
663
669
  async redeem(sender, rawCode) {
@@ -718,17 +724,27 @@ class PrismKoishiService {
718
724
  }
719
725
  /* ---------------------------- helpers ---------------------------------- */
720
726
  async power(sender, deviceId, state) {
721
- await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
727
+ const result = await this.client.requestDeviceCommandByIdentity(this.identity(sender), {
722
728
  type: state === "on" ? "power.on" : "power.off",
723
729
  target: { kind: "facility", id: deviceId },
724
730
  payload: { state },
725
731
  });
732
+ const failure = this.getCommandFailureMessage(result);
733
+ if (failure)
734
+ return `❌ 执行失败:${failure}`;
726
735
  if (state === "on")
727
736
  return `✅ ${deviceId} 启动成功`;
728
737
  if (deviceId === "all")
729
738
  return `🛑 全部机器关闭成功`;
730
739
  return `🛑 ${deviceId} 关闭成功`;
731
740
  }
741
+ getCommandFailureMessage(result) {
742
+ const action = result?.action;
743
+ if (action?.status === "expired" || action?.status === "rejected") {
744
+ return action.payload?.executorFailure?.message || "命令执行被拒绝或超时";
745
+ }
746
+ return null;
747
+ }
732
748
  async resolvePlatformName(subject) {
733
749
  if (!this.config.resolveDisplayName)
734
750
  return null;
@@ -1035,11 +1051,15 @@ class PrismKoishiService {
1035
1051
  }
1036
1052
  }
1037
1053
  }
1038
- const visibleCheckoutAdjustments = checkoutAdjustments.filter((adjustment) => toNumber(firstDefined(adjustment ?? {}, "amount", "saved", 0)) !== 0);
1054
+ const visibleCheckoutAdjustments = checkoutAdjustments.filter((adjustment) => {
1055
+ const amount = toNumber(firstDefined(adjustment ?? {}, "amount", "saved", 0));
1056
+ const isOverride = cleanText(adjustment?.source).startsWith("staff.override:");
1057
+ return amount !== 0 && !isOverride;
1058
+ });
1039
1059
  lines.push("");
1040
1060
  const cappedTotal = Math.max(0, toNumber(subtotal) + pricingCapAdjustments.reduce((sum, adjustment) => sum + toNumber(adjustment?.amount ?? 0), 0));
1041
1061
  lines.push(`计费总价:${formatNumber(cappedTotal)}${currency}`);
1042
- const hasManualAdjustment = visibleCheckoutAdjustments.some((adjustment) => cleanText(adjustment?.source).startsWith("staff.override:"));
1062
+ const hasManualAdjustment = checkoutAdjustments.some((adjustment) => cleanText(adjustment?.source).startsWith("staff.override:"));
1043
1063
  if (visibleCheckoutAdjustments.length > 0) {
1044
1064
  lines.push("");
1045
1065
  for (const adjustment of visibleCheckoutAdjustments) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "description": "PRiSM Next 计费与设备管理系统的 Koishi 机器人集成插件",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {