koishi-plugin-node-async-bot-all 1.5.1 → 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 +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +62 -4
- package/package.json +2 -1
- package/res/mtfSpawn.wav +0 -0
- package/res/mtfSpawnNoScp.wav +0 -0
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.
|
|
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
|
|
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
|
|
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}"}`);
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-node-async-bot-all",
|
|
3
3
|
"description": "NodeAsync Bot插件(自用)",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.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/mtfSpawn.wav
ADDED
|
Binary file
|
|
Binary file
|