koishi-plugin-node-async-bot-all 1.11.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 +60 -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: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", 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.11.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);
|
|
@@ -268,11 +274,16 @@ async function getStatus(ctx, session) {
|
|
|
268
274
|
"success": 1
|
|
269
275
|
};
|
|
270
276
|
} else {
|
|
277
|
+
log.info((await ctx.database.get("botData", "uptime"))[0].data);
|
|
271
278
|
msg = {
|
|
272
279
|
"time": time,
|
|
273
280
|
"name": vMsg["name"],
|
|
274
281
|
"cpu": vMsg["cpu"],
|
|
275
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
|
+
),
|
|
276
287
|
"success": 0
|
|
277
288
|
};
|
|
278
289
|
}
|
|
@@ -309,7 +320,7 @@ async function getInfo(ctx, session) {
|
|
|
309
320
|
log.info(`Got: {"form":"${session.event.guild.id}","user":"${session.event.user.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message.id}"}`);
|
|
310
321
|
const time = getHongKongTime();
|
|
311
322
|
let msg;
|
|
312
|
-
let data = await readInfoFile();
|
|
323
|
+
let data = await readInfoFile(ctx);
|
|
313
324
|
if (!data.includes("&time;")) {
|
|
314
325
|
log.error("Error: " + data);
|
|
315
326
|
msg = {
|
|
@@ -337,7 +348,7 @@ async function getRW(ctx, session) {
|
|
|
337
348
|
let data;
|
|
338
349
|
const time = getHongKongTime();
|
|
339
350
|
try {
|
|
340
|
-
const response = await fetchWithTimeout(
|
|
351
|
+
const response = await fetchWithTimeout(ctx.config.rwAPI, {}, ctx.config.timeout, log);
|
|
341
352
|
if (response.ok) {
|
|
342
353
|
data = await response.text();
|
|
343
354
|
log.info("Server data: " + data);
|
|
@@ -430,8 +441,39 @@ async function getCASSIE(ctx, session, name2) {
|
|
|
430
441
|
}
|
|
431
442
|
}
|
|
432
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("基础设置");
|
|
433
463
|
function apply(ctx) {
|
|
434
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
|
+
});
|
|
435
477
|
ctx.command("cx").action(async ({ session }) => {
|
|
436
478
|
const cx = await getServer(ctx, session);
|
|
437
479
|
if (cx["success"] == 0) {
|
|
@@ -490,7 +532,9 @@ function apply(ctx) {
|
|
|
490
532
|
__name(apply, "apply");
|
|
491
533
|
// Annotate the CommonJS export names for ESM import in node:
|
|
492
534
|
0 && (module.exports = {
|
|
535
|
+
Config,
|
|
493
536
|
apply,
|
|
494
537
|
inject,
|
|
495
|
-
name
|
|
538
|
+
name,
|
|
539
|
+
usage
|
|
496
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
|