koishi-plugin-node-async-bot-all 2.19.0 → 2.20.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/fun.d.ts +1 -0
- package/lib/index.js +93 -12
- package/package.json +1 -1
- package/res/userCard.html +1 -1
- package/res/userMsg.html +75 -0
package/lib/commands.d.ts
CHANGED
|
@@ -33,3 +33,4 @@ export declare function serverTest(ctx: Context, session: Session): Promise<Obje
|
|
|
33
33
|
export declare function getMeme(ctx: Context, session: Session, count: number): Promise<Number>;
|
|
34
34
|
export declare function getCat(ctx: Context, session: Session): Promise<Number>;
|
|
35
35
|
export declare function getQQInfo(ctx: Context, session: Session, qq: string): Promise<number>;
|
|
36
|
+
export declare function getMsg(ctx: Context, session: Session): Promise<number>;
|
package/lib/fun.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export declare function hostPing(host: string): Promise<{
|
|
|
16
16
|
export declare function random(type: number | undefined, data: any, data2?: any): number;
|
|
17
17
|
export declare function request<T = any>(url: string, options?: RequestInit, timeout?: number, log?: any): Promise<HttpResponse<T>>;
|
|
18
18
|
export declare function readUserCardFile(userInfo: APIUserInfo): Promise<string>;
|
|
19
|
+
export declare function readUserMsgFile(userName: string, userAvatar: string, msg: string): 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: "执行错误。", 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 号不正确。" } } } };
|
|
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 号不正确。" } }, msg2img: { description: "引用一个消息并使用此指令,即可将消息转图。", messages: { msg: "{quote}{image}", failed: "{quote}{time}\n获取失败:{data}", null: "未引用任何消息。" } } } };
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -269,6 +269,18 @@ async function readUserCardFile(userInfo) {
|
|
|
269
269
|
return card;
|
|
270
270
|
}
|
|
271
271
|
__name(readUserCardFile, "readUserCardFile");
|
|
272
|
+
async function readUserMsgFile(userName, userAvatar, msg) {
|
|
273
|
+
let html;
|
|
274
|
+
try {
|
|
275
|
+
const aPath = import_path.default.resolve(__dirname, "..") + import_path.default.sep + "res" + import_path.default.sep + "userMsg.html";
|
|
276
|
+
html = await import_fs.default.promises.readFile(aPath, "utf8");
|
|
277
|
+
html = html.toString().replace("{userData.avatarUrl}", userAvatar).replace("{userData.username}", userName).replace("{userData.message}", msg);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
html = error.message;
|
|
280
|
+
}
|
|
281
|
+
return html;
|
|
282
|
+
}
|
|
283
|
+
__name(readUserMsgFile, "readUserMsgFile");
|
|
272
284
|
|
|
273
285
|
// src/commands.ts
|
|
274
286
|
async function getServer(ctx, session) {
|
|
@@ -463,7 +475,7 @@ async function getRandomWord(ctx, session) {
|
|
|
463
475
|
if (response.success) {
|
|
464
476
|
msg = {
|
|
465
477
|
"time": time,
|
|
466
|
-
"data": response.data,
|
|
478
|
+
"data": response.data.data,
|
|
467
479
|
"success": 0
|
|
468
480
|
};
|
|
469
481
|
log.debug("Sent:");
|
|
@@ -634,15 +646,27 @@ async function getQQInfo(ctx, session, qq) {
|
|
|
634
646
|
if (response.success) {
|
|
635
647
|
const fullHtml = await readUserCardFile(response.data);
|
|
636
648
|
const page = await ctx.puppeteer.page();
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
649
|
+
try {
|
|
650
|
+
await page.setViewport({
|
|
651
|
+
width: 450,
|
|
652
|
+
height: 650,
|
|
653
|
+
deviceScaleFactor: 2
|
|
654
|
+
});
|
|
655
|
+
await page.setContent(fullHtml, { waitUntil: "networkidle0" });
|
|
656
|
+
const { width, height } = await page.evaluate(() => ({
|
|
657
|
+
width: document.body.scrollWidth,
|
|
658
|
+
height: document.body.scrollHeight
|
|
659
|
+
}));
|
|
660
|
+
await page.setViewport({ width, height, deviceScaleFactor: 2 });
|
|
661
|
+
const image = await page.screenshot({ type: "png", omitBackground: true });
|
|
662
|
+
await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(image, "image/png") }));
|
|
663
|
+
} catch (err) {
|
|
664
|
+
await session.send(session.text(".failed", { "quote": import_koishi2.h.quote(session.messageId), "time": time, "data": "图片渲染失败" }));
|
|
665
|
+
log.error("图片渲染失败:", err);
|
|
666
|
+
return 1;
|
|
667
|
+
} finally {
|
|
668
|
+
if (page && !page.isClosed()) await page.close();
|
|
669
|
+
}
|
|
646
670
|
log.debug("Sent: Image");
|
|
647
671
|
} else {
|
|
648
672
|
if (response.code) {
|
|
@@ -658,9 +682,63 @@ async function getQQInfo(ctx, session, qq) {
|
|
|
658
682
|
return 0;
|
|
659
683
|
}
|
|
660
684
|
__name(getQQInfo, "getQQInfo");
|
|
685
|
+
async function getMsg(ctx, session) {
|
|
686
|
+
const log = ctx.logger("getQQInfo");
|
|
687
|
+
log.debug(`Got: {"form":"${session.event.guild?.id}","user":"${session.event.user?.id}","timestamp":${session.event.timestamp},"messageId":"${session.event.message?.id}"}`);
|
|
688
|
+
const time = getHongKongTime();
|
|
689
|
+
if (!session.quote || !session.quote.user) {
|
|
690
|
+
await session.send(session.text(".null"));
|
|
691
|
+
log.warn("未引用任何信息");
|
|
692
|
+
return 1;
|
|
693
|
+
}
|
|
694
|
+
const user = await session.bot.getUser(session.quote.user.id, session.channelId);
|
|
695
|
+
const msg = session.quote.content;
|
|
696
|
+
if (!user.name || !user.avatar) {
|
|
697
|
+
await session.send(session.text(".failed", { "quote": import_koishi2.h.quote(session.messageId), "time": time, "data": "获取用户信息失败。" }));
|
|
698
|
+
log.error("获取用户信息失败");
|
|
699
|
+
return 1;
|
|
700
|
+
}
|
|
701
|
+
const page = await ctx.puppeteer.page();
|
|
702
|
+
const html = await readUserMsgFile(user.name, user.avatar, msg);
|
|
703
|
+
try {
|
|
704
|
+
await page.setViewport({
|
|
705
|
+
width: 450,
|
|
706
|
+
height: 1,
|
|
707
|
+
deviceScaleFactor: 2
|
|
708
|
+
});
|
|
709
|
+
await page.setContent(html, { waitUntil: "networkidle0" });
|
|
710
|
+
const { width, height } = await page.evaluate(() => ({
|
|
711
|
+
width: document.body.scrollWidth + 50,
|
|
712
|
+
height: document.body.scrollHeight
|
|
713
|
+
}));
|
|
714
|
+
await page.setViewport({ width, height, deviceScaleFactor: 2 });
|
|
715
|
+
const element = await page.$("#target-element");
|
|
716
|
+
if (element) {
|
|
717
|
+
const image = await element.screenshot({
|
|
718
|
+
type: "png",
|
|
719
|
+
omitBackground: true
|
|
720
|
+
// 使得 CSS 中未定义的背景部分透明
|
|
721
|
+
});
|
|
722
|
+
await session.send(session.text(".msg", { "quote": import_koishi2.h.quote(session.messageId), "image": import_koishi2.h.image(image, "image/png") }));
|
|
723
|
+
log.debug("Sent: Image");
|
|
724
|
+
} else {
|
|
725
|
+
await session.send(session.text(".failed", { "quote": import_koishi2.h.quote(session.messageId), "time": time, "data": "未找到目标元素。" }));
|
|
726
|
+
log.error("未找到目标元素");
|
|
727
|
+
return 1;
|
|
728
|
+
}
|
|
729
|
+
} catch (err) {
|
|
730
|
+
await session.send(session.text(".failed", { "quote": import_koishi2.h.quote(session.messageId), "time": time, "data": "图片渲染失败" }));
|
|
731
|
+
log.error("图片渲染失败:", err);
|
|
732
|
+
return 1;
|
|
733
|
+
} finally {
|
|
734
|
+
if (page && !page.isClosed()) await page.close();
|
|
735
|
+
}
|
|
736
|
+
return 0;
|
|
737
|
+
}
|
|
738
|
+
__name(getMsg, "getMsg");
|
|
661
739
|
|
|
662
740
|
// package.json
|
|
663
|
-
var version = "2.
|
|
741
|
+
var version = "2.20.1";
|
|
664
742
|
|
|
665
743
|
// src/index.ts
|
|
666
744
|
var inject = ["database", "installer", "puppeteer"];
|
|
@@ -776,6 +854,9 @@ function apply(ctx) {
|
|
|
776
854
|
if (qq == void 0 || isNaN(Number(qq))) return session?.text(".command");
|
|
777
855
|
await getQQInfo(ctx, session, qq);
|
|
778
856
|
});
|
|
857
|
+
ctx.command("msg2img").alias("消息转图").alias("m").action(async ({ session }) => {
|
|
858
|
+
await getMsg(ctx, session);
|
|
859
|
+
});
|
|
779
860
|
}
|
|
780
861
|
__name(apply, "apply");
|
|
781
862
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/res/userCard.html
CHANGED
package/res/userMsg.html
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>UserMsg</title>
|
|
6
|
+
<style>
|
|
7
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
8
|
+
|
|
9
|
+
body {
|
|
10
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
11
|
+
background: transparent;
|
|
12
|
+
padding: 20px; /* 给截图留一点边缘留白 */
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* 核心容器 */
|
|
16
|
+
.message-card {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: row;
|
|
19
|
+
align-items: flex-start;
|
|
20
|
+
width: 100%;
|
|
21
|
+
background: #ffffff;
|
|
22
|
+
padding: 15px;
|
|
23
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* 头像样式 */
|
|
27
|
+
.avatar {
|
|
28
|
+
width: 50px;
|
|
29
|
+
height: 50px;
|
|
30
|
+
border-radius: 50%;
|
|
31
|
+
object-fit: cover;
|
|
32
|
+
flex-shrink: 0; /* 防止被长文本挤压变形 */
|
|
33
|
+
margin-right: 15px;
|
|
34
|
+
border: 1px solid #eee;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* 消息气泡样式 */
|
|
38
|
+
.content {
|
|
39
|
+
flex: 1;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-direction: column;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.user-name {
|
|
45
|
+
font-weight: bold;
|
|
46
|
+
font-size: 14px;
|
|
47
|
+
color: #333;
|
|
48
|
+
margin-bottom: 4px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.text-bubble {
|
|
52
|
+
font-size: 15px;
|
|
53
|
+
line-height: 1.5;
|
|
54
|
+
color: #444;
|
|
55
|
+
background: #f2f3f5;
|
|
56
|
+
padding: 10px 14px;
|
|
57
|
+
border-radius: 0 12px 12px 12px; /* 类似聊天气泡的圆角 */
|
|
58
|
+
|
|
59
|
+
white-space: pre-wrap; /* 保留换行符 */
|
|
60
|
+
word-wrap: break-word; /* 长单词断行 */
|
|
61
|
+
overflow-wrap: break-word;
|
|
62
|
+
word-break: break-all;
|
|
63
|
+
}
|
|
64
|
+
</style>
|
|
65
|
+
</head>
|
|
66
|
+
<body>
|
|
67
|
+
<div id="target-element" class="message-card">
|
|
68
|
+
<img src="{userData.avatarUrl}" class="avatar" />
|
|
69
|
+
<div class="content">
|
|
70
|
+
<div class="user-name">{userData.username}</div>
|
|
71
|
+
<div class="text-bubble">{userData.message}</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</body>
|
|
75
|
+
</html>
|