koishi-plugin-prism-neo 0.0.21 → 0.0.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/lib/index.d.ts CHANGED
@@ -3,9 +3,11 @@ export declare const name = "prism-neo";
3
3
  export interface Config {
4
4
  url: string;
5
5
  admin: string;
6
+ broadcasts: string[];
6
7
  currency: string;
7
8
  autoLockOnLogin: boolean;
8
9
  logoutConfirmation: boolean;
10
+ powerOffInterval: number;
9
11
  }
10
12
  export declare const Config: Schema<Config>;
11
13
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -95,7 +95,7 @@ async function machinePowerOn({ ctx, config }, machineName, userId, needLogin =
95
95
  makeUrl(config.url, `/machine/power`),
96
96
  {
97
97
  machineName,
98
- "powerState": true,
98
+ powerState: true,
99
99
  userId: `QQ:${userId}`,
100
100
  needLogin
101
101
  }
@@ -107,7 +107,7 @@ async function machinePowerOff({ ctx, config }, machineName, userId, needLogin =
107
107
  makeUrl(config.url, `/machine/power`),
108
108
  {
109
109
  machineName,
110
- "powerState": false,
110
+ powerState: false,
111
111
  userId: `QQ:${userId}`,
112
112
  needLogin
113
113
  }
@@ -181,11 +181,16 @@ __name(insertCoin, "insertCoin");
181
181
  var name = "prism-neo";
182
182
  var kv = /* @__PURE__ */ new Map();
183
183
  var Config = import_koishi.Schema.object({
184
+ // botId: Schema.string().required().description("e.g: onebot:114514"),
184
185
  url: import_koishi.Schema.string().required(),
185
186
  admin: import_koishi.Schema.string().default("authority:3"),
187
+ broadcasts: import_koishi.Schema.array(
188
+ import_koishi.Schema.string()
189
+ ),
186
190
  currency: import_koishi.Schema.string().default("月饼").description("货币名称"),
187
191
  autoLockOnLogin: import_koishi.Schema.boolean().default(true).description("登录时自动获取门锁密码"),
188
- logoutConfirmation: import_koishi.Schema.boolean().default(true).description("登出时需要二次确认")
192
+ logoutConfirmation: import_koishi.Schema.boolean().default(true).description("登出时需要二次确认"),
193
+ powerOffInterval: import_koishi.Schema.number().default(6e5).description("多长时间没人时自动关闭所有机器")
189
194
  });
190
195
  async function getUserName(session, userId) {
191
196
  if (userId) {
@@ -654,6 +659,26 @@ function apply(ctx, config) {
654
659
  ctx.command("add <user:user> <amount>").action(createAction(handleWalletAdd));
655
660
  ctx.command("del <user:user> <amount>").action(createAction(handleWalletDeduct));
656
661
  ctx.command("overwrite <user:user> <amount>").action(createAction(handleCostOverwrite));
662
+ ctx.setInterval(
663
+ async () => {
664
+ let list2 = await list({ ctx, config });
665
+ if (list2.length < 1) {
666
+ let machines = await getAllMachinePower({ ctx, config });
667
+ let turnOff = false;
668
+ machines.forEach((m) => {
669
+ if (m.state.state) {
670
+ turnOff = true;
671
+ }
672
+ });
673
+ if (turnOff) {
674
+ let res = await machinePowerOff({ ctx, config }, "all", null);
675
+ ctx.broadcast(config.broadcasts, "窝里目前有 0 人,自动关闭所有机器");
676
+ }
677
+ return;
678
+ }
679
+ },
680
+ config.powerOffInterval
681
+ );
657
682
  }
658
683
  __name(apply, "apply");
659
684
  // Annotate the CommonJS export names for ESM import in node:
package/lib/types.d.ts CHANGED
@@ -3,5 +3,5 @@ import { Config } from './index';
3
3
  export interface ActionContext {
4
4
  ctx: Context;
5
5
  config: Config;
6
- session: Session;
6
+ session?: Session;
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-prism-neo",
3
3
  "description": "prism koishi前端",
4
- "version": "0.0.21",
4
+ "version": "0.0.22",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",
@@ -14,6 +14,7 @@
14
14
  "plugin"
15
15
  ],
16
16
  "peerDependencies": {
17
- "koishi": "^4.18.7"
17
+ "koishi": "^4.18.7",
18
+ "koishi-plugin-cron": "^3.1.0"
18
19
  }
19
20
  }