koishi-plugin-node-async-bot-all 2.18.1 → 2.19.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 +0 -6
- package/lib/index.js +59 -136
- package/package.json +1 -1
package/lib/fun.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Context } from "koishi";
|
|
|
3
3
|
import { APIUserInfo } from "./commands";
|
|
4
4
|
export declare function getSystemUsage(): Promise<Object>;
|
|
5
5
|
export declare function getHongKongTime(): string;
|
|
6
|
-
export declare function fetchWithTimeout(url: string, options: {} | undefined, timeout: number | undefined, log: any): Promise<Response>;
|
|
7
6
|
export declare function readInfoFile(ctx: Context): Promise<string>;
|
|
8
7
|
export declare function formatTimestampDiff(start: number, end: number): string;
|
|
9
8
|
export declare function getMsgCount(ctx: Context): Promise<Object>;
|
|
@@ -15,10 +14,5 @@ export declare function hostPing(host: string): Promise<{
|
|
|
15
14
|
packetLoss?: string;
|
|
16
15
|
}>;
|
|
17
16
|
export declare function random(type: number | undefined, data: any, data2?: any): number;
|
|
18
|
-
export declare function getHttp(log: any, url: string, timeout: number): Promise<{
|
|
19
|
-
success: boolean;
|
|
20
|
-
data: object;
|
|
21
|
-
error?: boolean;
|
|
22
|
-
}>;
|
|
23
17
|
export declare function request<T = any>(url: string, options?: RequestInit, timeout?: number, log?: any): Promise<HttpResponse<T>>;
|
|
24
18
|
export declare function readUserCardFile(userInfo: APIUserInfo): Promise<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➣ 请稍后重试。", 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: "执行错误。",
|
|
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: "执行错误。", 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 号不正确。" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -132,33 +132,6 @@ function getHongKongTime() {
|
|
|
132
132
|
return `${dateObj.year}-${dateObj.month}-${dateObj.day} ${dateObj.hour}:${dateObj.minute}:${dateObj.second}`;
|
|
133
133
|
}
|
|
134
134
|
__name(getHongKongTime, "getHongKongTime");
|
|
135
|
-
async function fetchWithTimeout(url, options = {}, timeout = 5e3, log) {
|
|
136
|
-
const controller = new AbortController();
|
|
137
|
-
const { signal } = controller;
|
|
138
|
-
const fetchOptions = {
|
|
139
|
-
...options,
|
|
140
|
-
signal
|
|
141
|
-
};
|
|
142
|
-
const timeoutId = setTimeout(() => {
|
|
143
|
-
controller.abort();
|
|
144
|
-
}, timeout);
|
|
145
|
-
try {
|
|
146
|
-
const response = await fetch(url, fetchOptions);
|
|
147
|
-
clearTimeout(timeoutId);
|
|
148
|
-
log.info(`Fetch code: ${response.status}`);
|
|
149
|
-
return response;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
clearTimeout(timeoutId);
|
|
152
|
-
log.error(error);
|
|
153
|
-
log.error(`${error.name}: ${error.message}`);
|
|
154
|
-
if (error.name === "AbortError") {
|
|
155
|
-
throw new Error(`请求超时。(${timeout}ms)`);
|
|
156
|
-
} else {
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
__name(fetchWithTimeout, "fetchWithTimeout");
|
|
162
135
|
async function readInfoFile(ctx) {
|
|
163
136
|
let info;
|
|
164
137
|
try {
|
|
@@ -231,36 +204,6 @@ function random(type = 0, data, data2) {
|
|
|
231
204
|
}
|
|
232
205
|
}
|
|
233
206
|
__name(random, "random");
|
|
234
|
-
async function getHttp(log, url, timeout) {
|
|
235
|
-
let data;
|
|
236
|
-
try {
|
|
237
|
-
const response = await fetchWithTimeout(url, {}, timeout, log);
|
|
238
|
-
if (response.ok) {
|
|
239
|
-
data = await response.text();
|
|
240
|
-
log.info("Server data: " + data);
|
|
241
|
-
return {
|
|
242
|
-
"data": JSON.parse(data),
|
|
243
|
-
"success": true
|
|
244
|
-
};
|
|
245
|
-
} else {
|
|
246
|
-
data = await response.text();
|
|
247
|
-
log.error(`Error fetching data: ${data}`);
|
|
248
|
-
return {
|
|
249
|
-
"data": JSON.parse(data),
|
|
250
|
-
"error": false,
|
|
251
|
-
"success": false
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
} catch (err) {
|
|
255
|
-
log.error(`Request error: ${err.message}`);
|
|
256
|
-
return {
|
|
257
|
-
"data": { "name": err.name, "message": err.message },
|
|
258
|
-
"error": true,
|
|
259
|
-
"success": false
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
__name(getHttp, "getHttp");
|
|
264
207
|
async function request(url, options = {}, timeout = 8e3, log) {
|
|
265
208
|
const signal = AbortSignal.timeout(timeout);
|
|
266
209
|
try {
|
|
@@ -332,8 +275,6 @@ async function getServer(ctx, session) {
|
|
|
332
275
|
const log = ctx.logger("cx");
|
|
333
276
|
log.debug(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
334
277
|
let msg;
|
|
335
|
-
let data;
|
|
336
|
-
let error;
|
|
337
278
|
const time = getHongKongTime();
|
|
338
279
|
const index = ctx.config.cxV2.findIndex((item) => item.id === session.event.guild?.id);
|
|
339
280
|
if (index !== -1) {
|
|
@@ -344,8 +285,8 @@ async function getServer(ctx, session) {
|
|
|
344
285
|
"data": "未指定查询 API",
|
|
345
286
|
"success": 2
|
|
346
287
|
};
|
|
347
|
-
log.
|
|
348
|
-
log.
|
|
288
|
+
log.warn("Sent:");
|
|
289
|
+
log.warn(msg);
|
|
349
290
|
return msg;
|
|
350
291
|
}
|
|
351
292
|
let count = 0;
|
|
@@ -353,14 +294,13 @@ async function getServer(ctx, session) {
|
|
|
353
294
|
for (const item of api) {
|
|
354
295
|
const note = ctx.config.cxV2[index]["note"][count];
|
|
355
296
|
count++;
|
|
356
|
-
const response = await
|
|
297
|
+
const response = await request(item, {}, ctx.config.timeout, log);
|
|
357
298
|
if (response.success) {
|
|
358
|
-
|
|
359
|
-
if (data["list"] == null) {
|
|
299
|
+
if (response.data.list == null) {
|
|
360
300
|
const temp = {
|
|
361
301
|
"count": count,
|
|
362
|
-
"players": data
|
|
363
|
-
"version": data
|
|
302
|
+
"players": response.data.players,
|
|
303
|
+
"version": response.data.version,
|
|
364
304
|
"note": note ?? "无"
|
|
365
305
|
};
|
|
366
306
|
log.info(`Server ${count}:`);
|
|
@@ -369,9 +309,9 @@ async function getServer(ctx, session) {
|
|
|
369
309
|
} else {
|
|
370
310
|
const temp = {
|
|
371
311
|
"count": count,
|
|
372
|
-
"players": data
|
|
373
|
-
"version": data
|
|
374
|
-
"list": data
|
|
312
|
+
"players": response.data.players,
|
|
313
|
+
"version": response.data.version,
|
|
314
|
+
"list": response.data.list.join(", "),
|
|
375
315
|
"note": note ?? "无"
|
|
376
316
|
};
|
|
377
317
|
log.info(`Server ${count}:`);
|
|
@@ -379,37 +319,30 @@ async function getServer(ctx, session) {
|
|
|
379
319
|
list = list + "\n" + session.text(".list", temp);
|
|
380
320
|
}
|
|
381
321
|
} else {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
error = session.text(".close");
|
|
396
|
-
} else if (error.includes("No route to host")) {
|
|
397
|
-
error = session.text(".host");
|
|
398
|
-
} else if (error.includes("Connection timed out")) {
|
|
399
|
-
error = session.text(".timeout");
|
|
400
|
-
} else if (error.includes("Server returned too few data")) {
|
|
401
|
-
error = session.text(".fewData");
|
|
402
|
-
} else if (error.includes("Server read timed out")) {
|
|
403
|
-
error = session.text(".timeout2");
|
|
322
|
+
let err;
|
|
323
|
+
if (response.code) {
|
|
324
|
+
err = response.isJson ? response.error["data"] : response.error;
|
|
325
|
+
if (err.includes("Connection refused")) {
|
|
326
|
+
err = session.text(".close");
|
|
327
|
+
} else if (err.includes("No route to host")) {
|
|
328
|
+
err = session.text(".host");
|
|
329
|
+
} else if (err.includes("Connection timed out")) {
|
|
330
|
+
err = session.text(".timeout");
|
|
331
|
+
} else if (err.includes("Server returned too few data")) {
|
|
332
|
+
err = session.text(".fewData");
|
|
333
|
+
} else if (err.includes("Server read timed out")) {
|
|
334
|
+
err = session.text(".timeout2");
|
|
404
335
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
"data": error
|
|
408
|
-
};
|
|
409
|
-
log.info(`Server ${count}:`);
|
|
410
|
-
log.info(temp);
|
|
411
|
-
list = list + "\n" + session.text(".listFailed", temp);
|
|
336
|
+
} else {
|
|
337
|
+
err = response.error.message;
|
|
412
338
|
}
|
|
339
|
+
const temp = {
|
|
340
|
+
"count": count,
|
|
341
|
+
"data": err
|
|
342
|
+
};
|
|
343
|
+
log.error(`Server ${count}:`);
|
|
344
|
+
log.error(temp);
|
|
345
|
+
list = list + "\n" + session.text(".listFailed", temp);
|
|
413
346
|
}
|
|
414
347
|
}
|
|
415
348
|
msg = {
|
|
@@ -457,8 +390,8 @@ async function getStatus(ctx, session) {
|
|
|
457
390
|
"success": 0
|
|
458
391
|
};
|
|
459
392
|
}
|
|
460
|
-
log.
|
|
461
|
-
log.
|
|
393
|
+
log.debug("Sent:");
|
|
394
|
+
log.debug(msg);
|
|
462
395
|
return msg;
|
|
463
396
|
}
|
|
464
397
|
__name(getStatus, "getStatus");
|
|
@@ -480,8 +413,8 @@ async function getRandom(ctx, session, min, max) {
|
|
|
480
413
|
"data": data,
|
|
481
414
|
"success": 0
|
|
482
415
|
};
|
|
483
|
-
log.
|
|
484
|
-
log.
|
|
416
|
+
log.debug("Sent:");
|
|
417
|
+
log.debug(msg);
|
|
485
418
|
return msg;
|
|
486
419
|
}
|
|
487
420
|
__name(getRandom, "getRandom");
|
|
@@ -506,8 +439,8 @@ async function getInfo(ctx, session) {
|
|
|
506
439
|
"success": 0
|
|
507
440
|
};
|
|
508
441
|
}
|
|
509
|
-
log.
|
|
510
|
-
log.
|
|
442
|
+
log.debug("Sent:");
|
|
443
|
+
log.debug(msg);
|
|
511
444
|
return msg;
|
|
512
445
|
}
|
|
513
446
|
__name(getInfo, "getInfo");
|
|
@@ -515,7 +448,6 @@ async function getRandomWord(ctx, session) {
|
|
|
515
448
|
const log = ctx.logger("rw");
|
|
516
449
|
log.debug(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
517
450
|
let msg;
|
|
518
|
-
let data;
|
|
519
451
|
const time = getHongKongTime();
|
|
520
452
|
if (ctx.config.rwAPI == void 0) {
|
|
521
453
|
msg = {
|
|
@@ -523,40 +455,33 @@ async function getRandomWord(ctx, session) {
|
|
|
523
455
|
"data": "未指定 API",
|
|
524
456
|
"success": 2
|
|
525
457
|
};
|
|
526
|
-
log.
|
|
527
|
-
log.
|
|
458
|
+
log.warn("Sent:");
|
|
459
|
+
log.warn(msg);
|
|
528
460
|
return msg;
|
|
529
461
|
}
|
|
530
|
-
const response = await
|
|
462
|
+
const response = await request(ctx.config.rwAPI + "?format=json", {}, ctx.config.timeout, log);
|
|
531
463
|
if (response.success) {
|
|
532
|
-
data = response.data;
|
|
533
464
|
msg = {
|
|
534
465
|
"time": time,
|
|
535
|
-
"data": data
|
|
466
|
+
"data": response.data,
|
|
536
467
|
"success": 0
|
|
537
468
|
};
|
|
538
|
-
log.
|
|
539
|
-
log.
|
|
469
|
+
log.debug("Sent:");
|
|
470
|
+
log.debug(msg);
|
|
540
471
|
} else {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
"time": time,
|
|
545
|
-
"data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
|
|
546
|
-
"success": 2
|
|
547
|
-
};
|
|
548
|
-
log.info("Sent:");
|
|
549
|
-
log.info(msg);
|
|
472
|
+
let err;
|
|
473
|
+
if (response.code) {
|
|
474
|
+
err = response.isJson ? response.error["data"] : response.error;
|
|
550
475
|
} else {
|
|
551
|
-
|
|
552
|
-
msg = {
|
|
553
|
-
"time": time,
|
|
554
|
-
"data": data["data"],
|
|
555
|
-
"success": 1
|
|
556
|
-
};
|
|
557
|
-
log.info("Sent:");
|
|
558
|
-
log.info(msg);
|
|
476
|
+
err = response.error.message;
|
|
559
477
|
}
|
|
478
|
+
msg = {
|
|
479
|
+
"time": time,
|
|
480
|
+
"data": err,
|
|
481
|
+
"success": 1
|
|
482
|
+
};
|
|
483
|
+
log.warn("Sent:");
|
|
484
|
+
log.warn(msg);
|
|
560
485
|
}
|
|
561
486
|
return msg;
|
|
562
487
|
}
|
|
@@ -678,7 +603,8 @@ async function getCat(ctx, session) {
|
|
|
678
603
|
const response = await request(ctx.config.catAPI, {}, ctx.config.timeout, log);
|
|
679
604
|
if (response.success) {
|
|
680
605
|
log.debug(response.data);
|
|
681
|
-
await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(response.data[0].url) }));
|
|
606
|
+
const status = await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(response.data[0].url) }));
|
|
607
|
+
if (!status) await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(response.data[0].url) }));
|
|
682
608
|
log.debug("Sent:");
|
|
683
609
|
log.debug(response.data[0].url);
|
|
684
610
|
} else {
|
|
@@ -706,7 +632,6 @@ async function getQQInfo(ctx, session, qq) {
|
|
|
706
632
|
}
|
|
707
633
|
const response = await request(ctx.config.qqAPI + `?qq=${qq}`, {}, ctx.config.timeout, log);
|
|
708
634
|
if (response.success) {
|
|
709
|
-
log.info(response.data);
|
|
710
635
|
const fullHtml = await readUserCardFile(response.data);
|
|
711
636
|
const page = await ctx.puppeteer.page();
|
|
712
637
|
await page.setViewport({
|
|
@@ -735,7 +660,7 @@ async function getQQInfo(ctx, session, qq) {
|
|
|
735
660
|
__name(getQQInfo, "getQQInfo");
|
|
736
661
|
|
|
737
662
|
// package.json
|
|
738
|
-
var version = "2.
|
|
663
|
+
var version = "2.19.0";
|
|
739
664
|
|
|
740
665
|
// src/index.ts
|
|
741
666
|
var inject = ["database", "installer", "puppeteer"];
|
|
@@ -824,10 +749,8 @@ function apply(ctx) {
|
|
|
824
749
|
const rw = await getRandomWord(ctx, session);
|
|
825
750
|
if (rw["success"] == 0) {
|
|
826
751
|
return session?.text(".msg", rw);
|
|
827
|
-
} else if (rw["success"] == 1) {
|
|
828
|
-
return session?.text(".failed1", rw);
|
|
829
752
|
} else {
|
|
830
|
-
return session?.text(".
|
|
753
|
+
return session?.text(".failed", rw);
|
|
831
754
|
}
|
|
832
755
|
});
|
|
833
756
|
ctx.command("randomBA").alias("随机ba图").action(async ({ session }) => {
|