koishi-plugin-node-async-bot-all 1.5.0 → 1.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/fun.d.ts CHANGED
@@ -2,3 +2,4 @@ export declare function getSystemUsage(): Promise<object>;
2
2
  export declare function getHongKongTime(): string;
3
3
  export declare function fetchWithTimeout(url: string, options?: {}, timeout?: number): Promise<Response>;
4
4
  export declare function readInfoFile(): Promise<string>;
5
+ export declare function getAudioPath(name: string): Promise<string>;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
1
  import { Context } from 'koishi';
2
+ import SilkService from 'koishi-plugin-silk';
3
+ export declare const inject: readonly ["silk"];
4
+ declare module 'koishi' {
5
+ interface Context {
6
+ silk: SilkService;
7
+ }
8
+ }
2
9
  export declare const name = "node-async-bot-all";
3
10
  export declare function apply(ctx: Context): void;
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ 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进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。" } }, 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)。" } } } };
36
+ module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}\n【服务器当前人数】\n➣ {version}:{players}\n进服指南请在群公告中查看。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}\n请稍后重试。", timeout: "请求超时。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。" } }, 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【播放列表】\n1. mtfSpawn\n2. mtfSpawnNoScp", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
37
37
  }
38
38
  });
39
39
 
@@ -41,15 +41,17 @@ var require_zh_CN = __commonJS({
41
41
  var src_exports = {};
42
42
  __export(src_exports, {
43
43
  apply: () => apply,
44
+ inject: () => inject,
44
45
  name: () => name
45
46
  });
46
47
  module.exports = __toCommonJS(src_exports);
48
+ var import_koishi = require("koishi");
47
49
 
48
50
  // src/fun.ts
49
51
  var import_os = __toESM(require("os"));
50
52
 
51
53
  // package.json
52
- var version = "1.5.0";
54
+ var version = "1.6.0";
53
55
 
54
56
  // src/fun.ts
55
57
  function getSystemName() {
@@ -132,12 +134,12 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
132
134
  }
133
135
  __name(fetchWithTimeout, "fetchWithTimeout");
134
136
  async function readInfoFile() {
135
- const fs = require("node:fs/promises");
137
+ const fs2 = require("node:fs/promises");
136
138
  const path = require("path");
137
139
  let info;
138
140
  try {
139
141
  const aPath = path.resolve(__dirname, "..") + path.sep + "res" + path.sep + "info.txt";
140
- info = await fs.readFile(aPath, "utf8");
142
+ info = await fs2.readFile(aPath, "utf8");
141
143
  info = info.toString().replace("&version;", version);
142
144
  } catch (e) {
143
145
  info = e.message;
@@ -145,8 +147,15 @@ async function readInfoFile() {
145
147
  return info;
146
148
  }
147
149
  __name(readInfoFile, "readInfoFile");
150
+ async function getAudioPath(name2) {
151
+ const path = require("path");
152
+ return path.resolve(__dirname, "..") + path.sep + "res" + path.sep + name2 + ".wav";
153
+ }
154
+ __name(getAudioPath, "getAudioPath");
148
155
 
149
156
  // src/index.ts
157
+ var import_fs = __toESM(require("fs"));
158
+ var inject = ["silk"];
150
159
  var name = "node-async-bot-all";
151
160
  async function getServer(ctx, session) {
152
161
  ctx.logger.info(`Got: {"command":"${session.text(".message")}","form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
@@ -155,7 +164,7 @@ async function getServer(ctx, session) {
155
164
  let data;
156
165
  let error;
157
166
  const time = getHongKongTime();
158
- if (session.event.guild.id == "757729218" || session.event.guild.id == "#") {
167
+ if (session.event.guild.id == "757729218" || session.event.guild.id == "1047732162") {
159
168
  try {
160
169
  const response = await fetchWithTimeout("https://api.tasaed.top/get/minecraftServer/", {}, 8e3);
161
170
  if (response.ok) {
@@ -369,10 +378,59 @@ function apply(ctx) {
369
378
  return session.text(".failed2", rw);
370
379
  }
371
380
  });
381
+ ctx.command("cassie [名称:string]").action(async ({ session }, name2) => {
382
+ ctx.logger.info(`Got: {"command":"${session.text(".message")}","form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
383
+ const msg = {
384
+ time: getHongKongTime()
385
+ };
386
+ let type;
387
+ switch (name2) {
388
+ case void 0:
389
+ type = 1;
390
+ break;
391
+ case "mtfSpawn":
392
+ type = 2;
393
+ break;
394
+ case "mtfSpawnNoScp":
395
+ type = 3;
396
+ break;
397
+ default:
398
+ type = 0;
399
+ break;
400
+ }
401
+ if (type == 0) {
402
+ ctx.logger.info("Sent: .unknown");
403
+ ctx.logger.info(msg);
404
+ return session.text(".unknown", msg);
405
+ } else if (type == 1) {
406
+ ctx.logger.info("Sent: .msg");
407
+ ctx.logger.info(msg);
408
+ return session.text(".msg", msg);
409
+ } else {
410
+ const fullPath = await getAudioPath(name2);
411
+ try {
412
+ const fileBuffer = await import_fs.default.promises.readFile(fullPath);
413
+ ctx.logger.info(fullPath);
414
+ const wavInfo = ctx.silk.getWavFileInfo(fileBuffer);
415
+ ctx.logger.info(wavInfo);
416
+ const encodeResult = await ctx.silk.encode(fileBuffer, wavInfo.fmt.sampleRate);
417
+ const bufferToSend = Buffer.from(encodeResult.data);
418
+ const base64Data = bufferToSend.toString("base64");
419
+ ctx.logger.info("Sent: A audio file.");
420
+ return (0, import_koishi.h)("audio", { src: `base64://${base64Data}` });
421
+ } catch (e) {
422
+ ctx.logger.error("发送失败:" + e.message);
423
+ ctx.logger.info("Sent: .failed");
424
+ ctx.logger.info(msg);
425
+ return session.text(".failed", msg);
426
+ }
427
+ }
428
+ });
372
429
  }
373
430
  __name(apply, "apply");
374
431
  // Annotate the CommonJS export names for ESM import in node:
375
432
  0 && (module.exports = {
376
433
  apply,
434
+ inject,
377
435
  name
378
436
  });
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "koishi-plugin-node-async-bot-all",
3
3
  "description": "NodeAsync Bot插件(自用)",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
+ "contributors": [
8
+ "ccd2s <tasaedem@outlook.com>"
9
+ ],
7
10
  "files": [
8
11
  "lib",
9
12
  "dist",
10
13
  "res"
11
14
  ],
12
15
  "license": "AGPL-3.0",
16
+ "homepage": "https://www.tasaed.top",
13
17
  "keywords": [
14
18
  "chatbot",
15
19
  "koishi",
@@ -21,14 +25,14 @@
21
25
  },
22
26
  "repository": {
23
27
  "type": "git",
24
- "url": "git+https://github.com/ccd2s/node-async-bot-all"
28
+ "url": "https://github.com/ccd2s/node-async-bot-all"
25
29
  },
26
30
  "devDependencies": {
27
31
  "@koishijs/client": "^5.30.4"
28
32
  },
29
33
  "peerDependencies": {
30
- "@koishijs/plugin-console": "^5.30.4",
31
34
  "@koishijs/plugin-help": "^2.4.5",
35
+ "koishi-plugin-silk": "^2.0.1",
32
36
  "koishi": "^4.18.7"
33
37
  }
34
38
  }
Binary file
Binary file