koishi-plugin-node-async-bot-all 2.11.1 → 2.13.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
@@ -7,3 +7,4 @@ export declare function getRW(ctx: Context, session: Session): Promise<Object>;
7
7
  export declare function getBA(ctx: Context, session: Session): Promise<Number>;
8
8
  export declare function serverTest(ctx: Context, session: Session): Promise<Object>;
9
9
  export declare function getSteam(ctx: Context, session: Session, id: number): Promise<Object>;
10
+ export declare function getMeme(ctx: Context, session: Session): Promise<Object>;
package/lib/fun.d.ts CHANGED
@@ -13,3 +13,8 @@ export declare function hostPing(host: string): Promise<{
13
13
  packetLoss?: string;
14
14
  }>;
15
15
  export declare function random(type: number | undefined, data: any, data2?: any): number;
16
+ export declare function getHttp(log: any, url: string, timeout: number): Promise<{
17
+ success: boolean;
18
+ data: object;
19
+ error?: boolean;
20
+ }>;
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Context, Schema } from 'koishi';
1
+ import { Context, Dict, Schema } from 'koishi';
2
2
  export declare const inject: string[];
3
3
  declare module 'koishi' {
4
4
  interface Tables {
@@ -21,7 +21,9 @@ export interface Config {
21
21
  rwAPI: string;
22
22
  timeout: number;
23
23
  baAPI: string[];
24
+ serverPing: Dict<string>;
24
25
  steamAPI: string;
26
+ memesAPI: Dict<string>;
25
27
  }
26
28
  export declare const Config: Schema<Config>;
27
29
  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: { cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 备注:{note}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 备注:{note}", 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}", error: "执行错误。", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败({data})。" } }, randomba: { description: "随机BA图。", messages: { wait: "{time}\n请等待图片上传(可能较慢)。" } }, servertest: { description: "Ping服务器。", messages: { msg: "{time}\n== Ping {host} ==\n状态:{alive}\n丢包率:{packetLoss}\n返回IP:{ip}", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\nPing 失败:{data}" } }, steamid: { description: "将 Steam 好友码(SteamID 3)转为 SteamID 64。", messages: { msg: "{time}\n转换结果:{data}", failed: "{time}\n转换失败:{data}", null: "参数 Steam 好友码(SteamID 3) 不得为空。" } } } };
37
+ module2.exports = { commands: { cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 备注:{note}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 备注:{note}", 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}", error: "执行错误。", failed1: "{time}\n获取失败(1)。", failed2: "{time}\n获取失败({data})。" } }, randomba: { description: "随机BA图。", messages: { wait: "{time}\n请等待图片上传(可能较慢)。" } }, servertest: { description: "Ping服务器。", messages: { msg: "{time}\n== Ping {host} ==\n状态:{alive}\n丢包率:{packetLoss}\n返回IP:{ip}", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\nPing 失败:{data}" } }, steamid: { description: "将 Steam 好友码(SteamID 3)转为 SteamID 64。", messages: { msg: "{time}\n转换结果:{data}", failed: "{time}\n转换失败:{data}", null: "参数 Steam 好友码(SteamID 3) 不得为空。", error: "执行错误。" } }, meme: { description: "群友的怪话!", messages: { msg: "{time}\n{image}\n{title}", failed: "{time}\n获取失败:{data}", forbidden: "{time}\n此指令不允许在本群使用。", error: "执行错误。" } } } };
38
38
  }
39
39
  });
40
40
 
@@ -230,6 +230,37 @@ function random(type = 0, data, data2) {
230
230
  }
231
231
  }
232
232
  __name(random, "random");
233
+ async function getHttp(log, url, timeout) {
234
+ let data;
235
+ try {
236
+ const response = await fetchWithTimeout(url, {}, timeout, log);
237
+ if (response.ok) {
238
+ data = await response.text();
239
+ log.info("Server data: " + data);
240
+ return {
241
+ "data": JSON.parse(data),
242
+ "success": true
243
+ };
244
+ } else {
245
+ data = await response.text();
246
+ log.error(`Error fetching data: ${data}`);
247
+ data = JSON.parse(data);
248
+ return {
249
+ "data": JSON.parse(data),
250
+ "error": false,
251
+ "success": false
252
+ };
253
+ }
254
+ } catch (err) {
255
+ log.error(`Request error: ${err.message}`);
256
+ return {
257
+ "data": { "name": err.name, "message": err.message },
258
+ "error": true,
259
+ "success": false
260
+ };
261
+ }
262
+ }
263
+ __name(getHttp, "getHttp");
233
264
 
234
265
  // src/commands.ts
235
266
  async function getServer(ctx, session) {
@@ -434,37 +465,36 @@ async function getRW(ctx, session) {
434
465
  let msg;
435
466
  let data;
436
467
  const time = getHongKongTime();
437
- try {
438
- const response = await fetchWithTimeout(ctx.config.rwAPI, {}, ctx.config.timeout, log);
439
- if (response.ok) {
440
- data = await response.text();
441
- log.info("Server data: " + data);
468
+ const response = await getHttp(log, ctx.config.rwAPI + "?format=json", ctx.config.timeout);
469
+ if (response.success) {
470
+ data = response.data;
471
+ msg = {
472
+ "time": time,
473
+ "data": data["data"],
474
+ "success": 0
475
+ };
476
+ log.info("Sent:");
477
+ log.info(msg);
478
+ } else {
479
+ if (response.error) {
480
+ data = response.data;
442
481
  msg = {
443
482
  "time": time,
444
- "data": data,
445
- "success": 0
483
+ "data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
484
+ "success": 2
446
485
  };
447
486
  log.info("Sent:");
448
487
  log.info(msg);
449
488
  } else {
450
- data = await response.text();
451
- log.error(`Error fetching data: ${data}`);
489
+ data = response.data;
452
490
  msg = {
453
491
  "time": time,
492
+ "data": data["data"],
454
493
  "success": 1
455
494
  };
456
495
  log.info("Sent:");
457
496
  log.info(msg);
458
497
  }
459
- } catch (err) {
460
- log.error(`Request error: ${err.message}`);
461
- msg = {
462
- "time": time,
463
- "data": err.name === "AbortError" ? session.text(".error") : err.message,
464
- "success": 2
465
- };
466
- log.info("Sent:");
467
- log.info(msg);
468
498
  }
469
499
  return msg;
470
500
  }
@@ -526,23 +556,28 @@ async function getSteam(ctx, session, id) {
526
556
  let msg;
527
557
  let data;
528
558
  const time = getHongKongTime();
529
- try {
530
- const response = await fetchWithTimeout(ctx.config.steamAPI + `?format=json&id=${id}`, {}, ctx.config.timeout, log);
531
- if (response.ok) {
532
- data = await response.text();
533
- log.info("Server data: " + data);
534
- data = JSON.parse(data);
559
+ const response = await getHttp(log, ctx.config.steamAPI + `?format=json&id=${id}`, ctx.config.timeout);
560
+ if (response.success) {
561
+ data = response.data;
562
+ msg = {
563
+ "time": time,
564
+ "data": data["data"],
565
+ "success": 0
566
+ };
567
+ log.info("Sent:");
568
+ log.info(msg);
569
+ } else {
570
+ if (response.error) {
571
+ data = response.data;
535
572
  msg = {
536
573
  "time": time,
537
- "data": data["data"],
538
- "success": 0
574
+ "data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
575
+ "success": 2
539
576
  };
540
577
  log.info("Sent:");
541
578
  log.info(msg);
542
579
  } else {
543
- data = await response.text();
544
- log.error(`Error fetching data: ${data}`);
545
- data = JSON.parse(data);
580
+ data = response.data;
546
581
  msg = {
547
582
  "time": time,
548
583
  "data": data["data"],
@@ -551,22 +586,64 @@ async function getSteam(ctx, session, id) {
551
586
  log.info("Sent:");
552
587
  log.info(msg);
553
588
  }
554
- } catch (err) {
555
- log.error(`Request error: ${err.message}`);
589
+ }
590
+ return msg;
591
+ }
592
+ __name(getSteam, "getSteam");
593
+ async function getMeme(ctx, session) {
594
+ const log = ctx.logger("getMeme");
595
+ log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
596
+ let msg;
597
+ let data;
598
+ const time = getHongKongTime();
599
+ const api = ctx.config.memesAPI[`${session.event.guild?.id}`];
600
+ if (api == void 0) {
556
601
  msg = {
557
602
  "time": time,
558
- "data": err.name === "AbortError" ? session.text(".error") : err.message,
559
603
  "success": 2
560
604
  };
561
605
  log.info("Sent:");
562
606
  log.info(msg);
607
+ return msg;
608
+ }
609
+ const response = await getHttp(log, api, ctx.config.timeout);
610
+ if (response.success) {
611
+ data = response.data;
612
+ msg = {
613
+ "time": time,
614
+ "title": data["data"]["title"],
615
+ "image": import_koishi2.h.image(data["data"]["image"]),
616
+ "success": 0
617
+ };
618
+ log.info("Sent:");
619
+ log.info(msg);
620
+ } else {
621
+ if (response.error) {
622
+ data = response.data;
623
+ msg = {
624
+ "time": time,
625
+ "data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
626
+ "success": 1
627
+ };
628
+ log.info("Sent:");
629
+ log.info(msg);
630
+ } else {
631
+ data = response.data;
632
+ msg = {
633
+ "time": time,
634
+ "data": data["data"],
635
+ "success": 1
636
+ };
637
+ log.info("Sent:");
638
+ log.info(msg);
639
+ }
563
640
  }
564
641
  return msg;
565
642
  }
566
- __name(getSteam, "getSteam");
643
+ __name(getMeme, "getMeme");
567
644
 
568
645
  // package.json
569
- var version = "2.11.1";
646
+ var version = "2.13.0";
570
647
 
571
648
  // src/index.ts
572
649
  var inject = ["database"];
@@ -596,7 +673,10 @@ var Config = import_koishi3.Schema.intersect([
596
673
  }).description("服之测测(Ping)"),
597
674
  import_koishi3.Schema.object({
598
675
  steamAPI: import_koishi3.Schema.string().default("https://api.tasaed.top/get/steamid/").description("转换 Steam ID API")
599
- }).description("转换 Steam ID")
676
+ }).description("转换 Steam ID"),
677
+ import_koishi3.Schema.object({
678
+ memesAPI: import_koishi3.Schema.dict(String).role("table").description("群友 meme API")
679
+ }).description("群友 meme")
600
680
  ]).description("基础设置");
601
681
  function apply(ctx) {
602
682
  ctx.i18n.define("zh-CN", require_zh_CN());
@@ -676,6 +756,16 @@ function apply(ctx) {
676
756
  return session?.text(".failed", steam);
677
757
  }
678
758
  });
759
+ ctx.command("meme").alias("memes").action(async ({ session }) => {
760
+ const meme = await getMeme(ctx, session);
761
+ if (meme["success"] == 0) {
762
+ return session?.text(".msg", meme);
763
+ } else if (meme["success"] == 1) {
764
+ return session?.text(".failed", meme);
765
+ } else {
766
+ return session?.text(".forbidden", meme);
767
+ }
768
+ });
679
769
  }
680
770
  __name(apply, "apply");
681
771
  // 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.11.1",
4
+ "version": "2.13.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [