koishi-plugin-node-async-bot-all 2.6.0 → 2.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/commands.d.ts +1 -0
- package/lib/fun.d.ts +8 -0
- package/lib/index.js +77 -5
- package/package.json +4 -1
package/lib/commands.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare function getRandom(ctx: Context, session: Session, min: number, m
|
|
|
5
5
|
export declare function getInfo(ctx: Context, session: Session): Promise<Object>;
|
|
6
6
|
export declare function getRW(ctx: Context, session: Session): Promise<Object>;
|
|
7
7
|
export declare function getBA(ctx: Context, session: Session): Promise<Number>;
|
|
8
|
+
export declare function serverTest(ctx: Context, session: Session): Promise<Object>;
|
package/lib/fun.d.ts
CHANGED
|
@@ -6,3 +6,11 @@ export declare function fetchWithTimeout(url: string, options: {} | undefined, t
|
|
|
6
6
|
export declare function readInfoFile(ctx: Context): Promise<string>;
|
|
7
7
|
export declare function formatTimestampDiff(start: number, end: number): string;
|
|
8
8
|
export declare function getMsgCount(array: FlatPick<Analytics.Message, "type" | "count">[]): Object;
|
|
9
|
+
export declare function hostPing(host: string): Promise<{
|
|
10
|
+
success: boolean;
|
|
11
|
+
data?: any;
|
|
12
|
+
ip?: string;
|
|
13
|
+
alive?: boolean;
|
|
14
|
+
time?: string;
|
|
15
|
+
packetLoss?: string;
|
|
16
|
+
}>;
|
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
34
34
|
// src/locales/zh-CN.yml
|
|
35
35
|
var require_zh_CN = __commonJS({
|
|
36
36
|
"src/locales/zh-CN.yml"(exports2, module2) {
|
|
37
|
-
module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 协议版本:{protocol}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\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)。" } }, randomba: { description: "随机BA图。", messages: { wait: "{time}\n请等待图片上传(可能较慢)。" } } } };
|
|
37
|
+
module2.exports = { commands: { cx: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 协议版本:{protocol}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 协议版本:{protocol}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", unknown: "未知错误。", host: "没有到主机的路由。" } }, status: { description: "查询机器人状态。", messages: { msg: "{time}\n--- 系统状态 ---\n系统名称:{name}\nCPU使用率:{cpu}\n内存使用率:{memory}\n--- 机器人状态 ---\n昨日收/发消息数量:{msgCount}\n机器人版本:{version}\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)。" } }, randomba: { description: "随机BA图。", messages: { wait: "{time}\n请等待图片上传(可能较慢)。" } }, servertest: { description: "Ping服务器。", messages: { msg: "{time}\n== Ping {host} ==\n状态:{alive}\n丢包率:{packetLoss}\n返回IP:{ip}\n{avg}", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\nPing 失败:{data}" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -56,6 +56,7 @@ var import_koishi = require("koishi");
|
|
|
56
56
|
// src/fun.ts
|
|
57
57
|
var import_os = __toESM(require("os"));
|
|
58
58
|
var import_fs = __toESM(require("fs"));
|
|
59
|
+
var import_ping = __toESM(require("ping"));
|
|
59
60
|
var import_path = __toESM(require("path"));
|
|
60
61
|
function getSystemName() {
|
|
61
62
|
return import_os.default.type() + " " + import_os.default.release();
|
|
@@ -175,6 +176,26 @@ function getMsgCount(array) {
|
|
|
175
176
|
return { "receive": receive, "send": send };
|
|
176
177
|
}
|
|
177
178
|
__name(getMsgCount, "getMsgCount");
|
|
179
|
+
async function hostPing(host) {
|
|
180
|
+
try {
|
|
181
|
+
const tmp = await import_ping.default.promise.probe(host, {
|
|
182
|
+
timeout: 5
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
"success": true,
|
|
186
|
+
"ip": tmp.numeric_host,
|
|
187
|
+
"alive": tmp.alive,
|
|
188
|
+
"time": tmp.avg == "unknown" ? "请求超时。" : `平均延迟:${tmp.avg}ms`,
|
|
189
|
+
"packetLoss": tmp.packetLoss.toString()
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return {
|
|
193
|
+
"success": false,
|
|
194
|
+
"data": error.message
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
__name(hostPing, "hostPing");
|
|
178
199
|
|
|
179
200
|
// src/commands.ts
|
|
180
201
|
async function getServer(ctx, session) {
|
|
@@ -427,9 +448,47 @@ async function getBA(ctx, session) {
|
|
|
427
448
|
return 0;
|
|
428
449
|
}
|
|
429
450
|
__name(getBA, "getBA");
|
|
451
|
+
async function serverTest(ctx, session) {
|
|
452
|
+
const log = ctx.logger("serverTest");
|
|
453
|
+
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
454
|
+
const time = getHongKongTime();
|
|
455
|
+
const host = ctx.config.serverPing[`${session.event.guild?.id}`];
|
|
456
|
+
if (host == void 0) {
|
|
457
|
+
return {
|
|
458
|
+
"success": 1,
|
|
459
|
+
"time": time
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
const tmp = await hostPing(host);
|
|
463
|
+
log.info(tmp);
|
|
464
|
+
if (!tmp.success) {
|
|
465
|
+
return {
|
|
466
|
+
"success": 2,
|
|
467
|
+
"time": time,
|
|
468
|
+
"data": tmp.data
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (tmp.ip == void 0) {
|
|
472
|
+
return {
|
|
473
|
+
"success": 2,
|
|
474
|
+
"time": time,
|
|
475
|
+
"data": "未知的主机 " + host
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
"success": 0,
|
|
480
|
+
"time": time,
|
|
481
|
+
"host": host,
|
|
482
|
+
"ip": tmp.ip,
|
|
483
|
+
"alive": tmp.alive == true ? "正常" : "异常",
|
|
484
|
+
"packetLoss": tmp.packetLoss,
|
|
485
|
+
"avg": tmp.time
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
__name(serverTest, "serverTest");
|
|
430
489
|
|
|
431
490
|
// package.json
|
|
432
|
-
var version = "2.
|
|
491
|
+
var version = "2.7.0";
|
|
433
492
|
|
|
434
493
|
// src/index.ts
|
|
435
494
|
var inject = ["database"];
|
|
@@ -452,7 +511,10 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
452
511
|
}).description("随机文本"),
|
|
453
512
|
import_koishi2.Schema.object({
|
|
454
513
|
baAPI: import_koishi2.Schema.array(String).default(["https://rba.kanostar.top/portrait"]).description("随机BA图 API")
|
|
455
|
-
}).description("随机BA图")
|
|
514
|
+
}).description("随机BA图"),
|
|
515
|
+
import_koishi2.Schema.object({
|
|
516
|
+
serverPing: import_koishi2.Schema.dict(String).role("table").description("键:群号;值:Host")
|
|
517
|
+
}).description("服之测测(Ping)")
|
|
456
518
|
]).description("基础设置");
|
|
457
519
|
function apply(ctx) {
|
|
458
520
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
@@ -486,7 +548,7 @@ function apply(ctx) {
|
|
|
486
548
|
return session?.text(".failed", status);
|
|
487
549
|
}
|
|
488
550
|
});
|
|
489
|
-
ctx.command("random [最小数:number] [最大数:number]").action(async ({ session }, min, max) => {
|
|
551
|
+
ctx.command("random [最小数:number] [最大数:number]").alias("随机数").action(async ({ session }, min, max) => {
|
|
490
552
|
const random = await getRandom(ctx, session, min, max);
|
|
491
553
|
return session?.text(".msg", random);
|
|
492
554
|
});
|
|
@@ -508,9 +570,19 @@ function apply(ctx) {
|
|
|
508
570
|
return session?.text(".failed2", rw);
|
|
509
571
|
}
|
|
510
572
|
});
|
|
511
|
-
ctx.command("randomBA").action(async ({ session }) => {
|
|
573
|
+
ctx.command("randomBA").alias("随机BA图").action(async ({ session }) => {
|
|
512
574
|
await getBA(ctx, session);
|
|
513
575
|
});
|
|
576
|
+
ctx.command("serverTest").alias("服之测测").action(async ({ session }) => {
|
|
577
|
+
const server = await serverTest(ctx, session);
|
|
578
|
+
if (server["success"] == 0) {
|
|
579
|
+
return session?.text(".msg", server);
|
|
580
|
+
} else if (server["success"] == 1) {
|
|
581
|
+
return session?.text(".forbidden", server);
|
|
582
|
+
} else {
|
|
583
|
+
return session?.text(".failed", server);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
514
586
|
}
|
|
515
587
|
__name(apply, "apply");
|
|
516
588
|
// Annotate the CommonJS export names for ESM import in node:
|
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": "2.
|
|
4
|
+
"version": "2.7.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"contributors": [
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"@koishijs/plugin-database-sqlite": "^4.6.0",
|
|
35
35
|
"@koishijs/plugin-help": "^2.4.5",
|
|
36
36
|
"koishi": "^4.18.7"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"ping": "^1.0.0"
|
|
37
40
|
}
|
|
38
41
|
}
|