koishi-plugin-node-async-bot-all 2.6.0 → 2.8.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 +7 -0
- package/lib/index.js +75 -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,10 @@ 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
|
+
packetLoss?: string;
|
|
15
|
+
}>;
|
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}", 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,25 @@ 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
|
+
"packetLoss": tmp.packetLoss.toString()
|
|
189
|
+
};
|
|
190
|
+
} catch (error) {
|
|
191
|
+
return {
|
|
192
|
+
"success": false,
|
|
193
|
+
"data": error.message
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
__name(hostPing, "hostPing");
|
|
178
198
|
|
|
179
199
|
// src/commands.ts
|
|
180
200
|
async function getServer(ctx, session) {
|
|
@@ -427,9 +447,46 @@ async function getBA(ctx, session) {
|
|
|
427
447
|
return 0;
|
|
428
448
|
}
|
|
429
449
|
__name(getBA, "getBA");
|
|
450
|
+
async function serverTest(ctx, session) {
|
|
451
|
+
const log = ctx.logger("serverTest");
|
|
452
|
+
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
453
|
+
const time = getHongKongTime();
|
|
454
|
+
const host = ctx.config.serverPing[`${session.event.guild?.id}`];
|
|
455
|
+
if (host == void 0) {
|
|
456
|
+
return {
|
|
457
|
+
"success": 1,
|
|
458
|
+
"time": time
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const tmp = await hostPing(host);
|
|
462
|
+
log.info(tmp);
|
|
463
|
+
if (!tmp.success) {
|
|
464
|
+
return {
|
|
465
|
+
"success": 2,
|
|
466
|
+
"time": time,
|
|
467
|
+
"data": tmp.data
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (tmp.ip == void 0) {
|
|
471
|
+
return {
|
|
472
|
+
"success": 2,
|
|
473
|
+
"time": time,
|
|
474
|
+
"data": "未知的主机 " + host
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
"success": 0,
|
|
479
|
+
"time": time,
|
|
480
|
+
"host": host,
|
|
481
|
+
"ip": tmp.ip,
|
|
482
|
+
"alive": tmp.alive == true ? "正常" : "异常",
|
|
483
|
+
"packetLoss": tmp.packetLoss
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
__name(serverTest, "serverTest");
|
|
430
487
|
|
|
431
488
|
// package.json
|
|
432
|
-
var version = "2.
|
|
489
|
+
var version = "2.8.0";
|
|
433
490
|
|
|
434
491
|
// src/index.ts
|
|
435
492
|
var inject = ["database"];
|
|
@@ -452,7 +509,10 @@ var Config = import_koishi2.Schema.intersect([
|
|
|
452
509
|
}).description("随机文本"),
|
|
453
510
|
import_koishi2.Schema.object({
|
|
454
511
|
baAPI: import_koishi2.Schema.array(String).default(["https://rba.kanostar.top/portrait"]).description("随机BA图 API")
|
|
455
|
-
}).description("随机BA图")
|
|
512
|
+
}).description("随机BA图"),
|
|
513
|
+
import_koishi2.Schema.object({
|
|
514
|
+
serverPing: import_koishi2.Schema.dict(String).role("table").description("键:群号;值:Host")
|
|
515
|
+
}).description("服之测测(Ping)")
|
|
456
516
|
]).description("基础设置");
|
|
457
517
|
function apply(ctx) {
|
|
458
518
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
@@ -486,7 +546,7 @@ function apply(ctx) {
|
|
|
486
546
|
return session?.text(".failed", status);
|
|
487
547
|
}
|
|
488
548
|
});
|
|
489
|
-
ctx.command("random [最小数:number] [最大数:number]").action(async ({ session }, min, max) => {
|
|
549
|
+
ctx.command("random [最小数:number] [最大数:number]").alias("随机数").action(async ({ session }, min, max) => {
|
|
490
550
|
const random = await getRandom(ctx, session, min, max);
|
|
491
551
|
return session?.text(".msg", random);
|
|
492
552
|
});
|
|
@@ -508,9 +568,19 @@ function apply(ctx) {
|
|
|
508
568
|
return session?.text(".failed2", rw);
|
|
509
569
|
}
|
|
510
570
|
});
|
|
511
|
-
ctx.command("randomBA").action(async ({ session }) => {
|
|
571
|
+
ctx.command("randomBA").alias("随机BA图").action(async ({ session }) => {
|
|
512
572
|
await getBA(ctx, session);
|
|
513
573
|
});
|
|
574
|
+
ctx.command("serverTest").alias("服之测测").action(async ({ session }) => {
|
|
575
|
+
const server = await serverTest(ctx, session);
|
|
576
|
+
if (server["success"] == 0) {
|
|
577
|
+
return session?.text(".msg", server);
|
|
578
|
+
} else if (server["success"] == 1) {
|
|
579
|
+
return session?.text(".forbidden", server);
|
|
580
|
+
} else {
|
|
581
|
+
return session?.text(".failed", server);
|
|
582
|
+
}
|
|
583
|
+
});
|
|
514
584
|
}
|
|
515
585
|
__name(apply, "apply");
|
|
516
586
|
// 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.8.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
|
}
|