koishi-plugin-node-async-bot-all 2.20.1 → 2.21.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 +12 -0
- package/lib/index.d.ts +8 -4
- package/lib/index.js +112 -47
- package/package.json +5 -2
package/lib/fun.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { HttpResponse } from "./index";
|
|
2
2
|
import { Context } from "koishi";
|
|
3
3
|
import { APIUserInfo } from "./commands";
|
|
4
|
+
export type serverInfo = {
|
|
5
|
+
players: string;
|
|
6
|
+
protocol: number;
|
|
7
|
+
version: string;
|
|
8
|
+
bots: number;
|
|
9
|
+
port: number;
|
|
10
|
+
success: true;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
error: any;
|
|
14
|
+
};
|
|
4
15
|
export declare function getSystemUsage(): Promise<Object>;
|
|
5
16
|
export declare function getHongKongTime(): string;
|
|
6
17
|
export declare function readInfoFile(ctx: Context): Promise<string>;
|
|
@@ -17,3 +28,4 @@ export declare function random(type: number | undefined, data: any, data2?: any)
|
|
|
17
28
|
export declare function request<T = any>(url: string, options?: RequestInit, timeout?: number, log?: any): Promise<HttpResponse<T>>;
|
|
18
29
|
export declare function readUserCardFile(userInfo: APIUserInfo): Promise<string>;
|
|
19
30
|
export declare function readUserMsgFile(userName: string, userAvatar: string, msg: string): Promise<string>;
|
|
31
|
+
export declare function queryA2S(host: string, log: any): Promise<serverInfo>;
|
package/lib/index.d.ts
CHANGED
|
@@ -20,13 +20,17 @@ interface botDataTables {
|
|
|
20
20
|
}
|
|
21
21
|
export declare const name = "node-async-bot-all";
|
|
22
22
|
export declare const usage = "\u8FD9\u662F\u4E00\u4E2A\u79C1\u6709\u63D2\u4EF6\u3002";
|
|
23
|
-
export interface
|
|
23
|
+
export interface ConfigCxV3 {
|
|
24
24
|
id: string;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
server: Array<ConfigV3Server>;
|
|
26
|
+
}
|
|
27
|
+
export interface ConfigV3Server {
|
|
28
|
+
api: string;
|
|
29
|
+
note: string;
|
|
30
|
+
type: "mc" | "a2s" | null | undefined;
|
|
27
31
|
}
|
|
28
32
|
export interface Config {
|
|
29
|
-
|
|
33
|
+
cxV3: Array<ConfigCxV3>;
|
|
30
34
|
rwAPI: string;
|
|
31
35
|
timeout: number;
|
|
32
36
|
baAPI: string[];
|
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: { cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 备注:{note}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 备注:{note}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣
|
|
37
|
+
module2.exports = { commands: { cxgame: { description: "查询服务器当前人数。", messages: { msg: "{time}{list}\n进服指南请在群公告中查看。", list: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 玩家列表:{list}\n➣ 备注:{note}", listNoPlayer: "【MC 服务器 {count}】\n➣ {version}:{players}\n➣ 备注:{note}", listFailed: "【MC 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。\n➣ 备注:{note}", listA2S: "【A2S 服务器 {count}】\n➣ {version}:{players}\n➣ 机器人:{bots}\n➣ 备注:{note}", listFailedA2S: "【A2S 服务器 {count}】\n➣ 查询失败:{data}\n➣ 请稍后重试。\n➣ 备注:{note}", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。", 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}", error: "执行错误。", failed: "{time}\n获取失败({data})。" } }, randomba: { description: "随机BA图。", messages: { msg: "{quote}{image}", wait: "{quote}{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}" } }, meme: { description: "群友的怪话!", messages: { msg: "{quote}{time}\n{image}\n{title}", failed: "{quote}{time}\n获取失败:{data}", forbidden: "{quote}{time}\n此指令不允许在本群使用。", error: "执行错误。" } }, randomcat: { description: "随机猫猫图。", messages: { msg: "{quote}{image}", wait: "{quote}{time}\n请等待图片上传(可能较慢)。", failed: "{quote}{time}\n获取失败:{data}" } }, getqqinfo: { description: "获取 QQ 号的信息。", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", command: "QQ 号不正确。" } }, msg2img: { description: "引用一个消息并使用此指令,即可将消息转图。", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", null: "未引用任何消息。", matroska: "{quote}禁止套娃!" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -57,6 +57,7 @@ var import_koishi2 = require("koishi");
|
|
|
57
57
|
var import_os = __toESM(require("os"));
|
|
58
58
|
var import_fs = __toESM(require("fs"));
|
|
59
59
|
var import_ping = __toESM(require("ping"));
|
|
60
|
+
var import_steam_server_query = require("steam-server-query");
|
|
60
61
|
var import_path = __toESM(require("path"));
|
|
61
62
|
var import_koishi = require("koishi");
|
|
62
63
|
function getSystemName() {
|
|
@@ -281,6 +282,27 @@ async function readUserMsgFile(userName, userAvatar, msg) {
|
|
|
281
282
|
return html;
|
|
282
283
|
}
|
|
283
284
|
__name(readUserMsgFile, "readUserMsgFile");
|
|
285
|
+
async function queryA2S(host, log) {
|
|
286
|
+
try {
|
|
287
|
+
const playerResponse = await (0, import_steam_server_query.queryGameServerInfo)(host);
|
|
288
|
+
log?.info("Server Info:", playerResponse);
|
|
289
|
+
return {
|
|
290
|
+
players: playerResponse.players + "/" + playerResponse.maxPlayers,
|
|
291
|
+
protocol: playerResponse.protocol,
|
|
292
|
+
version: playerResponse.version,
|
|
293
|
+
bots: playerResponse.bots,
|
|
294
|
+
port: playerResponse.port,
|
|
295
|
+
success: true
|
|
296
|
+
};
|
|
297
|
+
} catch (e) {
|
|
298
|
+
log?.error("A2S Error:", e);
|
|
299
|
+
return {
|
|
300
|
+
error: e,
|
|
301
|
+
success: false
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
__name(queryA2S, "queryA2S");
|
|
284
306
|
|
|
285
307
|
// src/commands.ts
|
|
286
308
|
async function getServer(ctx, session) {
|
|
@@ -288,13 +310,13 @@ async function getServer(ctx, session) {
|
|
|
288
310
|
log.debug(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
289
311
|
let msg;
|
|
290
312
|
const time = getHongKongTime();
|
|
291
|
-
const index = ctx.config.
|
|
313
|
+
const index = ctx.config.cxV3.findIndex((item) => item.id === session.event.guild?.id);
|
|
292
314
|
if (index !== -1) {
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
315
|
+
const server = ctx.config.cxV3[index].server;
|
|
316
|
+
if (server == void 0) {
|
|
295
317
|
msg = {
|
|
296
318
|
"time": time,
|
|
297
|
-
"data": "未指定查询
|
|
319
|
+
"data": "未指定查询 服务器",
|
|
298
320
|
"success": 2
|
|
299
321
|
};
|
|
300
322
|
log.warn("Sent:");
|
|
@@ -303,58 +325,92 @@ async function getServer(ctx, session) {
|
|
|
303
325
|
}
|
|
304
326
|
let count = 0;
|
|
305
327
|
let list = "";
|
|
306
|
-
for (const item of
|
|
307
|
-
const note =
|
|
328
|
+
for (const item of server) {
|
|
329
|
+
const note = item.note;
|
|
330
|
+
const type = item.type;
|
|
331
|
+
const api = item.api;
|
|
308
332
|
count++;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (
|
|
333
|
+
if (type == "a2s") {
|
|
334
|
+
const info = await queryA2S(api, log);
|
|
335
|
+
if (info.success) {
|
|
312
336
|
const temp = {
|
|
313
337
|
"count": count,
|
|
314
|
-
"players":
|
|
315
|
-
"version":
|
|
338
|
+
"players": info.players,
|
|
339
|
+
"version": info.version,
|
|
340
|
+
"bots": info.bots,
|
|
316
341
|
"note": note ?? "无"
|
|
317
342
|
};
|
|
318
343
|
log.info(`Server ${count}:`);
|
|
319
344
|
log.info(temp);
|
|
320
|
-
list = list + "\n" + session.text(".
|
|
345
|
+
list = list + "\n" + session.text(".listA2S", temp);
|
|
321
346
|
} else {
|
|
347
|
+
let err;
|
|
348
|
+
if (info.error.toString().includes("Timeout reached. Possible reasons: You are being rate limited; Timeout too short; Wrong server host configured")) {
|
|
349
|
+
err = "请求超时。";
|
|
350
|
+
} else {
|
|
351
|
+
err = "未知错误。";
|
|
352
|
+
}
|
|
322
353
|
const temp = {
|
|
323
354
|
"count": count,
|
|
324
|
-
"
|
|
325
|
-
"
|
|
326
|
-
"list": response.data.list.join(", "),
|
|
327
|
-
"note": note ?? "无"
|
|
355
|
+
"data": err,
|
|
356
|
+
"note": note
|
|
328
357
|
};
|
|
329
|
-
log.
|
|
330
|
-
log.
|
|
331
|
-
list = list + "\n" + session.text(".
|
|
358
|
+
log.error(`Server ${count}:`);
|
|
359
|
+
log.error(temp);
|
|
360
|
+
list = list + "\n" + session.text(".listFailedA2S", temp);
|
|
332
361
|
}
|
|
333
362
|
} else {
|
|
334
|
-
|
|
335
|
-
if (response.
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
363
|
+
const response = await request(api, {}, ctx.config.timeout, log);
|
|
364
|
+
if (response.success) {
|
|
365
|
+
if (response.data.list == null) {
|
|
366
|
+
const temp = {
|
|
367
|
+
"count": count,
|
|
368
|
+
"players": response.data.players,
|
|
369
|
+
"version": response.data.version,
|
|
370
|
+
"note": note ?? "无"
|
|
371
|
+
};
|
|
372
|
+
log.info(`Server ${count}:`);
|
|
373
|
+
log.info(temp);
|
|
374
|
+
list = list + "\n" + session.text(".listNoPlayer", temp);
|
|
375
|
+
} else {
|
|
376
|
+
const temp = {
|
|
377
|
+
"count": count,
|
|
378
|
+
"players": response.data.players,
|
|
379
|
+
"version": response.data.version,
|
|
380
|
+
"list": response.data.list.join(", "),
|
|
381
|
+
"note": note ?? "无"
|
|
382
|
+
};
|
|
383
|
+
log.info(`Server ${count}:`);
|
|
384
|
+
log.info(temp);
|
|
385
|
+
list = list + "\n" + session.text(".list", temp);
|
|
347
386
|
}
|
|
348
387
|
} else {
|
|
349
|
-
err
|
|
388
|
+
let err;
|
|
389
|
+
if (response.code) {
|
|
390
|
+
err = response.isJson ? response.error["data"] : response.error;
|
|
391
|
+
if (err.includes("Connection refused")) {
|
|
392
|
+
err = session.text(".close");
|
|
393
|
+
} else if (err.includes("No route to host")) {
|
|
394
|
+
err = session.text(".host");
|
|
395
|
+
} else if (err.includes("Connection timed out")) {
|
|
396
|
+
err = session.text(".timeout");
|
|
397
|
+
} else if (err.includes("Server returned too few data")) {
|
|
398
|
+
err = session.text(".fewData");
|
|
399
|
+
} else if (err.includes("Server read timed out")) {
|
|
400
|
+
err = session.text(".timeout2");
|
|
401
|
+
}
|
|
402
|
+
} else {
|
|
403
|
+
err = response.error.message;
|
|
404
|
+
}
|
|
405
|
+
const temp = {
|
|
406
|
+
"count": count,
|
|
407
|
+
"data": err,
|
|
408
|
+
"note": note
|
|
409
|
+
};
|
|
410
|
+
log.error(`Server ${count}:`);
|
|
411
|
+
log.error(temp);
|
|
412
|
+
list = list + "\n" + session.text(".listFailed", temp);
|
|
350
413
|
}
|
|
351
|
-
const temp = {
|
|
352
|
-
"count": count,
|
|
353
|
-
"data": err
|
|
354
|
-
};
|
|
355
|
-
log.error(`Server ${count}:`);
|
|
356
|
-
log.error(temp);
|
|
357
|
-
list = list + "\n" + session.text(".listFailed", temp);
|
|
358
414
|
}
|
|
359
415
|
}
|
|
360
416
|
msg = {
|
|
@@ -691,6 +747,10 @@ async function getMsg(ctx, session) {
|
|
|
691
747
|
log.warn("未引用任何信息");
|
|
692
748
|
return 1;
|
|
693
749
|
}
|
|
750
|
+
if (session.quote.user.id == session.event.selfId) {
|
|
751
|
+
await session.send(session.text(".matroska", { "quote": import_koishi2.h.quote(session.messageId) }));
|
|
752
|
+
return 1;
|
|
753
|
+
}
|
|
694
754
|
const user = await session.bot.getUser(session.quote.user.id, session.channelId);
|
|
695
755
|
const msg = session.quote.content;
|
|
696
756
|
if (!user.name || !user.avatar) {
|
|
@@ -738,7 +798,7 @@ async function getMsg(ctx, session) {
|
|
|
738
798
|
__name(getMsg, "getMsg");
|
|
739
799
|
|
|
740
800
|
// package.json
|
|
741
|
-
var version = "2.
|
|
801
|
+
var version = "2.21.0";
|
|
742
802
|
|
|
743
803
|
// src/index.ts
|
|
744
804
|
var inject = ["database", "installer", "puppeteer"];
|
|
@@ -749,13 +809,18 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
749
809
|
timeout: import_koishi3.Schema.number().default(8e3).description("超时时间(毫秒)")
|
|
750
810
|
}).description("基础"),
|
|
751
811
|
import_koishi3.Schema.object({
|
|
752
|
-
|
|
812
|
+
cxV3: import_koishi3.Schema.array(
|
|
753
813
|
import_koishi3.Schema.object({
|
|
754
|
-
id: import_koishi3.Schema.string().
|
|
755
|
-
|
|
756
|
-
|
|
814
|
+
id: import_koishi3.Schema.string().description("查询 群"),
|
|
815
|
+
server: import_koishi3.Schema.array(
|
|
816
|
+
import_koishi3.Schema.object({
|
|
817
|
+
api: import_koishi3.Schema.string().description("查询 API | HOST"),
|
|
818
|
+
note: import_koishi3.Schema.string().description("查询 备注"),
|
|
819
|
+
type: import_koishi3.Schema.union(["mc", "a2s"]).description("查询 类型")
|
|
820
|
+
})
|
|
821
|
+
).description("查询 服务器")
|
|
757
822
|
})
|
|
758
|
-
).default([]).description("
|
|
823
|
+
).default([]).description("查询的群")
|
|
759
824
|
}).description("查询"),
|
|
760
825
|
import_koishi3.Schema.object({
|
|
761
826
|
rwAPI: import_koishi3.Schema.string().default("https://api.tasaed.top/rw/").description("随机文本 API")
|
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.21.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"contributors": [
|
|
@@ -33,9 +33,12 @@
|
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@koishijs/plugin-database-sqlite": "^4.6.0",
|
|
35
35
|
"@koishijs/plugin-help": "^2.4.5",
|
|
36
|
+
"koishi-plugin-puppeteer": "^3.9.0",
|
|
37
|
+
"@koishijs/plugin-market": "^2.11.8",
|
|
36
38
|
"koishi": "^4.18.7"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"ping": "^1.0.0"
|
|
41
|
+
"ping": "^1.0.0",
|
|
42
|
+
"steam-server-query": "^1.1.3"
|
|
40
43
|
}
|
|
41
44
|
}
|