koishi-plugin-node-async-bot-all 2.22.2 → 2.24.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 +20 -1
- package/lib/fun.d.ts +29 -11
- package/lib/index.d.ts +6 -11
- package/lib/index.js +156 -116
- package/package.json +5 -3
package/lib/commands.d.ts
CHANGED
|
@@ -44,13 +44,32 @@ interface NewsItem {
|
|
|
44
44
|
feed_type: number;
|
|
45
45
|
appid: number;
|
|
46
46
|
}
|
|
47
|
+
interface Heartbeat {
|
|
48
|
+
status: 0 | 1;
|
|
49
|
+
time: string;
|
|
50
|
+
msg: string;
|
|
51
|
+
ping: number | null;
|
|
52
|
+
}
|
|
53
|
+
interface HeartbeatList {
|
|
54
|
+
[monitorId: string]: Heartbeat[];
|
|
55
|
+
}
|
|
56
|
+
interface UptimeList {
|
|
57
|
+
[periodKey: string]: number;
|
|
58
|
+
}
|
|
59
|
+
export interface MonitorStatusResponse {
|
|
60
|
+
heartbeatList: HeartbeatList;
|
|
61
|
+
uptimeList: UptimeList;
|
|
62
|
+
}
|
|
47
63
|
export declare function getServer(ctx: Context, session: Session): Promise<Object>;
|
|
48
64
|
export declare function getStatus(ctx: Context, session: Session): Promise<Object>;
|
|
49
65
|
export declare function getRandom(ctx: Context, session: Session, min: number, max: number): Promise<Object>;
|
|
50
66
|
export declare function getInfo(ctx: Context, session: Session): Promise<Object>;
|
|
51
67
|
export declare function getRandomWord(ctx: Context, session: Session): Promise<Object>;
|
|
52
68
|
export declare function getBlueArchive(ctx: Context, session: Session): Promise<Number>;
|
|
53
|
-
export declare function
|
|
69
|
+
export declare function centerServerTest(ctx: Context, session: Session): Promise<{
|
|
70
|
+
success: string;
|
|
71
|
+
data: object;
|
|
72
|
+
}>;
|
|
54
73
|
export declare function getMeme(ctx: Context, session: Session, count: number): Promise<Number>;
|
|
55
74
|
export declare function getCat(ctx: Context, session: Session): Promise<Number>;
|
|
56
75
|
export declare function getQQInfo(ctx: Context, session: Session, qq: string): Promise<number>;
|
package/lib/fun.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { HttpResponse } from "./index";
|
|
2
1
|
import { Context } from "koishi";
|
|
3
|
-
import { APINews, APIUserInfo } from "./commands";
|
|
2
|
+
import { APINews, APIUserInfo } from "./commands.ts";
|
|
3
|
+
import { JavaStatusResponse } from 'minecraft-server-util';
|
|
4
|
+
export type HttpResponse<T> = {
|
|
5
|
+
success: true;
|
|
6
|
+
data: T;
|
|
7
|
+
} | {
|
|
8
|
+
success: false;
|
|
9
|
+
error: any;
|
|
10
|
+
code?: number;
|
|
11
|
+
isJson: boolean;
|
|
12
|
+
};
|
|
4
13
|
export type serverInfo = {
|
|
5
14
|
players: string;
|
|
6
15
|
protocol: number;
|
|
@@ -12,21 +21,30 @@ export type serverInfo = {
|
|
|
12
21
|
success: false;
|
|
13
22
|
error: any;
|
|
14
23
|
};
|
|
15
|
-
export declare function getSystemUsage(): Promise<
|
|
24
|
+
export declare function getSystemUsage(): Promise<{
|
|
25
|
+
name: string;
|
|
26
|
+
cpu: string;
|
|
27
|
+
memory: string;
|
|
28
|
+
success: 0;
|
|
29
|
+
} | {
|
|
30
|
+
data: string;
|
|
31
|
+
success: 1;
|
|
32
|
+
}>;
|
|
16
33
|
export declare function getHongKongTime(): string;
|
|
17
34
|
export declare function readInfoFile(ctx: Context): Promise<string>;
|
|
18
35
|
export declare function formatTimestampDiff(start: number, end: number): string;
|
|
19
36
|
export declare function getMsgCount(ctx: Context): Promise<Object>;
|
|
20
|
-
export declare function hostPing(host: string): Promise<{
|
|
21
|
-
success: boolean;
|
|
22
|
-
data?: any;
|
|
23
|
-
ip?: string;
|
|
24
|
-
alive?: boolean;
|
|
25
|
-
packetLoss?: string;
|
|
26
|
-
}>;
|
|
27
37
|
export declare function random(type: number | undefined, data: any, data2?: any): number;
|
|
28
38
|
export declare function request<T = any>(url: string, options?: RequestInit, timeout?: number, log?: any): Promise<HttpResponse<T>>;
|
|
29
39
|
export declare function readUserCardFile(userInfo: APIUserInfo): Promise<string>;
|
|
30
40
|
export declare function readUserMsgFile(userName: string, userAvatar: string, msg: string): Promise<string>;
|
|
31
41
|
export declare function queryA2S(host: string, log: any): Promise<serverInfo>;
|
|
32
|
-
export declare function readNewsFile(info: APINews): Promise<string>;
|
|
42
|
+
export declare function readNewsFile(info: APINews, log: any): Promise<string[]>;
|
|
43
|
+
export declare function translateAPI(log: any, text: string): Promise<string>;
|
|
44
|
+
export declare function slpInfo(log: any, host: string, port: number, timeout?: number): Promise<{
|
|
45
|
+
success: true;
|
|
46
|
+
data: JavaStatusResponse;
|
|
47
|
+
} | {
|
|
48
|
+
success: false;
|
|
49
|
+
data: string;
|
|
50
|
+
}>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { Context, Dict, Schema } from 'koishi';
|
|
2
2
|
export declare const inject: string[];
|
|
3
|
-
export type HttpResponse<T> = {
|
|
4
|
-
success: true;
|
|
5
|
-
data: T;
|
|
6
|
-
} | {
|
|
7
|
-
success: false;
|
|
8
|
-
error: any;
|
|
9
|
-
code?: number;
|
|
10
|
-
isJson: boolean;
|
|
11
|
-
};
|
|
12
3
|
declare module 'koishi' {
|
|
13
4
|
interface Tables {
|
|
14
5
|
botData: botDataTables;
|
|
@@ -27,17 +18,21 @@ export interface ConfigCxV3 {
|
|
|
27
18
|
id: string;
|
|
28
19
|
server: Array<ConfigV3Server>;
|
|
29
20
|
}
|
|
30
|
-
|
|
21
|
+
interface ConfigV3Server {
|
|
31
22
|
api: string;
|
|
32
23
|
note: string;
|
|
33
24
|
type: "mc" | "a2s" | null | undefined;
|
|
34
25
|
}
|
|
26
|
+
interface CenterServerConfig {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
35
30
|
export interface Config {
|
|
36
31
|
cxV3: Array<ConfigCxV3>;
|
|
37
32
|
rwAPI: string;
|
|
38
33
|
timeout: number;
|
|
39
34
|
baAPI: string[];
|
|
40
|
-
|
|
35
|
+
slTest: CenterServerConfig[];
|
|
41
36
|
steamAPI: string;
|
|
42
37
|
memesAPI: Dict<string>;
|
|
43
38
|
catAPI: 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➣ 请稍后重试。\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: "请求超时。",
|
|
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: "请求超时。", 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请等待图片上传(可能较慢)。" } }, centerservertest: { description: "查看中心服务器状态。", messages: { msg: "{time}{list}", list: "== {name} ==\n状态:{status}\n存活率:{uptime}\n检测时间:{time}", listFailed: "== {name} ==\n查看失败:{data}", failed: "{time}\n查看失败:{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}禁止套娃!" } }, slnews: { description: "抓取 NorthWood 的 Steam 最新新闻。" } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -56,12 +56,13 @@ var import_koishi2 = 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"));
|
|
60
|
-
var import_steam_server_query = require("steam-server-query");
|
|
61
59
|
var import_path = __toESM(require("path"));
|
|
62
60
|
var import_koishi = require("koishi");
|
|
61
|
+
var import_steam_server_query = require("steam-server-query");
|
|
63
62
|
var import_html = __toESM(require("@bbob/html"));
|
|
64
63
|
var import_preset_html5 = __toESM(require("@bbob/preset-html5"));
|
|
64
|
+
var import_bing_translate_api = require("bing-translate-api");
|
|
65
|
+
var import_minecraft_server_util = require("minecraft-server-util");
|
|
65
66
|
function getSystemName() {
|
|
66
67
|
return import_os.default.type() + " " + import_os.default.release();
|
|
67
68
|
}
|
|
@@ -96,21 +97,19 @@ async function getCpuUsage() {
|
|
|
96
97
|
}
|
|
97
98
|
__name(getCpuUsage, "getCpuUsage");
|
|
98
99
|
async function getSystemUsage() {
|
|
99
|
-
let info;
|
|
100
100
|
try {
|
|
101
|
-
|
|
101
|
+
return {
|
|
102
102
|
"name": getSystemName(),
|
|
103
103
|
"cpu": await getCpuUsage() + "%",
|
|
104
104
|
"memory": getMemoryUsage() + "%",
|
|
105
105
|
"success": 0
|
|
106
106
|
};
|
|
107
107
|
} catch (error) {
|
|
108
|
-
|
|
108
|
+
return {
|
|
109
109
|
"data": error.message,
|
|
110
110
|
"success": 1
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
return info;
|
|
114
113
|
}
|
|
115
114
|
__name(getSystemUsage, "getSystemUsage");
|
|
116
115
|
function getHongKongTime() {
|
|
@@ -161,7 +160,6 @@ function formatTimestampDiff(start, end) {
|
|
|
161
160
|
__name(formatTimestampDiff, "formatTimestampDiff");
|
|
162
161
|
async function getMsgCount(ctx) {
|
|
163
162
|
const array = await ctx.database.get("analytics.message", { date: import_koishi.Time.getDateNumber() - 1 }, ["type", "count"]);
|
|
164
|
-
ctx.logger.info(import_koishi.Time.getDateNumber() - 1);
|
|
165
163
|
let receive = 0;
|
|
166
164
|
let send = 0;
|
|
167
165
|
array.forEach((item) => {
|
|
@@ -174,25 +172,6 @@ async function getMsgCount(ctx) {
|
|
|
174
172
|
return { "receive": receive, "send": send };
|
|
175
173
|
}
|
|
176
174
|
__name(getMsgCount, "getMsgCount");
|
|
177
|
-
async function hostPing(host) {
|
|
178
|
-
try {
|
|
179
|
-
const tmp = await import_ping.default.promise.probe(host, {
|
|
180
|
-
timeout: 5
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
"success": true,
|
|
184
|
-
"ip": tmp.numeric_host,
|
|
185
|
-
"alive": tmp.alive,
|
|
186
|
-
"packetLoss": tmp.packetLoss.toString()
|
|
187
|
-
};
|
|
188
|
-
} catch (error) {
|
|
189
|
-
return {
|
|
190
|
-
"success": false,
|
|
191
|
-
"data": error.message
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
__name(hostPing, "hostPing");
|
|
196
175
|
function random(type = 0, data, data2) {
|
|
197
176
|
const random2 = new import_koishi.Random(() => Math.random());
|
|
198
177
|
switch (type) {
|
|
@@ -305,20 +284,62 @@ async function queryA2S(host, log) {
|
|
|
305
284
|
}
|
|
306
285
|
}
|
|
307
286
|
__name(queryA2S, "queryA2S");
|
|
308
|
-
async function readNewsFile(info) {
|
|
287
|
+
async function readNewsFile(info, log) {
|
|
309
288
|
let html;
|
|
310
289
|
try {
|
|
311
290
|
const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "slNews.html";
|
|
312
291
|
html = await import_fs.default.promises.readFile(aPath, "utf8");
|
|
313
|
-
const content =
|
|
292
|
+
const content = info.appnews.newsitems[0].contents.replace("[spoiler]", "").replace("[/spoiler]", "").replace(/\r\n/g, "\n").replace(/\n{3,}/g, "\n\n").split("\n\n").map((p) => p.trim()).filter(Boolean);
|
|
293
|
+
const bilingualParagraphs = [];
|
|
294
|
+
for (const paragraph of content) {
|
|
295
|
+
const zh = await translateAPI(log, paragraph);
|
|
296
|
+
bilingualParagraphs.push(
|
|
297
|
+
paragraph,
|
|
298
|
+
zh,
|
|
299
|
+
""
|
|
300
|
+
// 空行用于分隔段落
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const finalText = bilingualParagraphs.join("<br />").replace(/<br \/>{2,}/g, "<br />");
|
|
304
|
+
const contentHtml = (0, import_html.default)(finalText, (0, import_preset_html5.default)());
|
|
314
305
|
const date = Number(info.appnews.newsitems[0].date + "000");
|
|
315
|
-
html = html.toString().replace("{date}", new Date(date).toLocaleString()).replace("{title}", info.appnews.newsitems[0].title).replace("{content}",
|
|
306
|
+
html = html.toString().replace("{date}", new Date(date).toLocaleString()).replace("{title}", info.appnews.newsitems[0].title).replace("{content}", contentHtml);
|
|
316
307
|
} catch (error) {
|
|
317
|
-
|
|
308
|
+
log.error(error);
|
|
309
|
+
log.error(error.message);
|
|
310
|
+
return [error, error.message];
|
|
318
311
|
}
|
|
319
|
-
return html;
|
|
312
|
+
return [html];
|
|
320
313
|
}
|
|
321
314
|
__name(readNewsFile, "readNewsFile");
|
|
315
|
+
async function translateAPI(log, text) {
|
|
316
|
+
const ms = random(0, 0, 250);
|
|
317
|
+
await (0, import_koishi.sleep)(ms);
|
|
318
|
+
await (0, import_bing_translate_api.translate)(text, "en", "zh-Hans").then((result) => {
|
|
319
|
+
text = result?.translation;
|
|
320
|
+
}).catch((err) => {
|
|
321
|
+
log.error(err);
|
|
322
|
+
});
|
|
323
|
+
return text;
|
|
324
|
+
}
|
|
325
|
+
__name(translateAPI, "translateAPI");
|
|
326
|
+
async function slpInfo(log, host, port, timeout) {
|
|
327
|
+
try {
|
|
328
|
+
const info = await (0, import_minecraft_server_util.status)(host, port, { timeout });
|
|
329
|
+
log.info(info);
|
|
330
|
+
return {
|
|
331
|
+
"success": true,
|
|
332
|
+
"data": info
|
|
333
|
+
};
|
|
334
|
+
} catch (error) {
|
|
335
|
+
log.error(error);
|
|
336
|
+
return {
|
|
337
|
+
"success": false,
|
|
338
|
+
"data": error.message
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
__name(slpInfo, "slpInfo");
|
|
322
343
|
|
|
323
344
|
// src/commands.ts
|
|
324
345
|
async function getServer(ctx, session) {
|
|
@@ -376,13 +397,14 @@ async function getServer(ctx, session) {
|
|
|
376
397
|
list = list + "\n" + session.text(".listFailedA2S", temp);
|
|
377
398
|
}
|
|
378
399
|
} else {
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
400
|
+
const host = api.split(":");
|
|
401
|
+
const serverInfo = await slpInfo(log, host[0], Number(host[1]), ctx.config.timeout);
|
|
402
|
+
if (serverInfo.success) {
|
|
403
|
+
if (serverInfo.data.players.sample == null) {
|
|
382
404
|
const temp = {
|
|
383
405
|
"count": count,
|
|
384
|
-
"players":
|
|
385
|
-
"version":
|
|
406
|
+
"players": serverInfo.data.players.online + "/" + serverInfo.data.players.max,
|
|
407
|
+
"version": serverInfo.data.version.name,
|
|
386
408
|
"note": note ?? "无"
|
|
387
409
|
};
|
|
388
410
|
log.info(`Server ${count}:`);
|
|
@@ -391,9 +413,9 @@ async function getServer(ctx, session) {
|
|
|
391
413
|
} else {
|
|
392
414
|
const temp = {
|
|
393
415
|
"count": count,
|
|
394
|
-
"players":
|
|
395
|
-
"version":
|
|
396
|
-
"list":
|
|
416
|
+
"players": serverInfo.data.players.online + "/" + serverInfo.data.players.max,
|
|
417
|
+
"version": serverInfo.data.version.name,
|
|
418
|
+
"list": serverInfo.data.players.sample.map((item2) => item2.name).join(", "),
|
|
397
419
|
"note": note ?? "无"
|
|
398
420
|
};
|
|
399
421
|
log.info(`Server ${count}:`);
|
|
@@ -401,22 +423,17 @@ async function getServer(ctx, session) {
|
|
|
401
423
|
list = list + "\n" + session.text(".list", temp);
|
|
402
424
|
}
|
|
403
425
|
} else {
|
|
404
|
-
let err;
|
|
405
|
-
if (
|
|
406
|
-
err =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
} else if (err.includes("Server read timed out")) {
|
|
416
|
-
err = session.text(".timeout2");
|
|
417
|
-
}
|
|
418
|
-
} else {
|
|
419
|
-
err = response.error.message;
|
|
426
|
+
let err = serverInfo.data;
|
|
427
|
+
if (err.includes("connect ECONNREFUSED") || err.includes("Server is offline or unreachable")) {
|
|
428
|
+
err = session.text(".close");
|
|
429
|
+
} else if (err.includes("connect EHOSTUNREACH")) {
|
|
430
|
+
err = session.text(".host");
|
|
431
|
+
} else if (err.includes("connect ETIMEDOUT")) {
|
|
432
|
+
err = session.text(".timeout");
|
|
433
|
+
} else if (err.includes("Ping payload did not match received payload")) {
|
|
434
|
+
err = session.text(".fewData");
|
|
435
|
+
} else if (err.includes("Expected server to send packet type")) {
|
|
436
|
+
err = session.text(".fewData");
|
|
420
437
|
}
|
|
421
438
|
const temp = {
|
|
422
439
|
"count": count,
|
|
@@ -583,49 +600,72 @@ async function getBlueArchive(ctx, session) {
|
|
|
583
600
|
const link = random(2, ctx.config.baAPI) + `?cacheBuster=${random(1, 1, 2147483647)}`;
|
|
584
601
|
log.info(`Link: ${link}`);
|
|
585
602
|
await (0, import_koishi2.sleep)(ms);
|
|
586
|
-
const
|
|
587
|
-
if (!
|
|
603
|
+
const status2 = await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(link) }));
|
|
604
|
+
if (!status2) await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(link) }));
|
|
588
605
|
await session.bot.deleteMessage(session.event.guild?.id, vid[0]);
|
|
589
606
|
return 0;
|
|
590
607
|
}
|
|
591
608
|
__name(getBlueArchive, "getBlueArchive");
|
|
592
|
-
async function
|
|
593
|
-
const log = ctx.logger("
|
|
609
|
+
async function centerServerTest(ctx, session) {
|
|
610
|
+
const log = ctx.logger("centerServerTest");
|
|
594
611
|
log.debug(`Got: {"form":"${session.platform}:${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
595
612
|
const time = getHongKongTime();
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
613
|
+
let msg;
|
|
614
|
+
let list = "";
|
|
615
|
+
const timeFormatter = new Intl.DateTimeFormat("zh-CN", {
|
|
616
|
+
timeZone: "Asia/Shanghai",
|
|
617
|
+
year: "numeric",
|
|
618
|
+
month: "2-digit",
|
|
619
|
+
day: "2-digit",
|
|
620
|
+
hour: "2-digit",
|
|
621
|
+
minute: "2-digit",
|
|
622
|
+
second: "2-digit",
|
|
623
|
+
hour12: false
|
|
624
|
+
});
|
|
625
|
+
const response = await request("https://status.scpslgame.com/api/status-page/heartbeat/nw", {}, ctx.config.timeout, log);
|
|
626
|
+
if (response.success) {
|
|
627
|
+
for (const server of ctx.config.slTest) {
|
|
628
|
+
const lastTime = response.data.heartbeatList[server.id].at(-1);
|
|
629
|
+
if (lastTime) {
|
|
630
|
+
const uptime24 = (response.data.uptimeList[server.id + "_24"] * 100).toFixed(2) + "%";
|
|
631
|
+
const status2 = lastTime?.status == 1 ? "正常" : "故障";
|
|
632
|
+
const testTime = timeFormatter.format(/* @__PURE__ */ new Date(lastTime?.time.replace(" ", "T") + "Z"));
|
|
633
|
+
list = list + "\n" + session.text(".list", {
|
|
634
|
+
"name": server.name,
|
|
635
|
+
"status": status2,
|
|
636
|
+
"uptime": uptime24,
|
|
637
|
+
"time": testTime
|
|
638
|
+
});
|
|
639
|
+
} else {
|
|
640
|
+
list = list + "\n" + session.text(".listFailed", {
|
|
641
|
+
"name": server.name,
|
|
642
|
+
"data": "未能获取到此服务器的状态信息。"
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
msg = {
|
|
647
|
+
"data": { "list": list, "time": time },
|
|
648
|
+
"success": ".msg"
|
|
610
649
|
};
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
"data":
|
|
650
|
+
log.debug("Sent:");
|
|
651
|
+
log.debug(msg);
|
|
652
|
+
} else {
|
|
653
|
+
let err;
|
|
654
|
+
if (response.code) {
|
|
655
|
+
err = response.isJson ? response.error["data"] : response.error;
|
|
656
|
+
} else {
|
|
657
|
+
err = response.error.message;
|
|
658
|
+
}
|
|
659
|
+
msg = {
|
|
660
|
+
"data": { "data": err, "time": time },
|
|
661
|
+
"success": ".failed"
|
|
617
662
|
};
|
|
663
|
+
log.warn("Sent:");
|
|
664
|
+
log.warn(msg);
|
|
618
665
|
}
|
|
619
|
-
return
|
|
620
|
-
"success": 0,
|
|
621
|
-
"time": time,
|
|
622
|
-
"host": host,
|
|
623
|
-
"ip": tmp.ip,
|
|
624
|
-
"alive": tmp.alive == true ? "正常" : "异常",
|
|
625
|
-
"packetLoss": tmp.packetLoss
|
|
626
|
-
};
|
|
666
|
+
return msg;
|
|
627
667
|
}
|
|
628
|
-
__name(
|
|
668
|
+
__name(centerServerTest, "centerServerTest");
|
|
629
669
|
async function getMeme(ctx, session, count) {
|
|
630
670
|
const log = ctx.logger("getMeme");
|
|
631
671
|
log.debug(`Got: {"form":"${session.platform}:${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
@@ -670,8 +710,8 @@ async function getMeme(ctx, session, count) {
|
|
|
670
710
|
log.warn("Sent:");
|
|
671
711
|
log.warn(msg);
|
|
672
712
|
}
|
|
673
|
-
const
|
|
674
|
-
if (!
|
|
713
|
+
const status2 = await session.send(session.text(msg["success"], msg));
|
|
714
|
+
if (!status2) await session.send(session.text(msg["success"], msg));
|
|
675
715
|
return 0;
|
|
676
716
|
}
|
|
677
717
|
__name(getMeme, "getMeme");
|
|
@@ -687,8 +727,8 @@ async function getCat(ctx, session) {
|
|
|
687
727
|
const response = await request(ctx.config.catAPI, {}, ctx.config.timeout, log);
|
|
688
728
|
if (response.success) {
|
|
689
729
|
log.debug(response.data);
|
|
690
|
-
const
|
|
691
|
-
if (!
|
|
730
|
+
const status2 = await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(response.data[0].url) }));
|
|
731
|
+
if (!status2) await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(response.data[0].url) }));
|
|
692
732
|
log.debug("Sent:");
|
|
693
733
|
log.debug(response.data[0].url);
|
|
694
734
|
} else {
|
|
@@ -820,15 +860,16 @@ async function getNewsMsg(ctx, type) {
|
|
|
820
860
|
log.debug("无新闻");
|
|
821
861
|
return { success: false, data: "" };
|
|
822
862
|
}
|
|
863
|
+
const html = await readNewsFile(response.data, log);
|
|
864
|
+
if (html[1]) return { success: false, data: `渲染图片失败` };
|
|
823
865
|
const page = await ctx.puppeteer.page();
|
|
824
|
-
const html = await readNewsFile(response.data);
|
|
825
866
|
try {
|
|
826
867
|
await page.setViewport({
|
|
827
868
|
width: 800,
|
|
828
869
|
height: 800,
|
|
829
870
|
deviceScaleFactor: 2
|
|
830
871
|
});
|
|
831
|
-
await page.setContent(html, { waitUntil: "networkidle0" });
|
|
872
|
+
await page.setContent(html[0], { waitUntil: "networkidle0" });
|
|
832
873
|
const { width, height } = await page.evaluate(() => ({
|
|
833
874
|
width: document.body.scrollWidth,
|
|
834
875
|
height: document.body.scrollHeight
|
|
@@ -843,7 +884,7 @@ async function getNewsMsg(ctx, type) {
|
|
|
843
884
|
if (type == 0) await ctx.database.upsert("botData", [
|
|
844
885
|
{ id: "newsId", data: response.data.appnews.newsitems[0].gid }
|
|
845
886
|
]);
|
|
846
|
-
return { success: true, data: Buffer.from(image).toString("base64"), msg: "NorthWood
|
|
887
|
+
return { success: true, data: Buffer.from(image).toString("base64"), msg: "NorthWood 发布了一个新闻(原文+机翻):" + response.data.appnews.newsitems[0].title };
|
|
847
888
|
} catch (err) {
|
|
848
889
|
log.error("图片渲染失败:", err);
|
|
849
890
|
return { success: false, data: "图片渲染失败" };
|
|
@@ -857,7 +898,7 @@ async function getNewsMsg(ctx, type) {
|
|
|
857
898
|
__name(getNewsMsg, "getNewsMsg");
|
|
858
899
|
|
|
859
900
|
// package.json
|
|
860
|
-
var version = "2.
|
|
901
|
+
var version = "2.24.0";
|
|
861
902
|
|
|
862
903
|
// src/index.ts
|
|
863
904
|
var inject = ["database", "installer", "puppeteer", "cron"];
|
|
@@ -887,9 +928,6 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
887
928
|
import_koishi3.Schema.object({
|
|
888
929
|
baAPI: import_koishi3.Schema.array(String).default(["https://rba.kanostar.top/portrait"]).description("随机BA图 API")
|
|
889
930
|
}).description("随机BA图"),
|
|
890
|
-
import_koishi3.Schema.object({
|
|
891
|
-
serverPing: import_koishi3.Schema.dict(String).role("table").description("键:群号;值:Host")
|
|
892
|
-
}).description("服之测测(Ping)"),
|
|
893
931
|
import_koishi3.Schema.object({
|
|
894
932
|
steamAPI: import_koishi3.Schema.string().default("https://api.tasaed.top/get/steamid/").description("转换 Steam ID API")
|
|
895
933
|
}).description("转换 Steam ID"),
|
|
@@ -904,7 +942,13 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
904
942
|
}).description("获取 QQ 信息"),
|
|
905
943
|
import_koishi3.Schema.object({
|
|
906
944
|
slNews: import_koishi3.Schema.array(String).default([""]).description("{platform}:{channelId}")
|
|
907
|
-
}).description("SL新闻列表")
|
|
945
|
+
}).description("SL新闻列表"),
|
|
946
|
+
import_koishi3.Schema.object({
|
|
947
|
+
slTest: import_koishi3.Schema.array(import_koishi3.Schema.object({
|
|
948
|
+
id: import_koishi3.Schema.string().description("服务器 ID"),
|
|
949
|
+
name: import_koishi3.Schema.string().description("服务器 名称")
|
|
950
|
+
})).default([{ "id": "1", "name": "中心 鲁贝 1" }, { "id": "19", "name": "中心 斯特拉斯堡 1" }, { "id": "3", "name": "Steam 认证 API" }]).description("测试中心服务器")
|
|
951
|
+
}).description("测试中心服务器")
|
|
908
952
|
]).description("基础设置");
|
|
909
953
|
function apply(ctx) {
|
|
910
954
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
@@ -920,12 +964,14 @@ function apply(ctx) {
|
|
|
920
964
|
{ id: "version", data: version }
|
|
921
965
|
]);
|
|
922
966
|
});
|
|
923
|
-
ctx.command("slnews"
|
|
967
|
+
ctx.command("slnews").action(async () => {
|
|
968
|
+
const log = ctx.logger("slnews");
|
|
924
969
|
const outMsg = await getNewsMsg(ctx, 1);
|
|
925
970
|
if (outMsg.success) {
|
|
926
971
|
return `${outMsg.msg}
|
|
927
972
|
${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` })}`;
|
|
928
973
|
} else {
|
|
974
|
+
log.warn(outMsg);
|
|
929
975
|
if (outMsg.data == "") return "无可用新闻";
|
|
930
976
|
return outMsg.data;
|
|
931
977
|
}
|
|
@@ -933,7 +979,7 @@ ${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` }
|
|
|
933
979
|
ctx.cron("0 * * * *", async () => {
|
|
934
980
|
ctx.emit("node-async/news");
|
|
935
981
|
});
|
|
936
|
-
ctx.cron("
|
|
982
|
+
ctx.cron("30 * * * *", async () => {
|
|
937
983
|
ctx.emit("node-async/news");
|
|
938
984
|
});
|
|
939
985
|
ctx.on("node-async/news", async () => {
|
|
@@ -957,11 +1003,11 @@ ${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` }
|
|
|
957
1003
|
}
|
|
958
1004
|
});
|
|
959
1005
|
ctx.command("status").alias("stats").alias("状态").action(async ({ session }) => {
|
|
960
|
-
const
|
|
961
|
-
if (
|
|
962
|
-
return session?.text(".msg",
|
|
1006
|
+
const status2 = await getStatus(ctx, session);
|
|
1007
|
+
if (status2["success"] == 0) {
|
|
1008
|
+
return session?.text(".msg", status2);
|
|
963
1009
|
} else {
|
|
964
|
-
return session?.text(".failed",
|
|
1010
|
+
return session?.text(".failed", status2);
|
|
965
1011
|
}
|
|
966
1012
|
});
|
|
967
1013
|
ctx.command("random [最小数:number] [最大数:number]").alias("随机数").action(async ({ session }, min, max) => {
|
|
@@ -987,15 +1033,9 @@ ${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` }
|
|
|
987
1033
|
ctx.command("randomBA").alias("随机ba图").action(async ({ session }) => {
|
|
988
1034
|
await getBlueArchive(ctx, session);
|
|
989
1035
|
});
|
|
990
|
-
ctx.command("
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
return session?.text(".msg", server);
|
|
994
|
-
} else if (server["success"] == 1) {
|
|
995
|
-
return session?.text(".forbidden", server);
|
|
996
|
-
} else {
|
|
997
|
-
return session?.text(".failed", server);
|
|
998
|
-
}
|
|
1036
|
+
ctx.command("centerServerTest").alias("测测中心服务器").action(async ({ session }) => {
|
|
1037
|
+
const msg = await centerServerTest(ctx, session);
|
|
1038
|
+
return session?.text(msg.success, msg.data);
|
|
999
1039
|
});
|
|
1000
1040
|
ctx.command("meme [序号:posint]").alias("memes").action(async ({ session }, count) => {
|
|
1001
1041
|
await getMeme(ctx, session, count);
|
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.24.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"contributors": [
|
|
@@ -35,12 +35,14 @@
|
|
|
35
35
|
"@koishijs/plugin-help": "^2.4.5",
|
|
36
36
|
"@koishijs/plugin-market": "^2.11.8",
|
|
37
37
|
"koishi": "^4.18.7",
|
|
38
|
-
"koishi-plugin-puppeteer": "^3.9.0"
|
|
38
|
+
"koishi-plugin-puppeteer": "^3.9.0",
|
|
39
|
+
"koishi-plugin-cron": "^3.1.0"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
42
|
"@bbob/html": "^4.3.1",
|
|
42
43
|
"@bbob/preset-html5": "^4.3.1",
|
|
43
|
-
"
|
|
44
|
+
"bing-translate-api": "^4.2.0",
|
|
45
|
+
"minecraft-server-util": "^5.4.4",
|
|
44
46
|
"steam-server-query": "^1.1.3"
|
|
45
47
|
}
|
|
46
48
|
}
|