koishi-plugin-prism 0.1.31 → 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 +19 -3
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "PRiSM Next 计费与设备管理系统的 Koishi 机器人集成插件",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {