koishi-plugin-node-async-bot-all 2.13.1 → 2.15.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 +7 -1
- package/lib/index.js +71 -70
- package/package.json +1 -1
- package/res/info.txt +2 -0
package/lib/commands.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Context, Session } from 'koishi';
|
|
2
|
+
import { Installer } from "@koishijs/plugin-market";
|
|
3
|
+
declare module 'koishi' {
|
|
4
|
+
interface Context {
|
|
5
|
+
installer: Installer;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
2
8
|
export declare function getServer(ctx: Context, session: Session): Promise<Object>;
|
|
3
9
|
export declare function getStatus(ctx: Context, session: Session): Promise<Object>;
|
|
4
10
|
export declare function getRandom(ctx: Context, session: Session, min: number, max: number): Promise<Object>;
|
|
@@ -7,4 +13,4 @@ export declare function getRW(ctx: Context, session: Session): Promise<Object>;
|
|
|
7
13
|
export declare function getBA(ctx: Context, session: Session): Promise<Number>;
|
|
8
14
|
export declare function serverTest(ctx: Context, session: Session): Promise<Object>;
|
|
9
15
|
export declare function getSteam(ctx: Context, session: Session, id: number): Promise<Object>;
|
|
10
|
-
export declare function getMeme(ctx: Context, session: Session): Promise<Object>;
|
|
16
|
+
export declare function getMeme(ctx: Context, session: Session, count: number): Promise<Object>;
|
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➣ 请稍后重试。", forbidden: "{time}\n此指令不允许在本群使用。", failed: "{time}\n查询失败:{data}", timeout: "请求超时。", timeout2: "响应超时。", fewData: "服务端返回的数据过少。", close: "服务器已关闭。", error: "执行错误。",
|
|
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➣ 请稍后重试。", 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: "执行错误。", failed1: "{time}\n获取失败(1)。", failed2: "{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}" } }, steamid: { description: "将 Steam 好友码(SteamID 3)转为 SteamID 64。", messages: { msg: "{time}\n转换结果:{data}", failed: "{time}\n转换失败:{data}", null: "参数 Steam 好友码(SteamID 3) 不得为空。", command: "执行错误。" } }, meme: { description: "群友的怪话!", messages: { msg: "{quote}{time}\n{image}\n{title}", failed: "{quote}{time}\n获取失败:{data}", forbidden: "{quote}{time}\n此指令不允许在本群使用。", error: "执行错误。" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -164,10 +164,11 @@ async function readInfoFile(ctx) {
|
|
|
164
164
|
try {
|
|
165
165
|
const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "info.txt";
|
|
166
166
|
info = await import_fs.default.promises.readFile(aPath, "utf8");
|
|
167
|
+
const deps = await ctx.installer.getDeps();
|
|
167
168
|
info = info.toString().replace(
|
|
168
169
|
"&version;",
|
|
169
170
|
(await ctx.database.get("botData", "version"))[0].data
|
|
170
|
-
);
|
|
171
|
+
).replace("&kVersion;", deps.koishi.resolved).replace("&nVersion;", process.versions.node);
|
|
171
172
|
} catch (error) {
|
|
172
173
|
info = error.message;
|
|
173
174
|
}
|
|
@@ -244,7 +245,6 @@ async function getHttp(log, url, timeout) {
|
|
|
244
245
|
} else {
|
|
245
246
|
data = await response.text();
|
|
246
247
|
log.error(`Error fetching data: ${data}`);
|
|
247
|
-
data = JSON.parse(data);
|
|
248
248
|
return {
|
|
249
249
|
"data": JSON.parse(data),
|
|
250
250
|
"error": false,
|
|
@@ -267,7 +267,6 @@ async function getServer(ctx, session) {
|
|
|
267
267
|
const log = ctx.logger("cx");
|
|
268
268
|
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
269
269
|
let msg;
|
|
270
|
-
let dataError;
|
|
271
270
|
let data;
|
|
272
271
|
let error;
|
|
273
272
|
const time = getHongKongTime();
|
|
@@ -289,58 +288,55 @@ async function getServer(ctx, session) {
|
|
|
289
288
|
for (const item of api) {
|
|
290
289
|
const note = ctx.config.cxV2[index]["note"][count];
|
|
291
290
|
count++;
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
log.info(`Server ${count}:`);
|
|
306
|
-
log.info(temp);
|
|
307
|
-
list = list + "\n" + session.text(".listNoPlayer", temp);
|
|
308
|
-
} else {
|
|
309
|
-
const temp = {
|
|
310
|
-
"count": count,
|
|
311
|
-
"players": data["players"],
|
|
312
|
-
"version": data["version"],
|
|
313
|
-
"list": data["list"].join(", "),
|
|
314
|
-
"note": note ?? "无"
|
|
315
|
-
};
|
|
316
|
-
log.info(`Server ${count}:`);
|
|
317
|
-
log.info(temp);
|
|
318
|
-
list = list + "\n" + session.text(".list", temp);
|
|
319
|
-
}
|
|
291
|
+
const response = await getHttp(log, item, ctx.config.timeout);
|
|
292
|
+
if (response.success) {
|
|
293
|
+
data = response.data;
|
|
294
|
+
if (data["list"] == null) {
|
|
295
|
+
const temp = {
|
|
296
|
+
"count": count,
|
|
297
|
+
"players": data["players"],
|
|
298
|
+
"version": data["version"],
|
|
299
|
+
"note": note ?? "无"
|
|
300
|
+
};
|
|
301
|
+
log.info(`Server ${count}:`);
|
|
302
|
+
log.info(temp);
|
|
303
|
+
list = list + "\n" + session.text(".listNoPlayer", temp);
|
|
320
304
|
} else {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
305
|
+
const temp = {
|
|
306
|
+
"count": count,
|
|
307
|
+
"players": data["players"],
|
|
308
|
+
"version": data["version"],
|
|
309
|
+
"list": data["list"].join(", "),
|
|
310
|
+
"note": note ?? "无"
|
|
311
|
+
};
|
|
312
|
+
log.info(`Server ${count}:`);
|
|
313
|
+
log.info(temp);
|
|
314
|
+
list = list + "\n" + session.text(".list", temp);
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
if (response.error) {
|
|
318
|
+
data = response.data;
|
|
319
|
+
const temp = {
|
|
320
|
+
"count": count,
|
|
321
|
+
"data": data["name"] === "AbortError" ? session.text(".error") : data["message"]
|
|
322
|
+
};
|
|
323
|
+
log.info(`Server ${count}:`);
|
|
324
|
+
log.info(temp);
|
|
325
|
+
list = list + "\n" + session.text(".listFailed", temp);
|
|
326
|
+
} else {
|
|
327
|
+
data = response.data;
|
|
328
|
+
error = data["data"];
|
|
329
|
+
if (error.includes("Connection refused")) {
|
|
330
|
+
error = session.text(".close");
|
|
331
|
+
} else if (error.includes("No route to host")) {
|
|
332
|
+
error = session.text(".host");
|
|
333
|
+
} else if (error.includes("Connection timed out")) {
|
|
334
|
+
error = session.text(".timeout");
|
|
335
|
+
} else if (error.includes("Server returned too few data")) {
|
|
336
|
+
error = session.text(".fewData");
|
|
337
|
+
} else if (error.includes("Server read timed out")) {
|
|
338
|
+
error = session.text(".timeout2");
|
|
342
339
|
}
|
|
343
|
-
log.error(`Error fetching data: ${dataError}`);
|
|
344
340
|
const temp = {
|
|
345
341
|
"count": count,
|
|
346
342
|
"data": error
|
|
@@ -349,15 +345,6 @@ async function getServer(ctx, session) {
|
|
|
349
345
|
log.info(temp);
|
|
350
346
|
list = list + "\n" + session.text(".listFailed", temp);
|
|
351
347
|
}
|
|
352
|
-
} catch (err) {
|
|
353
|
-
log.error(`Request error: ${err.message}`);
|
|
354
|
-
const temp = {
|
|
355
|
-
"count": count,
|
|
356
|
-
"data": err.name === "AbortError" ? session.text(".error") : err.message
|
|
357
|
-
};
|
|
358
|
-
log.info(`Server ${count}:`);
|
|
359
|
-
log.info(temp);
|
|
360
|
-
list = list + "\n" + session.text(".listFailed", temp);
|
|
361
348
|
}
|
|
362
349
|
}
|
|
363
350
|
msg = {
|
|
@@ -465,6 +452,16 @@ async function getRW(ctx, session) {
|
|
|
465
452
|
let msg;
|
|
466
453
|
let data;
|
|
467
454
|
const time = getHongKongTime();
|
|
455
|
+
if (ctx.config.rwAPI == void 0) {
|
|
456
|
+
msg = {
|
|
457
|
+
"time": time,
|
|
458
|
+
"data": "未指定 API",
|
|
459
|
+
"success": 2
|
|
460
|
+
};
|
|
461
|
+
log.info("Sent:");
|
|
462
|
+
log.info(msg);
|
|
463
|
+
return msg;
|
|
464
|
+
}
|
|
468
465
|
const response = await getHttp(log, ctx.config.rwAPI + "?format=json", ctx.config.timeout);
|
|
469
466
|
if (response.success) {
|
|
470
467
|
data = response.data;
|
|
@@ -503,6 +500,10 @@ async function getBA(ctx, session) {
|
|
|
503
500
|
const log = ctx.logger("ba");
|
|
504
501
|
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
505
502
|
const time = getHongKongTime();
|
|
503
|
+
if (ctx.config.rwAPI == void 0) {
|
|
504
|
+
await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": "未指定 API" }));
|
|
505
|
+
return 1;
|
|
506
|
+
}
|
|
506
507
|
const vid = await session.send(session.text(".wait", { "quote": import_koishi2.h.quote(session.messageId), "time": time }));
|
|
507
508
|
const ms = random(0, 0, 1500);
|
|
508
509
|
const link = random(2, ctx.config.baAPI) + `?cacheBuster=${random(1, 1, 2147483647)}`;
|
|
@@ -571,7 +572,7 @@ async function getSteam(ctx, session, id) {
|
|
|
571
572
|
data = response.data;
|
|
572
573
|
msg = {
|
|
573
574
|
"time": time,
|
|
574
|
-
"data": data["name"] === "AbortError" ? session.text(".
|
|
575
|
+
"data": data["name"] === "AbortError" ? session.text(".command") : data["message"],
|
|
575
576
|
"success": 2
|
|
576
577
|
};
|
|
577
578
|
log.info("Sent:");
|
|
@@ -590,7 +591,7 @@ async function getSteam(ctx, session, id) {
|
|
|
590
591
|
return msg;
|
|
591
592
|
}
|
|
592
593
|
__name(getSteam, "getSteam");
|
|
593
|
-
async function getMeme(ctx, session) {
|
|
594
|
+
async function getMeme(ctx, session, count) {
|
|
594
595
|
const log = ctx.logger("getMeme");
|
|
595
596
|
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
596
597
|
let msg;
|
|
@@ -607,7 +608,7 @@ async function getMeme(ctx, session) {
|
|
|
607
608
|
log.info(msg);
|
|
608
609
|
return msg;
|
|
609
610
|
}
|
|
610
|
-
const response = await getHttp(log, api, ctx.config.timeout);
|
|
611
|
+
const response = count ? await getHttp(log, api + `&type=1&count=${count}`, ctx.config.timeout) : await getHttp(log, api, ctx.config.timeout);
|
|
611
612
|
if (response.success) {
|
|
612
613
|
data = response.data;
|
|
613
614
|
msg = {
|
|
@@ -647,10 +648,10 @@ async function getMeme(ctx, session) {
|
|
|
647
648
|
__name(getMeme, "getMeme");
|
|
648
649
|
|
|
649
650
|
// package.json
|
|
650
|
-
var version = "2.
|
|
651
|
+
var version = "2.15.0";
|
|
651
652
|
|
|
652
653
|
// src/index.ts
|
|
653
|
-
var inject = ["database"];
|
|
654
|
+
var inject = ["database", "installer"];
|
|
654
655
|
var name = "node-async-bot-all";
|
|
655
656
|
var usage = "这是一个私有插件。";
|
|
656
657
|
var Config = import_koishi3.Schema.intersect([
|
|
@@ -760,8 +761,8 @@ function apply(ctx) {
|
|
|
760
761
|
return session?.text(".failed", steam);
|
|
761
762
|
}
|
|
762
763
|
});
|
|
763
|
-
ctx.command("meme").alias("memes").action(async ({ session }) => {
|
|
764
|
-
const meme = await getMeme(ctx, session);
|
|
764
|
+
ctx.command("meme [序号:posint]").alias("memes").action(async ({ session }, count) => {
|
|
765
|
+
const meme = await getMeme(ctx, session, count);
|
|
765
766
|
if (meme["success"] == 0) {
|
|
766
767
|
return session?.text(".msg", meme);
|
|
767
768
|
} else if (meme["success"] == 1) {
|
package/package.json
CHANGED