koishi-plugin-checkgal 1.6.4 → 1.6.5
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.js +102 -45
- package/lib/config.d.ts +1 -0
- package/lib/config.js +1 -0
- package/package.json +1 -1
package/lib/commands.js
CHANGED
|
@@ -17,24 +17,48 @@ function apply(ctx, config, deps) {
|
|
|
17
17
|
}
|
|
18
18
|
// 缓存结果
|
|
19
19
|
results.forEach(game => gameCache.set(game.id, game));
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
// 判断是否使用合并转发
|
|
21
|
+
if (config.isForward && (session.platform === 'onebot' || session.platform === 'red')) {
|
|
22
|
+
// 使用合并转发
|
|
23
|
+
const messageElements = [];
|
|
24
|
+
for (const game of results) {
|
|
25
|
+
const imageBuffer = await touchgal.downloadAndConvertImage(game.banner);
|
|
26
|
+
const imageElement = imageBuffer
|
|
27
|
+
? koishi_1.h.image(imageBuffer, 'image/jpeg')
|
|
28
|
+
: (0, koishi_1.h)('text', { content: '封面图加载失败' });
|
|
29
|
+
const content = [
|
|
30
|
+
imageElement,
|
|
31
|
+
`ID: ${game.id}`,
|
|
32
|
+
`名称: ${game.name}`,
|
|
33
|
+
`平台: ${game.platform.join(', ')}`,
|
|
34
|
+
`语言: ${game.language.join(', ')}`,
|
|
35
|
+
].join('\n');
|
|
36
|
+
// 包装成 message 元素
|
|
37
|
+
messageElements.push((0, koishi_1.h)('message', {
|
|
38
|
+
userId: session.userId,
|
|
39
|
+
nickname: session.author?.nickname || session.username,
|
|
40
|
+
}, koishi_1.h.parse(content)));
|
|
41
|
+
}
|
|
42
|
+
// 使用 figure 元素发送合并转发
|
|
43
|
+
await session.send((0, koishi_1.h)('figure', { children: messageElements }));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// 普通发送方式
|
|
47
|
+
for (const game of results) {
|
|
48
|
+
const imageBuffer = await touchgal.downloadAndConvertImage(game.banner);
|
|
49
|
+
const imageElement = imageBuffer
|
|
50
|
+
? koishi_1.h.image(imageBuffer, 'image/jpeg')
|
|
51
|
+
: (0, koishi_1.h)('text', { content: '封面图加载失败' });
|
|
52
|
+
const content = [
|
|
53
|
+
imageElement,
|
|
54
|
+
`ID: ${game.id}`,
|
|
55
|
+
`名称: ${game.name}`,
|
|
56
|
+
`平台: ${game.platform.join(', ')}`,
|
|
57
|
+
`语言: ${game.language.join(', ')}`,
|
|
58
|
+
].join('\n');
|
|
59
|
+
await session.send(content);
|
|
60
|
+
}
|
|
35
61
|
}
|
|
36
|
-
// 发送合并转发消息
|
|
37
|
-
await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
|
|
38
62
|
});
|
|
39
63
|
ctx.command('下载gal <id:number>', '获取Galgame下载地址')
|
|
40
64
|
.action(async ({ session }, id) => {
|
|
@@ -62,37 +86,70 @@ function apply(ctx, config, deps) {
|
|
|
62
86
|
}
|
|
63
87
|
const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
|
|
64
88
|
const imageBuffer = gameInfo ? await touchgal.downloadAndConvertImage(gameInfo.banner) : null;
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
// 判断是否使用合并转发
|
|
90
|
+
if (config.isForward && (session.platform === 'onebot' || session.platform === 'red')) {
|
|
91
|
+
// 使用合并转发
|
|
92
|
+
const messageElements = [];
|
|
93
|
+
// 第一条消息:游戏标题和封面
|
|
94
|
+
if (imageBuffer) {
|
|
95
|
+
const headerContent = [
|
|
96
|
+
koishi_1.h.image(imageBuffer, 'image/jpeg'),
|
|
97
|
+
gameTitle,
|
|
98
|
+
`共找到 ${downloads.length} 个下载资源`,
|
|
99
|
+
].join('\n');
|
|
100
|
+
messageElements.push((0, koishi_1.h)('message', {
|
|
101
|
+
userId: session.userId,
|
|
102
|
+
nickname: session.author?.nickname || session.username,
|
|
103
|
+
}, koishi_1.h.parse(headerContent)));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const headerContent = [
|
|
107
|
+
gameTitle,
|
|
108
|
+
`共找到 ${downloads.length} 个下载资源`,
|
|
109
|
+
].join('\n');
|
|
110
|
+
messageElements.push((0, koishi_1.h)('message', {
|
|
111
|
+
userId: session.userId,
|
|
112
|
+
nickname: session.author?.nickname || session.username,
|
|
113
|
+
}, koishi_1.h.parse(headerContent)));
|
|
114
|
+
}
|
|
115
|
+
// 后续消息:每个下载资源一条消息
|
|
116
|
+
for (const res of downloads) {
|
|
117
|
+
const resContent = [
|
|
118
|
+
`名称: ${res.name}`,
|
|
119
|
+
`平台: ${res.platform.join(', ')} | 大小: ${res.size}`,
|
|
120
|
+
`下载地址: ${res.content}`,
|
|
121
|
+
`提取码: ${res.code || '无'}`,
|
|
122
|
+
`解压码: ${res.password || '无'}`,
|
|
123
|
+
`备注: ${res.note || '无'}`,
|
|
124
|
+
].join('\n');
|
|
125
|
+
messageElements.push((0, koishi_1.h)('message', {
|
|
126
|
+
userId: session.userId,
|
|
127
|
+
nickname: session.author?.nickname || session.username,
|
|
128
|
+
}, resContent));
|
|
129
|
+
}
|
|
130
|
+
// 使用 figure 元素发送合并转发
|
|
131
|
+
await session.send((0, koishi_1.h)('figure', { children: messageElements }));
|
|
75
132
|
}
|
|
76
133
|
else {
|
|
77
|
-
|
|
134
|
+
// 普通发送方式
|
|
135
|
+
if (imageBuffer) {
|
|
136
|
+
await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
|
|
137
|
+
}
|
|
138
|
+
const header = [
|
|
78
139
|
gameTitle,
|
|
79
|
-
`共找到 ${downloads.length}
|
|
80
|
-
].join('\n');
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
].join('\n');
|
|
93
|
-
forwardMessages.push((0, koishi_1.h)('message', {}, resContent));
|
|
140
|
+
`共找到 ${downloads.length} 个下载资源:`,
|
|
141
|
+
].filter(Boolean).join('\n');
|
|
142
|
+
const downloadDetails = downloads.map(res => {
|
|
143
|
+
return [
|
|
144
|
+
`› 名称: ${res.name}`,
|
|
145
|
+
` 平台: ${res.platform.join(', ')} | 大小: ${res.size}`,
|
|
146
|
+
` 下载地址: ${res.content}`,
|
|
147
|
+
` 提取码: ${res.code || '无'}`,
|
|
148
|
+
` 解压码: ${res.password || '无'}`,
|
|
149
|
+
` 备注: ${res.note || '无'}`,
|
|
150
|
+
].join('\n');
|
|
151
|
+
}).join('\n\n');
|
|
152
|
+
return `${header}\n\n${downloadDetails}`;
|
|
94
153
|
}
|
|
95
|
-
// 发送合并转发消息
|
|
96
|
-
await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
|
|
97
154
|
});
|
|
98
155
|
}
|
package/lib/config.d.ts
CHANGED
package/lib/config.js
CHANGED
|
@@ -5,4 +5,5 @@ const koishi_1 = require("koishi");
|
|
|
5
5
|
exports.Config = koishi_1.Schema.object({
|
|
6
6
|
searchLimit: koishi_1.Schema.number().default(15).min(1).max(50).description('单次搜索返回的最大结果数量。'),
|
|
7
7
|
enableNsfw: koishi_1.Schema.boolean().default(false).description('是否允许搜索 NSFW 内容。'),
|
|
8
|
+
isForward: koishi_1.Schema.boolean().default(false).description('是否开启合并转发 `仅支持 onebot/red 适配器` 其他平台开启无效').experimental(),
|
|
8
9
|
});
|