koishi-plugin-node-async-bot-all 2.23.0 → 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/fun.d.ts +11 -2
- package/lib/index.js +89 -46
- package/package.json +5 -2
package/lib/fun.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Context } from "koishi";
|
|
2
|
-
import { APINews, APIUserInfo } from "./commands";
|
|
2
|
+
import { APINews, APIUserInfo } from "./commands.ts";
|
|
3
|
+
import { JavaStatusResponse } from 'minecraft-server-util';
|
|
3
4
|
export type HttpResponse<T> = {
|
|
4
5
|
success: true;
|
|
5
6
|
data: T;
|
|
@@ -38,4 +39,12 @@ export declare function request<T = any>(url: string, options?: RequestInit, tim
|
|
|
38
39
|
export declare function readUserCardFile(userInfo: APIUserInfo): Promise<string>;
|
|
39
40
|
export declare function readUserMsgFile(userName: string, userAvatar: string, msg: string): Promise<string>;
|
|
40
41
|
export declare function queryA2S(host: string, log: any): Promise<serverInfo>;
|
|
41
|
-
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.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
|
|
|
@@ -61,6 +61,8 @@ var import_koishi = require("koishi");
|
|
|
61
61
|
var import_steam_server_query = require("steam-server-query");
|
|
62
62
|
var import_html = __toESM(require("@bbob/html"));
|
|
63
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");
|
|
64
66
|
function getSystemName() {
|
|
65
67
|
return import_os.default.type() + " " + import_os.default.release();
|
|
66
68
|
}
|
|
@@ -282,20 +284,62 @@ async function queryA2S(host, log) {
|
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
286
|
__name(queryA2S, "queryA2S");
|
|
285
|
-
async function readNewsFile(info) {
|
|
287
|
+
async function readNewsFile(info, log) {
|
|
286
288
|
let html;
|
|
287
289
|
try {
|
|
288
290
|
const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "slNews.html";
|
|
289
291
|
html = await import_fs.default.promises.readFile(aPath, "utf8");
|
|
290
|
-
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)());
|
|
291
305
|
const date = Number(info.appnews.newsitems[0].date + "000");
|
|
292
|
-
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);
|
|
293
307
|
} catch (error) {
|
|
294
|
-
|
|
308
|
+
log.error(error);
|
|
309
|
+
log.error(error.message);
|
|
310
|
+
return [error, error.message];
|
|
295
311
|
}
|
|
296
|
-
return html;
|
|
312
|
+
return [html];
|
|
297
313
|
}
|
|
298
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");
|
|
299
343
|
|
|
300
344
|
// src/commands.ts
|
|
301
345
|
async function getServer(ctx, session) {
|
|
@@ -353,13 +397,14 @@ async function getServer(ctx, session) {
|
|
|
353
397
|
list = list + "\n" + session.text(".listFailedA2S", temp);
|
|
354
398
|
}
|
|
355
399
|
} else {
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
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) {
|
|
359
404
|
const temp = {
|
|
360
405
|
"count": count,
|
|
361
|
-
"players":
|
|
362
|
-
"version":
|
|
406
|
+
"players": serverInfo.data.players.online + "/" + serverInfo.data.players.max,
|
|
407
|
+
"version": serverInfo.data.version.name,
|
|
363
408
|
"note": note ?? "无"
|
|
364
409
|
};
|
|
365
410
|
log.info(`Server ${count}:`);
|
|
@@ -368,9 +413,9 @@ async function getServer(ctx, session) {
|
|
|
368
413
|
} else {
|
|
369
414
|
const temp = {
|
|
370
415
|
"count": count,
|
|
371
|
-
"players":
|
|
372
|
-
"version":
|
|
373
|
-
"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(", "),
|
|
374
419
|
"note": note ?? "无"
|
|
375
420
|
};
|
|
376
421
|
log.info(`Server ${count}:`);
|
|
@@ -378,22 +423,17 @@ async function getServer(ctx, session) {
|
|
|
378
423
|
list = list + "\n" + session.text(".list", temp);
|
|
379
424
|
}
|
|
380
425
|
} else {
|
|
381
|
-
let err;
|
|
382
|
-
if (
|
|
383
|
-
err =
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
} else if (err.includes("Server read timed out")) {
|
|
393
|
-
err = session.text(".timeout2");
|
|
394
|
-
}
|
|
395
|
-
} else {
|
|
396
|
-
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");
|
|
397
437
|
}
|
|
398
438
|
const temp = {
|
|
399
439
|
"count": count,
|
|
@@ -560,8 +600,8 @@ async function getBlueArchive(ctx, session) {
|
|
|
560
600
|
const link = random(2, ctx.config.baAPI) + `?cacheBuster=${random(1, 1, 2147483647)}`;
|
|
561
601
|
log.info(`Link: ${link}`);
|
|
562
602
|
await (0, import_koishi2.sleep)(ms);
|
|
563
|
-
const
|
|
564
|
-
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) }));
|
|
565
605
|
await session.bot.deleteMessage(session.event.guild?.id, vid[0]);
|
|
566
606
|
return 0;
|
|
567
607
|
}
|
|
@@ -588,11 +628,11 @@ async function centerServerTest(ctx, session) {
|
|
|
588
628
|
const lastTime = response.data.heartbeatList[server.id].at(-1);
|
|
589
629
|
if (lastTime) {
|
|
590
630
|
const uptime24 = (response.data.uptimeList[server.id + "_24"] * 100).toFixed(2) + "%";
|
|
591
|
-
const
|
|
631
|
+
const status2 = lastTime?.status == 1 ? "正常" : "故障";
|
|
592
632
|
const testTime = timeFormatter.format(/* @__PURE__ */ new Date(lastTime?.time.replace(" ", "T") + "Z"));
|
|
593
633
|
list = list + "\n" + session.text(".list", {
|
|
594
634
|
"name": server.name,
|
|
595
|
-
"status":
|
|
635
|
+
"status": status2,
|
|
596
636
|
"uptime": uptime24,
|
|
597
637
|
"time": testTime
|
|
598
638
|
});
|
|
@@ -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"];
|
|
@@ -924,11 +965,13 @@ function apply(ctx) {
|
|
|
924
965
|
]);
|
|
925
966
|
});
|
|
926
967
|
ctx.command("slnews").action(async () => {
|
|
968
|
+
const log = ctx.logger("slnews");
|
|
927
969
|
const outMsg = await getNewsMsg(ctx, 1);
|
|
928
970
|
if (outMsg.success) {
|
|
929
971
|
return `${outMsg.msg}
|
|
930
972
|
${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` })}`;
|
|
931
973
|
} else {
|
|
974
|
+
log.warn(outMsg);
|
|
932
975
|
if (outMsg.data == "") return "无可用新闻";
|
|
933
976
|
return outMsg.data;
|
|
934
977
|
}
|
|
@@ -960,11 +1003,11 @@ ${(0, import_koishi3.h)("image", { url: `data:image/jpg;base64,${outMsg.data}` }
|
|
|
960
1003
|
}
|
|
961
1004
|
});
|
|
962
1005
|
ctx.command("status").alias("stats").alias("状态").action(async ({ session }) => {
|
|
963
|
-
const
|
|
964
|
-
if (
|
|
965
|
-
return session?.text(".msg",
|
|
1006
|
+
const status2 = await getStatus(ctx, session);
|
|
1007
|
+
if (status2["success"] == 0) {
|
|
1008
|
+
return session?.text(".msg", status2);
|
|
966
1009
|
} else {
|
|
967
|
-
return session?.text(".failed",
|
|
1010
|
+
return session?.text(".failed", status2);
|
|
968
1011
|
}
|
|
969
1012
|
});
|
|
970
1013
|
ctx.command("random [最小数:number] [最大数:number]").alias("随机数").action(async ({ session }, min, max) => {
|
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,11 +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",
|
|
44
|
+
"bing-translate-api": "^4.2.0",
|
|
45
|
+
"minecraft-server-util": "^5.4.4",
|
|
43
46
|
"steam-server-query": "^1.1.3"
|
|
44
47
|
}
|
|
45
48
|
}
|