koishi-plugin-node-async-bot-all 2.11.1 → 2.12.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 +1 -0
- package/lib/fun.d.ts +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +115 -37
- package/package.json +1 -1
package/lib/commands.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare function getRW(ctx: Context, session: Session): Promise<Object>;
|
|
|
7
7
|
export declare function getBA(ctx: Context, session: Session): Promise<Number>;
|
|
8
8
|
export declare function serverTest(ctx: Context, session: Session): Promise<Object>;
|
|
9
9
|
export declare function getSteam(ctx: Context, session: Session, id: number): Promise<Object>;
|
|
10
|
+
export declare function getMeme(ctx: Context, session: Session): Promise<Object>;
|
package/lib/fun.d.ts
CHANGED
|
@@ -13,3 +13,8 @@ export declare function hostPing(host: string): Promise<{
|
|
|
13
13
|
packetLoss?: string;
|
|
14
14
|
}>;
|
|
15
15
|
export declare function random(type: number | undefined, data: any, data2?: any): number;
|
|
16
|
+
export declare function getHttp(log: any, url: string, timeout: number): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
data: object;
|
|
19
|
+
error?: boolean;
|
|
20
|
+
}>;
|
package/lib/index.d.ts
CHANGED
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: "执行错误。", unknown: "未知错误。", 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: { wait: "{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) 不得为空。" } } } };
|
|
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: "执行错误。", unknown: "未知错误。", 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: { wait: "{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) 不得为空。", error: "执行错误。" } }, meme: { description: "群友的怪话!", messages: { msg: "{time}\n{image}\n{title}", failed: "{time}\n获取失败:{data}", error: "执行错误。" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -230,6 +230,37 @@ function random(type = 0, data, data2) {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
__name(random, "random");
|
|
233
|
+
async function getHttp(log, url, timeout) {
|
|
234
|
+
let data;
|
|
235
|
+
try {
|
|
236
|
+
const response = await fetchWithTimeout(url, {}, timeout, log);
|
|
237
|
+
if (response.ok) {
|
|
238
|
+
data = await response.text();
|
|
239
|
+
log.info("Server data: " + data);
|
|
240
|
+
return {
|
|
241
|
+
"data": JSON.parse(data),
|
|
242
|
+
"success": true
|
|
243
|
+
};
|
|
244
|
+
} else {
|
|
245
|
+
data = await response.text();
|
|
246
|
+
log.error(`Error fetching data: ${data}`);
|
|
247
|
+
data = JSON.parse(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");
|
|
233
264
|
|
|
234
265
|
// src/commands.ts
|
|
235
266
|
async function getServer(ctx, session) {
|
|
@@ -434,37 +465,36 @@ async function getRW(ctx, session) {
|
|
|
434
465
|
let msg;
|
|
435
466
|
let data;
|
|
436
467
|
const time = getHongKongTime();
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
468
|
+
const response = await getHttp(log, ctx.config.rwAPI + "?format=json", ctx.config.timeout);
|
|
469
|
+
if (response.success) {
|
|
470
|
+
data = response.data;
|
|
471
|
+
msg = {
|
|
472
|
+
"time": time,
|
|
473
|
+
"data": data["data"],
|
|
474
|
+
"success": 0
|
|
475
|
+
};
|
|
476
|
+
log.info("Sent:");
|
|
477
|
+
log.info(msg);
|
|
478
|
+
} else {
|
|
479
|
+
if (response.error) {
|
|
480
|
+
data = response.data;
|
|
442
481
|
msg = {
|
|
443
482
|
"time": time,
|
|
444
|
-
"data": data,
|
|
445
|
-
"success":
|
|
483
|
+
"data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
|
|
484
|
+
"success": 2
|
|
446
485
|
};
|
|
447
486
|
log.info("Sent:");
|
|
448
487
|
log.info(msg);
|
|
449
488
|
} else {
|
|
450
|
-
data =
|
|
451
|
-
log.error(`Error fetching data: ${data}`);
|
|
489
|
+
data = response.data;
|
|
452
490
|
msg = {
|
|
453
491
|
"time": time,
|
|
492
|
+
"data": data["data"],
|
|
454
493
|
"success": 1
|
|
455
494
|
};
|
|
456
495
|
log.info("Sent:");
|
|
457
496
|
log.info(msg);
|
|
458
497
|
}
|
|
459
|
-
} catch (err) {
|
|
460
|
-
log.error(`Request error: ${err.message}`);
|
|
461
|
-
msg = {
|
|
462
|
-
"time": time,
|
|
463
|
-
"data": err.name === "AbortError" ? session.text(".error") : err.message,
|
|
464
|
-
"success": 2
|
|
465
|
-
};
|
|
466
|
-
log.info("Sent:");
|
|
467
|
-
log.info(msg);
|
|
468
498
|
}
|
|
469
499
|
return msg;
|
|
470
500
|
}
|
|
@@ -526,23 +556,28 @@ async function getSteam(ctx, session, id) {
|
|
|
526
556
|
let msg;
|
|
527
557
|
let data;
|
|
528
558
|
const time = getHongKongTime();
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
data
|
|
559
|
+
const response = await getHttp(log, ctx.config.steamAPI + `?format=json&id=${id}`, ctx.config.timeout);
|
|
560
|
+
if (response.success) {
|
|
561
|
+
data = response.data;
|
|
562
|
+
msg = {
|
|
563
|
+
"time": time,
|
|
564
|
+
"data": data["data"],
|
|
565
|
+
"success": 0
|
|
566
|
+
};
|
|
567
|
+
log.info("Sent:");
|
|
568
|
+
log.info(msg);
|
|
569
|
+
} else {
|
|
570
|
+
if (response.error) {
|
|
571
|
+
data = response.data;
|
|
535
572
|
msg = {
|
|
536
573
|
"time": time,
|
|
537
|
-
"data": data["data"],
|
|
538
|
-
"success":
|
|
574
|
+
"data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
|
|
575
|
+
"success": 2
|
|
539
576
|
};
|
|
540
577
|
log.info("Sent:");
|
|
541
578
|
log.info(msg);
|
|
542
579
|
} else {
|
|
543
|
-
data =
|
|
544
|
-
log.error(`Error fetching data: ${data}`);
|
|
545
|
-
data = JSON.parse(data);
|
|
580
|
+
data = response.data;
|
|
546
581
|
msg = {
|
|
547
582
|
"time": time,
|
|
548
583
|
"data": data["data"],
|
|
@@ -551,22 +586,54 @@ async function getSteam(ctx, session, id) {
|
|
|
551
586
|
log.info("Sent:");
|
|
552
587
|
log.info(msg);
|
|
553
588
|
}
|
|
554
|
-
}
|
|
555
|
-
|
|
589
|
+
}
|
|
590
|
+
return msg;
|
|
591
|
+
}
|
|
592
|
+
__name(getSteam, "getSteam");
|
|
593
|
+
async function getMeme(ctx, session) {
|
|
594
|
+
const log = ctx.logger("getMeme");
|
|
595
|
+
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
596
|
+
let msg;
|
|
597
|
+
let data;
|
|
598
|
+
const time = getHongKongTime();
|
|
599
|
+
const response = await getHttp(log, ctx.config.memesAPI, ctx.config.timeout);
|
|
600
|
+
if (response.success) {
|
|
601
|
+
data = response.data;
|
|
556
602
|
msg = {
|
|
557
603
|
"time": time,
|
|
558
|
-
"
|
|
559
|
-
"
|
|
604
|
+
"title": data["data"]["title"],
|
|
605
|
+
"image": import_koishi2.h.image(data["data"]["image"]),
|
|
606
|
+
"success": 0
|
|
560
607
|
};
|
|
561
608
|
log.info("Sent:");
|
|
562
609
|
log.info(msg);
|
|
610
|
+
} else {
|
|
611
|
+
if (response.error) {
|
|
612
|
+
data = response.data;
|
|
613
|
+
msg = {
|
|
614
|
+
"time": time,
|
|
615
|
+
"data": data["name"] === "AbortError" ? session.text(".error") : data["message"],
|
|
616
|
+
"success": 1
|
|
617
|
+
};
|
|
618
|
+
log.info("Sent:");
|
|
619
|
+
log.info(msg);
|
|
620
|
+
} else {
|
|
621
|
+
data = response.data;
|
|
622
|
+
msg = {
|
|
623
|
+
"time": time,
|
|
624
|
+
"data": data["data"],
|
|
625
|
+
"success": 1
|
|
626
|
+
};
|
|
627
|
+
log.info("Sent:");
|
|
628
|
+
log.info(msg);
|
|
629
|
+
}
|
|
563
630
|
}
|
|
564
631
|
return msg;
|
|
565
632
|
}
|
|
566
|
-
__name(
|
|
633
|
+
__name(getMeme, "getMeme");
|
|
567
634
|
|
|
568
635
|
// package.json
|
|
569
|
-
var version = "2.
|
|
636
|
+
var version = "2.12.0";
|
|
570
637
|
|
|
571
638
|
// src/index.ts
|
|
572
639
|
var inject = ["database"];
|
|
@@ -596,7 +663,10 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
596
663
|
}).description("服之测测(Ping)"),
|
|
597
664
|
import_koishi3.Schema.object({
|
|
598
665
|
steamAPI: import_koishi3.Schema.string().default("https://api.tasaed.top/get/steamid/").description("转换 Steam ID API")
|
|
599
|
-
}).description("转换 Steam ID")
|
|
666
|
+
}).description("转换 Steam ID"),
|
|
667
|
+
import_koishi3.Schema.object({
|
|
668
|
+
memesAPI: import_koishi3.Schema.string().description("群友 meme API")
|
|
669
|
+
}).description("群友 meme")
|
|
600
670
|
]).description("基础设置");
|
|
601
671
|
function apply(ctx) {
|
|
602
672
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
@@ -676,6 +746,14 @@ function apply(ctx) {
|
|
|
676
746
|
return session?.text(".failed", steam);
|
|
677
747
|
}
|
|
678
748
|
});
|
|
749
|
+
ctx.command("meme").alias("memes").action(async ({ session }) => {
|
|
750
|
+
const steam = await getMeme(ctx, session);
|
|
751
|
+
if (steam["success"] == 0) {
|
|
752
|
+
return session?.text(".msg", steam);
|
|
753
|
+
} else {
|
|
754
|
+
return session?.text(".failed", steam);
|
|
755
|
+
}
|
|
756
|
+
});
|
|
679
757
|
}
|
|
680
758
|
__name(apply, "apply");
|
|
681
759
|
// Annotate the CommonJS export names for ESM import in node:
|