koishi-plugin-prism-neo 0.0.9 → 0.0.12

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 ADDED
@@ -0,0 +1,8 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "prism-neo";
3
+ export interface Config {
4
+ url: string;
5
+ admin: string;
6
+ }
7
+ export declare const Config: Schema<Config>;
8
+ export declare function apply(ctx: Context, config: Config): void;
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,6 +166,16 @@ async function redeem({ ctx, config }, code, userId) {
164
166
  );
165
167
  }
166
168
  __name(redeem, "redeem");
169
+ async function insertCoin({ ctx, config }, alias, userId, force = false) {
170
+ return await ctx.http.post(
171
+ makeUrl(config.url, `/remote/${alias}/coin`),
172
+ {
173
+ userId: `QQ:${userId}`,
174
+ force
175
+ }
176
+ );
177
+ }
178
+ __name(insertCoin, "insertCoin");
167
179
 
168
180
  // src/index.ts
169
181
  var name = "prism-neo";
@@ -174,7 +186,7 @@ var Config = import_koishi.Schema.object({
174
186
  });
175
187
  async function getUserName(session, userId) {
176
188
  if (userId) {
177
- return (await session.bot.getUser(userId)).name + `( ${userId} )`;
189
+ return (await session.bot.getUser(userId)).name + ` ( ${userId} )`;
178
190
  } else {
179
191
  return "匿名用户";
180
192
  }
@@ -446,13 +458,15 @@ async function handleItemsCmd(context, user) {
446
458
  __name(handleItemsCmd, "handleItemsCmd");
447
459
  async function handleMachineOn(context, alias) {
448
460
  if (!alias) return "请输入设备名";
449
- 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);
450
463
  return `${res.machine} 启动成功`;
451
464
  }
452
465
  __name(handleMachineOn, "handleMachineOn");
453
466
  async function handleMachineOff(context, alias) {
454
467
  if (!alias) return "请输入设备名";
455
- 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);
456
470
  return `${res.machine} 关闭成功`;
457
471
  }
458
472
  __name(handleMachineOff, "handleMachineOff");
@@ -523,6 +537,13 @@ async function handleRedeem(context, code) {
523
537
  return message.join("\n");
524
538
  }
525
539
  __name(handleRedeem, "handleRedeem");
540
+ async function handleCoin(context, alias) {
541
+ if (!alias) return "请输入设备名";
542
+ let isAdmin = await context.ctx.permissions.check(context.config.admin, context.session);
543
+ const res = await insertCoin(context, alias, context.session.userId, isAdmin);
544
+ return `已为 ${res.machineName} 投入 ${res.count} 个币`;
545
+ }
546
+ __name(handleCoin, "handleCoin");
526
547
  function apply(ctx, config) {
527
548
  const createAction = /* @__PURE__ */ __name((handler) => {
528
549
  const actionFn = /* @__PURE__ */ __name((argv, ...args) => {
@@ -547,6 +568,7 @@ function apply(ctx, config) {
547
568
  ctx.command("on <alias>").action(createAction(handleMachineOn));
548
569
  ctx.command("off <alias>").action(createAction(handleMachineOff));
549
570
  ctx.command("redeem <code>").action(createAction(handleRedeem));
571
+ ctx.command("coin <alias>").action(createAction(handleCoin));
550
572
  ctx.command("add <user:user> <amount>").action(createAction(handleWalletAdd));
551
573
  ctx.command("del <user:user> <amount>").action(createAction(handleWalletDeduct));
552
574
  ctx.command("overwrite <user:user> <amount>").action(createAction(handleCostOverwrite));
@@ -0,0 +1,32 @@
1
+ import { ActionContext } from "./types";
2
+ import { BillingResponse, ListResponse, LogoutResponse, UserAsset, Wallet } from "./model";
3
+ export declare function register({ ctx, config }: ActionContext, userId: string): Promise<unknown>;
4
+ export declare function login({ ctx, config }: ActionContext, userId: string): Promise<unknown>;
5
+ export declare function logout({ ctx, config }: ActionContext, userId: string): Promise<LogoutResponse>;
6
+ export declare function billing({ ctx, config }: ActionContext, userId: string): Promise<BillingResponse>;
7
+ export declare function list({ ctx, config }: ActionContext): Promise<ListResponse>;
8
+ export declare function wallet({ ctx, config }: ActionContext, userId: string): Promise<Wallet>;
9
+ export declare function assets({ ctx, config }: ActionContext, userId: string): Promise<UserAsset[]>;
10
+ export declare function getLock({ ctx, config }: ActionContext, userId: string): Promise<{
11
+ password: string;
12
+ id: any;
13
+ }>;
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
+ export declare function getAllMachinePower({ ctx, config, session }: ActionContext): Promise<{
17
+ machine: string;
18
+ state: {
19
+ state: boolean;
20
+ };
21
+ }[]>;
22
+ export declare function getMachinePower({ ctx, config, session }: ActionContext, machineName: string): Promise<{
23
+ machine: string;
24
+ state: {
25
+ state: boolean;
26
+ };
27
+ }>;
28
+ export declare function walletAdd({ ctx, config }: ActionContext, amount: number, userId: string): Promise<any>;
29
+ export declare function walletDel({ ctx, config }: ActionContext, amount: number, userId: string): Promise<any>;
30
+ export declare function costOverwrite({ ctx, config }: ActionContext, amount: string, userId: string): Promise<any>;
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, force?: boolean): Promise<any>;
package/lib/types.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Context, Session } from 'koishi';
2
+ import { Config } from './index';
3
+ export interface ActionContext {
4
+ ctx: Context;
5
+ config: Config;
6
+ session: Session;
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.9",
4
+ "version": "0.0.12",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "lib",