koishi-plugin-node-async-bot-all 2.5.0 → 2.6.0

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/commands.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function getStatus(ctx: Context, session: Session): Promise<Objec
4
4
  export declare function getRandom(ctx: Context, session: Session, min: number, max: number): Promise<Object>;
5
5
  export declare function getInfo(ctx: Context, session: Session): Promise<Object>;
6
6
  export declare function getRW(ctx: Context, session: Session): Promise<Object>;
7
+ export declare function getBA(ctx: Context, session: Session): Promise<Number>;
package/lib/fun.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Context, FlatPick } from "koishi";
2
2
  import Analytics from "@koishijs/plugin-analytics";
3
3
  export declare function getSystemUsage(): Promise<Object>;
4
4
  export declare function getHongKongTime(): string;
5
- export declare function fetchWithTimeout(url: string, options: {}, timeout: number, log: any): Promise<Response>;
5
+ export declare function fetchWithTimeout(url: string, options: {} | undefined, timeout: number | undefined, log: any): Promise<Response>;
6
6
  export declare function readInfoFile(ctx: Context): Promise<string>;
7
7
  export declare function formatTimestampDiff(start: number, end: number): string;
8
8
  export declare function getMsgCount(array: FlatPick<Analytics.Message, "type" | "count">[]): Object;
package/lib/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface Config {
19
19
  cxV2: Array<ConfigCxV2>;
20
20
  rwAPI: string;
21
21
  timeout: number;
22
+ baAPI: string[];
22
23
  }
23
24
  export declare const Config: Schema<Config>;
24
25
  export declare function apply(ctx: Context): void;
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -33,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
34
  // src/locales/zh-CN.yml
34
35
  var require_zh_CN = __commonJS({
35
36
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 协议版本:{protocol}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", failed: "{time}\n状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成的随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{data}", failed: "{time}\n读取信息失败。" } }, rw: { description: "随机名言名句。", messages: { msg: "{time}\n{data}", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败(2)。" } } } };
37
+ module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 协议版本:{protocol}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\n运行时间:{online}", failed: "{time}\n状态获取失败。" } }, random: { description: "随机数生成器。", usage: "缺少参数时默认生成 0-10000 的随机数。\n使用示例:", examples: "random 1 128 生成1到128范围的随机数", messages: { msg: "{time}\n生成的随机数:{data}" } }, info: { description: "查询机器人信息。", messages: { msg: "{data}", failed: "{time}\n读取信息失败。" } }, rw: { description: "随机名言名句。", messages: { msg: "{time}\n{data}", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败(2)。" } }, randomba: { description: "随机BA图。", messages: { wait: "{time}\n请等待图片上传(可能较慢)。" } } } };
37
38
  }
38
39
  });
39
40
 
@@ -147,8 +148,8 @@ async function readInfoFile(ctx) {
147
148
  "&version;",
148
149
  (await ctx.database.get("botData", "version"))[0].data
149
150
  );
150
- } catch (e) {
151
- info = e.message;
151
+ } catch (error) {
152
+ info = error.message;
152
153
  }
153
154
  return info;
154
155
  }
@@ -178,13 +179,13 @@ __name(getMsgCount, "getMsgCount");
178
179
  // src/commands.ts
179
180
  async function getServer(ctx, session) {
180
181
  const log = ctx.logger("cx");
181
- log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
182
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
182
183
  let msg;
183
184
  let dataError;
184
185
  let data;
185
186
  let error;
186
187
  const time = getHongKongTime();
187
- const index = ctx.config.cxV2.findIndex((item) => item.id === session.event.guild.id);
188
+ const index = ctx.config.cxV2.findIndex((item) => item.id === session.event.guild?.id);
188
189
  if (index !== -1) {
189
190
  const api = ctx.config.cxV2[index]["api"];
190
191
  if (api == void 0) {
@@ -290,7 +291,7 @@ async function getServer(ctx, session) {
290
291
  __name(getServer, "getServer");
291
292
  async function getStatus(ctx, session) {
292
293
  const log = ctx.logger("status");
293
- log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
294
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
294
295
  const time = getHongKongTime();
295
296
  let msg;
296
297
  const vMsg = await getSystemUsage();
@@ -324,7 +325,7 @@ async function getStatus(ctx, session) {
324
325
  __name(getStatus, "getStatus");
325
326
  async function getRandom(ctx, session, min, max) {
326
327
  const log = ctx.logger("random");
327
- log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
328
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
328
329
  const time = getHongKongTime();
329
330
  let msg;
330
331
  let data;
@@ -347,7 +348,7 @@ async function getRandom(ctx, session, min, max) {
347
348
  __name(getRandom, "getRandom");
348
349
  async function getInfo(ctx, session) {
349
350
  const log = ctx.logger("info");
350
- log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
351
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
351
352
  const time = getHongKongTime();
352
353
  let msg;
353
354
  let data = await readInfoFile(ctx);
@@ -373,7 +374,7 @@ async function getInfo(ctx, session) {
373
374
  __name(getInfo, "getInfo");
374
375
  async function getRW(ctx, session) {
375
376
  const log = ctx.logger("rw");
376
- log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
377
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
377
378
  let msg;
378
379
  let data;
379
380
  const time = getHongKongTime();
@@ -411,9 +412,24 @@ async function getRW(ctx, session) {
411
412
  return msg;
412
413
  }
413
414
  __name(getRW, "getRW");
415
+ async function getBA(ctx, session) {
416
+ const log = ctx.logger("ba");
417
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
418
+ const random = new import_koishi.Random(() => Math.random());
419
+ const time = getHongKongTime();
420
+ const vid = await session.send(session.text(".wait", { "time": time }));
421
+ const ms = random.int(0, 1500);
422
+ const link = random.pick(ctx.config.baAPI) + `?cacheBuster=${random.real(1, 2147483647)}`;
423
+ log.info(`Link: ${link}`);
424
+ await (0, import_koishi.sleep)(ms);
425
+ await session.send(import_koishi.h.image(link));
426
+ await session.bot.deleteMessage(session.event.guild?.id, vid[0]);
427
+ return 0;
428
+ }
429
+ __name(getBA, "getBA");
414
430
 
415
431
  // package.json
416
- var version = "2.5.0";
432
+ var version = "2.6.0";
417
433
 
418
434
  // src/index.ts
419
435
  var inject = ["database"];
@@ -433,7 +449,10 @@ var Config = import_koishi2.Schema.intersect([
433
449
  }).description("查询"),
434
450
  import_koishi2.Schema.object({
435
451
  rwAPI: import_koishi2.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
436
- }).description("随机文本")
452
+ }).description("随机文本"),
453
+ import_koishi2.Schema.object({
454
+ baAPI: import_koishi2.Schema.array(String).default(["https://rba.kanostar.top/portrait"]).description("随机BA图 API")
455
+ }).description("随机BA图")
437
456
  ]).description("基础设置");
438
457
  function apply(ctx) {
439
458
  ctx.i18n.define("zh-CN", require_zh_CN());
@@ -452,43 +471,46 @@ function apply(ctx) {
452
471
  ctx.command("cx").action(async ({ session }) => {
453
472
  const cx = await getServer(ctx, session);
454
473
  if (cx["success"] == 0) {
455
- return session.text(".msg", cx);
474
+ return session?.text(".msg", cx);
456
475
  } else if (cx["success"] == 1) {
457
- return session.text(".forbidden", cx);
476
+ return session?.text(".forbidden", cx);
458
477
  } else if (cx["success"] == 2) {
459
- return session.text(".failed", cx);
478
+ return session?.text(".failed", cx);
460
479
  }
461
480
  });
462
481
  ctx.command("status").action(async ({ session }) => {
463
482
  const status = await getStatus(ctx, session);
464
483
  if (status["success"] == 0) {
465
- return session.text(".msg", status);
484
+ return session?.text(".msg", status);
466
485
  } else {
467
- return session.text(".failed", status);
486
+ return session?.text(".failed", status);
468
487
  }
469
488
  });
470
489
  ctx.command("random [最小数:number] [最大数:number]").action(async ({ session }, min, max) => {
471
490
  const random = await getRandom(ctx, session, min, max);
472
- return session.text(".msg", random);
491
+ return session?.text(".msg", random);
473
492
  });
474
493
  ctx.command("info").action(async ({ session }) => {
475
494
  const info = await getInfo(ctx, session);
476
495
  if (info["success"] == 0) {
477
- return session.text(".msg", info);
496
+ return session?.text(".msg", info);
478
497
  } else {
479
- return session.text(".failed", info);
498
+ return session?.text(".failed", info);
480
499
  }
481
500
  });
482
501
  ctx.command("rw").action(async ({ session }) => {
483
502
  const rw = await getRW(ctx, session);
484
503
  if (rw["success"] == 0) {
485
- return session.text(".msg", rw);
504
+ return session?.text(".msg", rw);
486
505
  } else if (rw["success"] == 1) {
487
- return session.text(".failed1", rw);
506
+ return session?.text(".failed1", rw);
488
507
  } else {
489
- return session.text(".failed2", rw);
508
+ return session?.text(".failed2", rw);
490
509
  }
491
510
  });
511
+ ctx.command("randomBA").action(async ({ session }) => {
512
+ await getBA(ctx, session);
513
+ });
492
514
  }
493
515
  __name(apply, "apply");
494
516
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
3
  "description": "NodeAsync Bot插件(自用)",
4
- "version": "2.5.0",
4
+ "version": "2.6.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "repository": {
27
27
  "type": "git",
28
- "url": "https://github.com/ccd2s/node-async-bot-all"
28
+ "url": "git+https://github.com/ccd2s/node-async-bot-all.git"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@koishijs/client": "^5.30.4"