koishi-plugin-node-async-bot-all 2.10.0 → 2.11.1
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/index.d.ts +1 -0
- package/lib/index.js +62 -4
- package/package.json +1 -1
package/lib/commands.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function getInfo(ctx: Context, session: Session): Promise<Object>
|
|
|
6
6
|
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
|
+
export declare function getSteam(ctx: Context, session: Session, id: number): Promise<Object>;
|
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: {
|
|
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) 不得为空。" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -520,9 +520,53 @@ async function serverTest(ctx, session) {
|
|
|
520
520
|
};
|
|
521
521
|
}
|
|
522
522
|
__name(serverTest, "serverTest");
|
|
523
|
+
async function getSteam(ctx, session, id) {
|
|
524
|
+
const log = ctx.logger("steamId");
|
|
525
|
+
log.info(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
526
|
+
let msg;
|
|
527
|
+
let data;
|
|
528
|
+
const time = getHongKongTime();
|
|
529
|
+
try {
|
|
530
|
+
const response = await fetchWithTimeout(ctx.config.steamAPI + `?format=json&id=${id}`, {}, ctx.config.timeout, log);
|
|
531
|
+
if (response.ok) {
|
|
532
|
+
data = await response.text();
|
|
533
|
+
log.info("Server data: " + data);
|
|
534
|
+
data = JSON.parse(data);
|
|
535
|
+
msg = {
|
|
536
|
+
"time": time,
|
|
537
|
+
"data": data["data"],
|
|
538
|
+
"success": 0
|
|
539
|
+
};
|
|
540
|
+
log.info("Sent:");
|
|
541
|
+
log.info(msg);
|
|
542
|
+
} else {
|
|
543
|
+
data = await response.text();
|
|
544
|
+
log.error(`Error fetching data: ${data}`);
|
|
545
|
+
data = JSON.parse(data);
|
|
546
|
+
msg = {
|
|
547
|
+
"time": time,
|
|
548
|
+
"data": data["data"],
|
|
549
|
+
"success": 1
|
|
550
|
+
};
|
|
551
|
+
log.info("Sent:");
|
|
552
|
+
log.info(msg);
|
|
553
|
+
}
|
|
554
|
+
} catch (err) {
|
|
555
|
+
log.error(`Request error: ${err.message}`);
|
|
556
|
+
msg = {
|
|
557
|
+
"time": time,
|
|
558
|
+
"data": err.name === "AbortError" ? session.text(".error") : err.message,
|
|
559
|
+
"success": 2
|
|
560
|
+
};
|
|
561
|
+
log.info("Sent:");
|
|
562
|
+
log.info(msg);
|
|
563
|
+
}
|
|
564
|
+
return msg;
|
|
565
|
+
}
|
|
566
|
+
__name(getSteam, "getSteam");
|
|
523
567
|
|
|
524
568
|
// package.json
|
|
525
|
-
var version = "2.
|
|
569
|
+
var version = "2.11.1";
|
|
526
570
|
|
|
527
571
|
// src/index.ts
|
|
528
572
|
var inject = ["database"];
|
|
@@ -549,7 +593,10 @@ var Config = import_koishi3.Schema.intersect([
|
|
|
549
593
|
}).description("随机BA图"),
|
|
550
594
|
import_koishi3.Schema.object({
|
|
551
595
|
serverPing: import_koishi3.Schema.dict(String).role("table").description("键:群号;值:Host")
|
|
552
|
-
}).description("服之测测(Ping)")
|
|
596
|
+
}).description("服之测测(Ping)"),
|
|
597
|
+
import_koishi3.Schema.object({
|
|
598
|
+
steamAPI: import_koishi3.Schema.string().default("https://api.tasaed.top/get/steamid/").description("转换 Steam ID API")
|
|
599
|
+
}).description("转换 Steam ID")
|
|
553
600
|
]).description("基础设置");
|
|
554
601
|
function apply(ctx) {
|
|
555
602
|
ctx.i18n.define("zh-CN", require_zh_CN());
|
|
@@ -565,7 +612,7 @@ function apply(ctx) {
|
|
|
565
612
|
{ id: "version", data: version }
|
|
566
613
|
]);
|
|
567
614
|
});
|
|
568
|
-
ctx.command("
|
|
615
|
+
ctx.command("cxGame").action(async ({ session }) => {
|
|
569
616
|
const cx = await getServer(ctx, session);
|
|
570
617
|
if (cx["success"] == 0) {
|
|
571
618
|
return session?.text(".msg", cx);
|
|
@@ -618,6 +665,17 @@ function apply(ctx) {
|
|
|
618
665
|
return session?.text(".failed", server);
|
|
619
666
|
}
|
|
620
667
|
});
|
|
668
|
+
ctx.command("steamId <Steam 好友码(SteamID 3):posint>").alias("steam").action(async ({ session }, id) => {
|
|
669
|
+
if (id == null) {
|
|
670
|
+
return session?.text(".null");
|
|
671
|
+
}
|
|
672
|
+
const steam = await getSteam(ctx, session, id);
|
|
673
|
+
if (steam["success"] == 0) {
|
|
674
|
+
return session?.text(".msg", steam);
|
|
675
|
+
} else {
|
|
676
|
+
return session?.text(".failed", steam);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
621
679
|
}
|
|
622
680
|
__name(apply, "apply");
|
|
623
681
|
// Annotate the CommonJS export names for ESM import in node:
|