koishi-plugin-node-async-bot-all 1.6.0 → 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
@@ -3,3 +3,4 @@ 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
5
  export declare function getAudioPath(name: string): Promise<string>;
6
+ export declare function getAudioList(): Promise<string[]>;
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)。" } }, 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 查看播放列表。" } } } };
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
 
@@ -51,9 +51,11 @@ var import_koishi = require("koishi");
51
51
  var import_os = __toESM(require("os"));
52
52
 
53
53
  // package.json
54
- var version = "1.6.0";
54
+ var version = "1.7.0";
55
55
 
56
56
  // src/fun.ts
57
+ var import_fs = __toESM(require("fs"));
58
+ var import_path = __toESM(require("path"));
57
59
  function getSystemName() {
58
60
  return import_os.default.type() + " " + import_os.default.release();
59
61
  }
@@ -134,12 +136,10 @@ async function fetchWithTimeout(url, options = {}, timeout = 5e3) {
134
136
  }
135
137
  __name(fetchWithTimeout, "fetchWithTimeout");
136
138
  async function readInfoFile() {
137
- const fs2 = require("node:fs/promises");
138
- const path = require("path");
139
139
  let info;
140
140
  try {
141
- const aPath = path.resolve(__dirname, "..") + path.sep + "res" + path.sep + "info.txt";
142
- info = await fs2.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");
143
143
  info = info.toString().replace("&version;", version);
144
144
  } catch (e) {
145
145
  info = e.message;
@@ -148,13 +148,18 @@ async function readInfoFile() {
148
148
  }
149
149
  __name(readInfoFile, "readInfoFile");
150
150
  async function getAudioPath(name2) {
151
- const path = require("path");
152
- return path.resolve(__dirname, "..") + path.sep + "res" + path.sep + name2 + ".wav";
151
+ return import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + name2 + ".wav";
153
152
  }
154
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");
155
160
 
156
161
  // src/index.ts
157
- var import_fs = __toESM(require("fs"));
162
+ var import_fs2 = __toESM(require("fs"));
158
163
  var inject = ["silk"];
159
164
  var name = "node-async-bot-all";
160
165
  async function getServer(ctx, session) {
@@ -336,6 +341,58 @@ async function getRW(ctx, session) {
336
341
  return msg;
337
342
  }
338
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");
339
396
  function apply(ctx) {
340
397
  ctx.i18n.define("zh-CN", require_zh_CN());
341
398
  ctx.command("cx").action(async ({ session }) => {
@@ -379,51 +436,15 @@ function apply(ctx) {
379
436
  }
380
437
  });
381
438
  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);
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);
409
446
  } 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
- }
447
+ return session.text(".unknown", cassie);
427
448
  }
428
449
  });
429
450
  }
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.6.0",
4
+ "version": "1.7.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
package/res/list.txt ADDED
@@ -0,0 +1,6 @@
1
+ 九尾狐入场
2
+ 九尾狐入场无SCP
3
+ 取消核弹
4
+ 轻收30秒
5
+ 轻收关闭
6
+ 核弹90秒