koishi-plugin-node-async-bot-all 1.10.0 → 2.0.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/commands.d.ts +7 -0
- package/lib/fun.d.ts +3 -1
- package/lib/index.d.ts +17 -2
- package/lib/index.js +64 -16
- package/package.json +1 -1
- package/res/slk//344/271/235/345/260/276/347/213/220/345/205/245/345/234/272.slk +0 -0
- package/res/slk//344/271/235/345/260/276/347/213/220/345/205/245/345/234/272/345/234/243/350/257/236/350/212/202.slk +0 -0
- package/res/slk//344/271/235/345/260/276/347/213/220/345/205/245/345/234/272/346/227/240SCP.slk +0 -0
- package/res/slk//346/240/270/345/274/27190/347/247/222.slk +0 -0
- package/res/slk//346/240/270/345/274/271/351/207/215/346/226/260/345/220/257/345/212/25030/347/247/222.slk +0 -0
- package/res/slk//346/240/270/345/274/271/351/207/215/346/226/260/345/220/257/345/212/25050/347/247/222.slk +0 -0
- package/res/slk//350/275/273/346/224/26610/345/210/206/351/222/237.slk +0 -0
- package/res/slk//350/275/273/346/224/2661/345/210/206/351/222/237.slk +0 -0
- package/res/slk//350/275/273/346/224/26630/347/247/222.slk +0 -0
- package/res/slk//350/275/273/346/224/2665/345/210/206/351/222/237.slk +0 -0
|
@@ -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:
|
|
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: "请求超时。", 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.10.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(
|
|
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/
|
|
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(
|
|
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);
|
|
@@ -212,6 +218,10 @@ async function getServer(ctx, session) {
|
|
|
212
218
|
error = session.text(".host");
|
|
213
219
|
} else if (error.includes("Connection timed out")) {
|
|
214
220
|
error = session.text(".timeout");
|
|
221
|
+
} else if (error.includes("Server returned too few data")) {
|
|
222
|
+
error = session.text(".fewData");
|
|
223
|
+
} else if (error.includes("Server read timed out")) {
|
|
224
|
+
error = session.text(".timeout2");
|
|
215
225
|
}
|
|
216
226
|
} catch (e) {
|
|
217
227
|
if (dataError.includes("CDN节点请求源服务器超时")) {
|
|
@@ -264,11 +274,16 @@ async function getStatus(ctx, session) {
|
|
|
264
274
|
"success": 1
|
|
265
275
|
};
|
|
266
276
|
} else {
|
|
277
|
+
log.info((await ctx.database.get("botData", "uptime"))[0].data);
|
|
267
278
|
msg = {
|
|
268
279
|
"time": time,
|
|
269
280
|
"name": vMsg["name"],
|
|
270
281
|
"cpu": vMsg["cpu"],
|
|
271
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
|
+
),
|
|
272
287
|
"success": 0
|
|
273
288
|
};
|
|
274
289
|
}
|
|
@@ -305,7 +320,7 @@ async function getInfo(ctx, session) {
|
|
|
305
320
|
log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
|
|
306
321
|
const time = getHongKongTime();
|
|
307
322
|
let msg;
|
|
308
|
-
let data = await readInfoFile();
|
|
323
|
+
let data = await readInfoFile(ctx);
|
|
309
324
|
if (!data.includes("&time;")) {
|
|
310
325
|
log.error("Error: " + data);
|
|
311
326
|
msg = {
|
|
@@ -333,7 +348,7 @@ async function getRW(ctx, session) {
|
|
|
333
348
|
let data;
|
|
334
349
|
const time = getHongKongTime();
|
|
335
350
|
try {
|
|
336
|
-
const response = await fetchWithTimeout(
|
|
351
|
+
const response = await fetchWithTimeout(ctx.config.rwAPI, {}, ctx.config.timeout, log);
|
|
337
352
|
if (response.ok) {
|
|
338
353
|
data = await response.text();
|
|
339
354
|
log.info("Server data: " + data);
|
|
@@ -426,8 +441,39 @@ async function getCASSIE(ctx, session, name2) {
|
|
|
426
441
|
}
|
|
427
442
|
}
|
|
428
443
|
__name(getCASSIE, "getCASSIE");
|
|
444
|
+
|
|
445
|
+
// package.json
|
|
446
|
+
var version = "2.0.0";
|
|
447
|
+
|
|
448
|
+
// src/index.ts
|
|
449
|
+
var inject = ["silk", "database"];
|
|
450
|
+
var name = "node-async-bot-all";
|
|
451
|
+
var usage = "这是一个私有插件。";
|
|
452
|
+
var Config = import_koishi.Schema.intersect([
|
|
453
|
+
import_koishi.Schema.object({
|
|
454
|
+
timeout: import_koishi.Schema.number().default(8e3).description("超时时间(毫秒)")
|
|
455
|
+
}).description("基础"),
|
|
456
|
+
import_koishi.Schema.object({
|
|
457
|
+
cxAPI: import_koishi.Schema.string().default("https://api.tasaed.top/get/minecraftServer/").description("查询 API")
|
|
458
|
+
}).description("查询"),
|
|
459
|
+
import_koishi.Schema.object({
|
|
460
|
+
rwAPI: import_koishi.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
|
|
461
|
+
}).description("随机文本")
|
|
462
|
+
]).description("基础设置");
|
|
429
463
|
function apply(ctx) {
|
|
430
464
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
465
|
+
ctx.on("ready", async () => {
|
|
466
|
+
ctx.model.extend("botData", {
|
|
467
|
+
// 向表中注入字符串
|
|
468
|
+
id: "string",
|
|
469
|
+
data: "string"
|
|
470
|
+
});
|
|
471
|
+
const date = /* @__PURE__ */ new Date();
|
|
472
|
+
await ctx.database.upsert("botData", [
|
|
473
|
+
{ id: "uptime", data: date.getTime().toString().substring(0, 10) },
|
|
474
|
+
{ id: "version", data: version }
|
|
475
|
+
]);
|
|
476
|
+
});
|
|
431
477
|
ctx.command("cx").action(async ({ session }) => {
|
|
432
478
|
const cx = await getServer(ctx, session);
|
|
433
479
|
if (cx["success"] == 0) {
|
|
@@ -486,7 +532,9 @@ function apply(ctx) {
|
|
|
486
532
|
__name(apply, "apply");
|
|
487
533
|
// Annotate the CommonJS export names for ESM import in node:
|
|
488
534
|
0 && (module.exports = {
|
|
535
|
+
Config,
|
|
489
536
|
apply,
|
|
490
537
|
inject,
|
|
491
|
-
name
|
|
538
|
+
name,
|
|
539
|
+
usage
|
|
492
540
|
});
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
package/res/slk//344/271/235/345/260/276/347/213/220/345/205/245/345/234/272/346/227/240SCP.slk
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|