koishi-plugin-node-async-bot-all 1.11.0 → 2.0.1

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.
@@ -0,0 +1,7 @@
1
+ import { Context } from 'koishi';
2
+ export declare function getServer(ctx: Context, session: any): Promise<object>;
3
+ export declare function getStatus(ctx: Context, session: any): Promise<object>;
4
+ export declare function getRandom(ctx: Context, session: any, min: number, max: number): Promise<object>;
5
+ export declare function getInfo(ctx: Context, session: any): Promise<object>;
6
+ export declare function getRW(ctx: Context, session: any): Promise<object>;
7
+ export declare function getCASSIE(ctx: Context, session: any, name: string): Promise<object>;
package/lib/fun.d.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import { Context } from "koishi";
1
2
  export declare function getSystemUsage(): Promise<object>;
2
3
  export declare function getHongKongTime(): string;
3
4
  export declare function fetchWithTimeout(url: string, options: {}, timeout: number, log: any): Promise<Response>;
4
- export declare function readInfoFile(): Promise<string>;
5
+ export declare function readInfoFile(ctx: Context): Promise<string>;
5
6
  export declare function getAudioPath(name: string): Promise<string>;
6
7
  export declare function getAudioList(): Promise<string[]>;
8
+ export declare function formatTimestampDiff(start: number, end: number): string;
package/lib/index.d.ts CHANGED
@@ -1,10 +1,25 @@
1
- import { Context } from 'koishi';
1
+ import { Context, Schema } from 'koishi';
2
2
  import SilkService from 'koishi-plugin-silk';
3
- export declare const inject: readonly ["silk"];
3
+ export declare const inject: string[];
4
4
  declare module 'koishi' {
5
5
  interface Context {
6
6
  silk: SilkService;
7
7
  }
8
+ interface Tables {
9
+ botData: botDataTables;
10
+ }
11
+ }
12
+ interface botDataTables {
13
+ id: string;
14
+ data: string;
8
15
  }
9
16
  export declare const name = "node-async-bot-all";
17
+ export declare const usage = "\u8FD9\u662F\u4E00\u4E2A\u79C1\u6709\u63D2\u4EF6\u3002";
18
+ export interface Config {
19
+ cxAPI: string;
20
+ rwAPI: string;
21
+ timeout: number;
22
+ }
23
+ export declare const Config: Schema<Config>;
10
24
  export declare function apply(ctx: Context): void;
25
+ export {};
package/lib/index.js CHANGED
@@ -33,27 +33,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  // src/locales/zh-CN.yml
34
34
  var require_zh_CN = __commonJS({
35
35
  "src/locales/zh-CN.yml"(exports2, module2) {
36
- module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", msgNoPlayer: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}", 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)。" } }, cassie: { description: "发送 C.A.S.S.I.E. 语音。", usage: "缺少参数时返回语音列表。\n使用示例:", examples: "cassie mtfSpawn 播放当机动特遣队重生并且SCP还活着时的语音。", messages: { msg: "{time}\n【播放列表】\n{data}", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
36
+ module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", msgNoPlayer: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n➣ 协议版本:{protocol}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\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)。" } }, cassie: { description: "发送 C.A.S.S.I.E. 语音。", usage: "缺少参数时返回语音列表。\n使用示例:", examples: "cassie mtfSpawn 播放当机动特遣队重生并且SCP还活着时的语音。", messages: { msg: "{time}\n【播放列表】\n{data}", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
37
37
  }
38
38
  });
39
39
 
40
40
  // src/index.ts
41
41
  var src_exports = {};
42
42
  __export(src_exports, {
43
+ Config: () => Config,
43
44
  apply: () => apply,
44
45
  inject: () => inject,
45
- name: () => name
46
+ name: () => name,
47
+ usage: () => usage
46
48
  });
47
49
  module.exports = __toCommonJS(src_exports);
48
50
  var import_koishi = require("koishi");
49
51
 
50
52
  // src/fun.ts
51
53
  var import_os = __toESM(require("os"));
52
-
53
- // package.json
54
- var version = "1.11.0";
55
-
56
- // src/fun.ts
57
54
  var import_fs = __toESM(require("fs"));
58
55
  var import_path = __toESM(require("path"));
59
56
  function getSystemName() {
@@ -137,12 +134,15 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3, log) {
137
134
  }
138
135
  }
139
136
  __name(fetchWithTimeout, "fetchWithTimeout");
140
- async function readInfoFile() {
137
+ async function readInfoFile(ctx) {
141
138
  let info;
142
139
  try {
143
140
  const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "info.txt";
144
141
  info = await import_fs.default.promises.readFile(aPath, "utf8");
145
- info = info.toString().replace("&version;", version);
142
+ info = info.toString().replace(
143
+ "&version;",
144
+ (await ctx.database.get("botData", "version"))[0].data
145
+ );
146
146
  } catch (e) {
147
147
  info = e.message;
148
148
  }
@@ -159,11 +159,17 @@ async function getAudioList() {
159
159
  return data.split(/\r?\n/).filter(Boolean);
160
160
  }
161
161
  __name(getAudioList, "getAudioList");
162
+ function formatTimestampDiff(start, end) {
163
+ const diff = Math.abs(end - start);
164
+ const hours = Math.floor(diff / 3600);
165
+ const minutes = Math.floor(diff % 3600 / 60);
166
+ const seconds = diff % 60;
167
+ return `${hours} 时 ${minutes} 分 ${seconds} 秒`;
168
+ }
169
+ __name(formatTimestampDiff, "formatTimestampDiff");
162
170
 
163
- // src/index.ts
171
+ // src/commands.ts
164
172
  var import_fs2 = __toESM(require("fs"));
165
- var inject = ["silk"];
166
- var name = "node-async-bot-all";
167
173
  async function getServer(ctx, session) {
168
174
  const log = ctx.logger("cx");
169
175
  log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
@@ -174,7 +180,7 @@ async function getServer(ctx, session) {
174
180
  const time = getHongKongTime();
175
181
  if (session.event.guild.id == "757729218" || session.event.guild.id == "1047732162") {
176
182
  try {
177
- const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3, log);
183
+ const response = await fetchWithTimeout(ctx.config.cxAPI, {}, ctx.config.timeout, log);
178
184
  if (response.ok) {
179
185
  data = await response.text();
180
186
  log.info("Server data: " + data);
@@ -268,11 +274,16 @@ async function getStatus(ctx, session) {
268
274
  "success": 1
269
275
  };
270
276
  } else {
277
+ log.info((await ctx.database.get("botData", "uptime"))[0].data);
271
278
  msg = {
272
279
  "time": time,
273
280
  "name": vMsg["name"],
274
281
  "cpu": vMsg["cpu"],
275
282
  "memory": vMsg["memory"],
283
+ "online": formatTimestampDiff(
284
+ Number((await ctx.database.get("botData", "uptime"))[0].data),
285
+ session.event.timestamp.toString().substring(0, 10)
286
+ ),
276
287
  "success": 0
277
288
  };
278
289
  }
@@ -309,7 +320,7 @@ async function getInfo(ctx, session) {
309
320
  log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
310
321
  const time = getHongKongTime();
311
322
  let msg;
312
- let data = await readInfoFile();
323
+ let data = await readInfoFile(ctx);
313
324
  if (!data.includes("&time;")) {
314
325
  log.error("Error: " + data);
315
326
  msg = {
@@ -337,7 +348,7 @@ async function getRW(ctx, session) {
337
348
  let data;
338
349
  const time = getHongKongTime();
339
350
  try {
340
- const response = await fetchWithTimeout("https://api.tasaed.top/rw/", {}, 8e3, log);
351
+ const response = await fetchWithTimeout(ctx.config.rwAPI, {}, ctx.config.timeout, log);
341
352
  if (response.ok) {
342
353
  data = await response.text();
343
354
  log.info("Server data: " + data);
@@ -400,11 +411,10 @@ async function getCASSIE(ctx, session, name2) {
400
411
  log.info("Sent: .failed");
401
412
  log.info(msg);
402
413
  } else {
403
- const base64Data = bufferToSend.toString("base64");
404
414
  log.info("Sent: A audio file.");
405
415
  msg = {
406
416
  "time": time,
407
- "data": base64Data,
417
+ "data": bufferToSend,
408
418
  "success": 0
409
419
  };
410
420
  }
@@ -430,8 +440,39 @@ async function getCASSIE(ctx, session, name2) {
430
440
  }
431
441
  }
432
442
  __name(getCASSIE, "getCASSIE");
443
+
444
+ // package.json
445
+ var version = "2.0.1";
446
+
447
+ // src/index.ts
448
+ var inject = ["silk", "database"];
449
+ var name = "node-async-bot-all";
450
+ var usage = "这是一个私有插件。";
451
+ var Config = import_koishi.Schema.intersect([
452
+ import_koishi.Schema.object({
453
+ timeout: import_koishi.Schema.number().default(8e3).description("超时时间(毫秒)")
454
+ }).description("基础"),
455
+ import_koishi.Schema.object({
456
+ cxAPI: import_koishi.Schema.string().default("https://api.tasaed.top/get/minecraftServer/").description("查询 API")
457
+ }).description("查询"),
458
+ import_koishi.Schema.object({
459
+ rwAPI: import_koishi.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
460
+ }).description("随机文本")
461
+ ]).description("基础设置");
433
462
  function apply(ctx) {
434
463
  ctx.i18n.define("zh-CN", require_zh_CN());
464
+ ctx.on("ready", async () => {
465
+ ctx.model.extend("botData", {
466
+ // 向表中注入字符串
467
+ id: "string",
468
+ data: "string"
469
+ });
470
+ const date = /* @__PURE__ */ new Date();
471
+ await ctx.database.upsert("botData", [
472
+ { id: "uptime", data: date.getTime().toString().substring(0, 10) },
473
+ { id: "version", data: version }
474
+ ]);
475
+ });
435
476
  ctx.command("cx").action(async ({ session }) => {
436
477
  const cx = await getServer(ctx, session);
437
478
  if (cx["success"] == 0) {
@@ -477,7 +518,7 @@ function apply(ctx) {
477
518
  ctx.command("cassie [名称:string]").action(async ({ session }, name2) => {
478
519
  const cassie = await getCASSIE(ctx, session, name2);
479
520
  if (cassie["success"] == 0) {
480
- return (0, import_koishi.h)("audio", { src: `base64://${cassie["data"]}` });
521
+ return import_koishi.h.audio(cassie["data"], "audio/silk");
481
522
  } else if (cassie["success"] == 1) {
482
523
  return [`${session.text(".msg", cassie)}`];
483
524
  } else if (cassie["success"] == 2) {
@@ -490,7 +531,9 @@ function apply(ctx) {
490
531
  __name(apply, "apply");
491
532
  // Annotate the CommonJS export names for ESM import in node:
492
533
  0 && (module.exports = {
534
+ Config,
493
535
  apply,
494
536
  inject,
495
- name
537
+ name,
538
+ usage
496
539
  });
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": "1.11.0",
4
+ "version": "2.0.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [