koishi-plugin-node-async-bot-all 2.5.1 → 2.7.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,5 @@ 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>;
8
+ export declare function serverTest(ctx: Context, session: Session): Promise<Object>;
package/lib/fun.d.ts CHANGED
@@ -6,3 +6,11 @@ export declare function fetchWithTimeout(url: string, options: {} | undefined, t
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;
9
+ export declare function hostPing(host: string): Promise<{
10
+ success: boolean;
11
+ data?: any;
12
+ ip?: string;
13
+ alive?: boolean;
14
+ time?: string;
15
+ packetLoss?: string;
16
+ }>;
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
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/locales/zh-CN.yml
35
35
  var require_zh_CN = __commonJS({
36
36
  "src/locales/zh-CN.yml"(exports2, module2) {
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)。" } } } };
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请等待图片上传(可能较慢)。" } }, servertest: { description: "Ping服务器。", messages: { msg: "{time}\n== Ping {host} ==\n状态:{alive}\n丢包率:{packetLoss}\n返回IP:{ip}\n{avg}", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\nPing 失败:{data}" } } } };
38
38
  }
39
39
  });
40
40
 
@@ -56,6 +56,7 @@ var import_koishi = require("koishi");
56
56
  // src/fun.ts
57
57
  var import_os = __toESM(require("os"));
58
58
  var import_fs = __toESM(require("fs"));
59
+ var import_ping = __toESM(require("ping"));
59
60
  var import_path = __toESM(require("path"));
60
61
  function getSystemName() {
61
62
  return import_os.default.type() + " " + import_os.default.release();
@@ -175,6 +176,26 @@ function getMsgCount(array) {
175
176
  return { "receive": receive, "send": send };
176
177
  }
177
178
  __name(getMsgCount, "getMsgCount");
179
+ async function hostPing(host) {
180
+ try {
181
+ const tmp = await import_ping.default.promise.probe(host, {
182
+ timeout: 5
183
+ });
184
+ return {
185
+ "success": true,
186
+ "ip": tmp.numeric_host,
187
+ "alive": tmp.alive,
188
+ "time": tmp.avg == "unknown" ? "请求超时。" : `平均延迟:${tmp.avg}ms`,
189
+ "packetLoss": tmp.packetLoss.toString()
190
+ };
191
+ } catch (error) {
192
+ return {
193
+ "success": false,
194
+ "data": error.message
195
+ };
196
+ }
197
+ }
198
+ __name(hostPing, "hostPing");
178
199
 
179
200
  // src/commands.ts
180
201
  async function getServer(ctx, session) {
@@ -412,9 +433,62 @@ async function getRW(ctx, session) {
412
433
  return msg;
413
434
  }
414
435
  __name(getRW, "getRW");
436
+ async function getBA(ctx, session) {
437
+ const log = ctx.logger("ba");
438
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
439
+ const random = new import_koishi.Random(() => Math.random());
440
+ const time = getHongKongTime();
441
+ const vid = await session.send(session.text(".wait", { "time": time }));
442
+ const ms = random.int(0, 1500);
443
+ const link = random.pick(ctx.config.baAPI) + `?cacheBuster=${random.real(1, 2147483647)}`;
444
+ log.info(`Link: ${link}`);
445
+ await (0, import_koishi.sleep)(ms);
446
+ await session.send(import_koishi.h.image(link));
447
+ await session.bot.deleteMessage(session.event.guild?.id, vid[0]);
448
+ return 0;
449
+ }
450
+ __name(getBA, "getBA");
451
+ async function serverTest(ctx, session) {
452
+ const log = ctx.logger("serverTest");
453
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
454
+ const time = getHongKongTime();
455
+ const host = ctx.config.serverPing[`${session.event.guild?.id}`];
456
+ if (host == void 0) {
457
+ return {
458
+ "success": 1,
459
+ "time": time
460
+ };
461
+ }
462
+ const tmp = await hostPing(host);
463
+ log.info(tmp);
464
+ if (!tmp.success) {
465
+ return {
466
+ "success": 2,
467
+ "time": time,
468
+ "data": tmp.data
469
+ };
470
+ }
471
+ if (tmp.ip == void 0) {
472
+ return {
473
+ "success": 2,
474
+ "time": time,
475
+ "data": "未知的主机 " + host
476
+ };
477
+ }
478
+ return {
479
+ "success": 0,
480
+ "time": time,
481
+ "host": host,
482
+ "ip": tmp.ip,
483
+ "alive": tmp.alive == true ? "正常" : "异常",
484
+ "packetLoss": tmp.packetLoss,
485
+ "avg": tmp.time
486
+ };
487
+ }
488
+ __name(serverTest, "serverTest");
415
489
 
416
490
  // package.json
417
- var version = "2.5.1";
491
+ var version = "2.7.0";
418
492
 
419
493
  // src/index.ts
420
494
  var inject = ["database"];
@@ -434,7 +508,13 @@ var Config = import_koishi2.Schema.intersect([
434
508
  }).description("查询"),
435
509
  import_koishi2.Schema.object({
436
510
  rwAPI: import_koishi2.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
437
- }).description("随机文本")
511
+ }).description("随机文本"),
512
+ import_koishi2.Schema.object({
513
+ baAPI: import_koishi2.Schema.array(String).default(["https://rba.kanostar.top/portrait"]).description("随机BA图 API")
514
+ }).description("随机BA图"),
515
+ import_koishi2.Schema.object({
516
+ serverPing: import_koishi2.Schema.dict(String).role("table").description("键:群号;值:Host")
517
+ }).description("服之测测(Ping)")
438
518
  ]).description("基础设置");
439
519
  function apply(ctx) {
440
520
  ctx.i18n.define("zh-CN", require_zh_CN());
@@ -468,7 +548,7 @@ function apply(ctx) {
468
548
  return session?.text(".failed", status);
469
549
  }
470
550
  });
471
- ctx.command("random [最小数:number] [最大数:number]").action(async ({ session }, min, max) => {
551
+ ctx.command("random [最小数:number] [最大数:number]").alias("随机数").action(async ({ session }, min, max) => {
472
552
  const random = await getRandom(ctx, session, min, max);
473
553
  return session?.text(".msg", random);
474
554
  });
@@ -490,6 +570,19 @@ function apply(ctx) {
490
570
  return session?.text(".failed2", rw);
491
571
  }
492
572
  });
573
+ ctx.command("randomBA").alias("随机BA图").action(async ({ session }) => {
574
+ await getBA(ctx, session);
575
+ });
576
+ ctx.command("serverTest").alias("服之测测").action(async ({ session }) => {
577
+ const server = await serverTest(ctx, session);
578
+ if (server["success"] == 0) {
579
+ return session?.text(".msg", server);
580
+ } else if (server["success"] == 1) {
581
+ return session?.text(".forbidden", server);
582
+ } else {
583
+ return session?.text(".failed", server);
584
+ }
585
+ });
493
586
  }
494
587
  __name(apply, "apply");
495
588
  // 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.1",
4
+ "version": "2.7.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"
@@ -34,5 +34,8 @@
34
34
  "@koishijs/plugin-database-sqlite": "^4.6.0",
35
35
  "@koishijs/plugin-help": "^2.4.5",
36
36
  "koishi": "^4.18.7"
37
+ },
38
+ "dependencies": {
39
+ "ping": "^1.0.0"
37
40
  }
38
41
  }