koishi-plugin-prism 0.1.32 → 0.1.33
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 +28 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -689,6 +689,28 @@ class PrismKoishiService {
|
|
|
689
689
|
this.mergeWaitingSeats(groups);
|
|
690
690
|
return formatPlayerGroups(groups, this.config.mahjongTableSize ?? 4, this.config.mahjongLabelPrefix ?? "麻将桌");
|
|
691
691
|
}
|
|
692
|
+
parseDeviceStateValue(stateVal) {
|
|
693
|
+
if (!stateVal)
|
|
694
|
+
return "unknown";
|
|
695
|
+
if (typeof stateVal === "string") {
|
|
696
|
+
try {
|
|
697
|
+
const decoded = JSON.parse(stateVal);
|
|
698
|
+
if (typeof decoded === "string") {
|
|
699
|
+
return decoded;
|
|
700
|
+
}
|
|
701
|
+
if (decoded && typeof decoded.state === "string") {
|
|
702
|
+
return decoded.state;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
return stateVal;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (typeof stateVal === "object" && stateVal !== null) {
|
|
710
|
+
return stateVal.state ?? "unknown";
|
|
711
|
+
}
|
|
712
|
+
return "unknown";
|
|
713
|
+
}
|
|
692
714
|
async listDeviceStates(rawAlias) {
|
|
693
715
|
const alias = cleanText(rawAlias);
|
|
694
716
|
const result = (await this.client.listDeviceStates());
|
|
@@ -699,11 +721,11 @@ class PrismKoishiService {
|
|
|
699
721
|
const matched = states.find((d) => d.deviceId === alias || d.label === alias);
|
|
700
722
|
if (!matched)
|
|
701
723
|
return `找不到设备: ${alias}`;
|
|
702
|
-
const stateVal = matched.state
|
|
724
|
+
const stateVal = this.parseDeviceStateValue(matched.state);
|
|
703
725
|
return `${matched.label || matched.deviceId}: ${stateVal}`;
|
|
704
726
|
}
|
|
705
727
|
return states
|
|
706
|
-
.map((d) => `${d.label || d.deviceId}: ${d.state
|
|
728
|
+
.map((d) => `${d.label || d.deviceId}: ${this.parseDeviceStateValue(d.state)}`)
|
|
707
729
|
.join("\n");
|
|
708
730
|
}
|
|
709
731
|
async autoPowerOffLoop() {
|
|
@@ -716,7 +738,7 @@ class PrismKoishiService {
|
|
|
716
738
|
return;
|
|
717
739
|
const statesResult = (await this.client.listDeviceStates());
|
|
718
740
|
const states = (statesResult?.deviceStates ?? []);
|
|
719
|
-
const anyOn = states.some((d) => d.state
|
|
741
|
+
const anyOn = states.some((d) => this.parseDeviceStateValue(d.state) !== "off");
|
|
720
742
|
if (!anyOn)
|
|
721
743
|
return;
|
|
722
744
|
const dummySender = { id: "system", name: "system" };
|
|
@@ -732,11 +754,12 @@ class PrismKoishiService {
|
|
|
732
754
|
const failure = this.getCommandFailureMessage(result);
|
|
733
755
|
if (failure)
|
|
734
756
|
return `❌ 执行失败:${failure}`;
|
|
757
|
+
const displayName = result?.action?.payload?.deviceLabel || deviceId;
|
|
735
758
|
if (state === "on")
|
|
736
|
-
return `✅ ${
|
|
759
|
+
return `✅ ${displayName} 启动成功`;
|
|
737
760
|
if (deviceId === "all")
|
|
738
761
|
return `🛑 全部机器关闭成功`;
|
|
739
|
-
return `🛑 ${
|
|
762
|
+
return `🛑 ${displayName} 关闭成功`;
|
|
740
763
|
}
|
|
741
764
|
getCommandFailureMessage(result) {
|
|
742
765
|
const action = result?.action;
|