koishi-plugin-prism-neo 0.0.10 → 0.0.13

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 CHANGED
@@ -90,24 +90,26 @@ async function getLock({ ctx, config }, userId) {
90
90
  );
91
91
  }
92
92
  __name(getLock, "getLock");
93
- async function machinePowerOn({ ctx, config }, machineName, userId) {
93
+ async function machinePowerOn({ ctx, config }, machineName, userId, needLogin = true) {
94
94
  return await ctx.http.post(
95
95
  makeUrl(config.url, `/machine/power`),
96
96
  {
97
97
  machineName,
98
98
  "powerState": true,
99
- userId: `QQ:${userId}`
99
+ userId: `QQ:${userId}`,
100
+ needLogin
100
101
  }
101
102
  );
102
103
  }
103
104
  __name(machinePowerOn, "machinePowerOn");
104
- async function machinePowerOff({ ctx, config }, machineName, userId) {
105
+ async function machinePowerOff({ ctx, config }, machineName, userId, needLogin = true) {
105
106
  return await ctx.http.post(
106
107
  makeUrl(config.url, `/machine/power`),
107
108
  {
108
109
  machineName,
109
110
  "powerState": false,
110
- userId: `QQ:${userId}`
111
+ userId: `QQ:${userId}`,
112
+ needLogin
111
113
  }
112
114
  );
113
115
  }
@@ -164,11 +166,12 @@ async function redeem({ ctx, config }, code, userId) {
164
166
  );
165
167
  }
166
168
  __name(redeem, "redeem");
167
- async function insertCoin({ ctx, config }, alias, userId) {
169
+ async function insertCoin({ ctx, config }, alias, userId, force = false) {
168
170
  return await ctx.http.post(
169
171
  makeUrl(config.url, `/remote/${alias}/coin`),
170
172
  {
171
- userId: `QQ:${userId}`
173
+ userId: `QQ:${userId}`,
174
+ force
172
175
  }
173
176
  );
174
177
  }
@@ -183,7 +186,7 @@ var Config = import_koishi.Schema.object({
183
186
  });
184
187
  async function getUserName(session, userId) {
185
188
  if (userId) {
186
- return (await session.bot.getUser(userId)).name + `(${userId}})`;
189
+ return (await session.bot.getUser(userId)).name + ` ( ${userId} )`;
187
190
  } else {
188
191
  return "匿名用户";
189
192
  }
@@ -302,7 +305,7 @@ async function handleLoginCmd(context, user) {
302
305
  await login(context, userId);
303
306
  const pwd = await getLock(context, userId);
304
307
  if (user) {
305
- return `✅ 已为用户 ${getUserName(context.session, userId)} 入场,该用户的门锁密码是: ${pwd.password}
308
+ return `✅ 已为用户 ${await getUserName(context.session, userId)} 入场,该用户的门锁密码是: ${pwd.password}
306
309
  注意! 门锁密码有效期为三分钟`;
307
310
  }
308
311
  return `✅ 入场成功,你的门锁密码是: ${pwd.password}
@@ -317,7 +320,7 @@ async function handleLogoutCmd(context, user) {
317
320
  if (pendingLogout && now - pendingLogout < 60 * 1e3) {
318
321
  kv.delete(targetUserId);
319
322
  const res = await logout(context, targetUserId);
320
- const messagePrefix = user ? `✅ 已为用户 ${getUserName(context.session, targetUserId)} 退场` : "✅ 退场成功";
323
+ const messagePrefix = user ? `✅ 已为用户 ${await getUserName(context.session, targetUserId)} 退场` : "✅ 退场成功";
321
324
  return [
322
325
  messagePrefix,
323
326
  `入场时间: ${formatDateTime(res.session.createdAt)}`,
@@ -455,13 +458,15 @@ async function handleItemsCmd(context, user) {
455
458
  __name(handleItemsCmd, "handleItemsCmd");
456
459
  async function handleMachineOn(context, alias) {
457
460
  if (!alias) return "请输入设备名";
458
- const res = await machinePowerOn(context, alias, context.session.userId);
461
+ let isAdmin = await context.ctx.permissions.check(context.config.admin, context.session);
462
+ const res = await machinePowerOn(context, alias, context.session.userId, !isAdmin);
459
463
  return `${res.machine} 启动成功`;
460
464
  }
461
465
  __name(handleMachineOn, "handleMachineOn");
462
466
  async function handleMachineOff(context, alias) {
463
467
  if (!alias) return "请输入设备名";
464
- const res = await machinePowerOff(context, alias, context.session.userId);
468
+ let isAdmin = await context.ctx.permissions.check(context.config.admin, context.session);
469
+ const res = await machinePowerOff(context, alias, context.session.userId, !isAdmin);
465
470
  return `${res.machine} 关闭成功`;
466
471
  }
467
472
  __name(handleMachineOff, "handleMachineOff");
@@ -534,7 +539,8 @@ async function handleRedeem(context, code) {
534
539
  __name(handleRedeem, "handleRedeem");
535
540
  async function handleCoin(context, alias) {
536
541
  if (!alias) return "请输入设备名";
537
- const res = await insertCoin(context, alias, context.session.userId);
542
+ let isAdmin = await context.ctx.permissions.check(context.config.admin, context.session);
543
+ const res = await insertCoin(context, alias, context.session.userId, isAdmin);
538
544
  return `已为 ${res.machineName} 投入 ${res.count} 个币`;
539
545
  }
540
546
  __name(handleCoin, "handleCoin");
package/lib/service.d.ts CHANGED
@@ -11,8 +11,8 @@ export declare function getLock({ ctx, config }: ActionContext, userId: string):
11
11
  password: string;
12
12
  id: any;
13
13
  }>;
14
- export declare function machinePowerOn({ ctx, config }: ActionContext, machineName: string, userId: string): Promise<any>;
15
- export declare function machinePowerOff({ ctx, config }: ActionContext, machineName: string, userId: string): Promise<any>;
14
+ export declare function machinePowerOn({ ctx, config }: ActionContext, machineName: string, userId: string, needLogin?: boolean): Promise<any>;
15
+ export declare function machinePowerOff({ ctx, config }: ActionContext, machineName: string, userId: string, needLogin?: boolean): Promise<any>;
16
16
  export declare function getAllMachinePower({ ctx, config, session }: ActionContext): Promise<{
17
17
  machine: string;
18
18
  state: {
@@ -29,4 +29,4 @@ export declare function walletAdd({ ctx, config }: ActionContext, amount: number
29
29
  export declare function walletDel({ ctx, config }: ActionContext, amount: number, userId: string): Promise<any>;
30
30
  export declare function costOverwrite({ ctx, config }: ActionContext, amount: string, userId: string): Promise<any>;
31
31
  export declare function redeem({ ctx, config }: ActionContext, code: string, userId: string): Promise<any>;
32
- export declare function insertCoin({ ctx, config }: ActionContext, alias: string, userId: string): Promise<any>;
32
+ export declare function insertCoin({ ctx, config }: ActionContext, alias: string, userId: string, force?: boolean): Promise<any>;
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.10",
4
+ "version": "0.0.13",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",