koishi-plugin-node-async-bot-all 1.5.1 → 1.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/fun.d.ts CHANGED
@@ -2,3 +2,5 @@ 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>;
6
+ export declare function getAudioList(): 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【播放列表】\n{data}", failed: "{time}\n发送失败,请稍后重试。", unknown: "{time}\n未知语音,发送 /cassie 查看播放列表。" } } } };
37
37
  }
38
38
  });
39
39
 
@@ -41,17 +41,21 @@ 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.1";
54
+ var version = "1.7.0";
53
55
 
54
56
  // src/fun.ts
57
+ var import_fs = __toESM(require("fs"));
58
+ var import_path = __toESM(require("path"));
55
59
  function getSystemName() {
56
60
  return import_os.default.type() + " " + import_os.default.release();
57
61
  }
@@ -132,12 +136,10 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
132
136
  }
133
137
  __name(fetchWithTimeout, "fetchWithTimeout");
134
138
  async function readInfoFile() {
135
- const fs = require("node:fs/promises");
136
- const path = require("path");
137
139
  let info;
138
140
  try {
139
- const aPath = path.resolve(__dirname, "..") + path.sep + "res" + path.sep + "info.txt";
140
- info = await fs.readFile(aPath, "utf8");
141
+ const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "info.txt";
142
+ info = await import_fs.default.promises.readFile(aPath, "utf8");
141
143
  info = info.toString().replace("&version;", version);
142
144
  } catch (e) {
143
145
  info = e.message;
@@ -145,8 +147,20 @@ async function readInfoFile() {
145
147
  return info;
146
148
  }
147
149
  __name(readInfoFile, "readInfoFile");
150
+ async function getAudioPath(name2) {
151
+ return import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + name2 + ".wav";
152
+ }
153
+ __name(getAudioPath, "getAudioPath");
154
+ async function getAudioList() {
155
+ const listPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "list.txt";
156
+ const data = await import_fs.default.promises.readFile(listPath, "utf-8");
157
+ return data.split(/\r?\n/).filter(Boolean);
158
+ }
159
+ __name(getAudioList, "getAudioList");
148
160
 
149
161
  // src/index.ts
162
+ var import_fs2 = __toESM(require("fs"));
163
+ var inject = ["silk"];
150
164
  var name = "node-async-bot-all";
151
165
  async function getServer(ctx, session) {
152
166
  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}"}`);
@@ -327,6 +341,58 @@ async function getRW(ctx, session) {
327
341
  return msg;
328
342
  }
329
343
  __name(getRW, "getRW");
344
+ async function getCASSIE(ctx, session, name2) {
345
+ 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}"}`);
346
+ let msg;
347
+ const time = getHongKongTime();
348
+ const list = await getAudioList();
349
+ if (name2 == void 0) {
350
+ msg = {
351
+ "time": time,
352
+ "data": list.map((fruit, index) => `${index + 1}. ${fruit}`).join("\n"),
353
+ "success": 1
354
+ };
355
+ ctx.logger.info("Sent: .msg");
356
+ ctx.logger.info(msg);
357
+ return msg;
358
+ } else if (list.includes(name2)) {
359
+ const fullPath = await getAudioPath(name2);
360
+ try {
361
+ const fileBuffer = await import_fs2.default.promises.readFile(fullPath);
362
+ ctx.logger.info(fullPath);
363
+ const wavInfo = ctx.silk.getWavFileInfo(fileBuffer);
364
+ ctx.logger.info(wavInfo);
365
+ const encodeResult = await ctx.silk.encode(fileBuffer, wavInfo.fmt.sampleRate);
366
+ const bufferToSend = Buffer.from(encodeResult.data);
367
+ const base64Data = bufferToSend.toString("base64");
368
+ ctx.logger.info("Sent: A audio file.");
369
+ msg = {
370
+ "time": time,
371
+ "data": base64Data,
372
+ "success": 0
373
+ };
374
+ return msg;
375
+ } catch (e) {
376
+ msg = {
377
+ "time": time,
378
+ "success": 2
379
+ };
380
+ ctx.logger.error("发送失败:" + e.message);
381
+ ctx.logger.info("Sent: .failed");
382
+ ctx.logger.info(msg);
383
+ return msg;
384
+ }
385
+ } else {
386
+ msg = {
387
+ "time": time,
388
+ "success": 3
389
+ };
390
+ ctx.logger.info("Sent: .unknown");
391
+ ctx.logger.info(msg);
392
+ return msg;
393
+ }
394
+ }
395
+ __name(getCASSIE, "getCASSIE");
330
396
  function apply(ctx) {
331
397
  ctx.i18n.define("zh-CN", require_zh_CN());
332
398
  ctx.command("cx").action(async ({ session }) => {
@@ -369,10 +435,23 @@ function apply(ctx) {
369
435
  return session.text(".failed2", rw);
370
436
  }
371
437
  });
438
+ ctx.command("cassie [名称:string]").action(async ({ session }, name2) => {
439
+ const cassie = await getCASSIE(ctx, session, name2);
440
+ if (cassie["success"] == 0) {
441
+ return (0, import_koishi.h)("audio", { src: `base64://${cassie["data"]}` });
442
+ } else if (cassie["success"] == 1) {
443
+ return session.text(".msg", cassie);
444
+ } else if (cassie["success"] == 2) {
445
+ return session.text(".failed", cassie);
446
+ } else {
447
+ return session.text(".unknown", cassie);
448
+ }
449
+ });
372
450
  }
373
451
  __name(apply, "apply");
374
452
  // Annotate the CommonJS export names for ESM import in node:
375
453
  0 && (module.exports = {
376
454
  apply,
455
+ inject,
377
456
  name
378
457
  });
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.5.1",
4
+ "version": "1.7.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
@@ -32,6 +32,7 @@
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@koishijs/plugin-help": "^2.4.5",
35
+ "koishi-plugin-silk": "^2.0.1",
35
36
  "koishi": "^4.18.7"
36
37
  }
37
38
  }
package/res/list.txt ADDED
@@ -0,0 +1,6 @@
1
+ 九尾狐入场
2
+ 九尾狐入场无SCP
3
+ 取消核弹
4
+ 轻收30秒
5
+ 轻收关闭
6
+ 核弹90秒