koishi-plugin-checkgal 1.6.1 → 1.6.4
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/api.d.ts +0 -5
- package/lib/api.js +5 -7
- package/lib/commands.js +36 -19
- package/lib/index.js +1 -1
- package/package.json +6 -4
package/lib/api.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
2
|
import { GameInfo, DownloadResource } from './types';
|
|
3
3
|
import { Config } from './config';
|
|
4
|
-
declare module 'koishi' {
|
|
5
|
-
interface Context {
|
|
6
|
-
canvas: any;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
4
|
export declare class TouchGalAPI {
|
|
10
5
|
private http;
|
|
11
6
|
private logger;
|
package/lib/api.js
CHANGED
|
@@ -66,14 +66,12 @@ class TouchGalAPI {
|
|
|
66
66
|
const response = await this.http.get(url, {
|
|
67
67
|
responseType: 'arraybuffer',
|
|
68
68
|
});
|
|
69
|
-
if (!(response instanceof ArrayBuffer))
|
|
70
|
-
return null;
|
|
71
69
|
const imageBuffer = Buffer.from(response);
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
// 使用 ffmpeg 将图片转换为 jpeg
|
|
71
|
+
const jpegBuffer = await this.ctx.ffmpeg.builder()
|
|
72
|
+
.input(imageBuffer)
|
|
73
|
+
.outputOption('-f', 'mjpeg')
|
|
74
|
+
.run('buffer');
|
|
77
75
|
return jpegBuffer;
|
|
78
76
|
}
|
|
79
77
|
catch (error) {
|
package/lib/commands.js
CHANGED
|
@@ -13,10 +13,12 @@ function apply(ctx, config, deps) {
|
|
|
13
13
|
await session.send('正在查询,请稍候...');
|
|
14
14
|
const results = await touchgal.searchGame(keyword, config);
|
|
15
15
|
if (!results.length) {
|
|
16
|
-
return
|
|
16
|
+
return `未找到关于"${keyword}"的任何游戏。`;
|
|
17
17
|
}
|
|
18
18
|
// 缓存结果
|
|
19
19
|
results.forEach(game => gameCache.set(game.id, game));
|
|
20
|
+
// 构建合并转发消息
|
|
21
|
+
const forwardMessages = [];
|
|
20
22
|
for (const game of results) {
|
|
21
23
|
const imageBuffer = await touchgal.downloadAndConvertImage(game.banner);
|
|
22
24
|
const imageElement = imageBuffer
|
|
@@ -29,8 +31,10 @@ function apply(ctx, config, deps) {
|
|
|
29
31
|
`平台: ${game.platform.join(', ')}`,
|
|
30
32
|
`语言: ${game.language.join(', ')}`,
|
|
31
33
|
].join('\n');
|
|
32
|
-
|
|
34
|
+
forwardMessages.push((0, koishi_1.h)('message', {}, content));
|
|
33
35
|
}
|
|
36
|
+
// 发送合并转发消息
|
|
37
|
+
await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
|
|
34
38
|
});
|
|
35
39
|
ctx.command('下载gal <id:number>', '获取Galgame下载地址')
|
|
36
40
|
.action(async ({ session }, id) => {
|
|
@@ -49,7 +53,7 @@ function apply(ctx, config, deps) {
|
|
|
49
53
|
gameCache.set(id, gameInfo);
|
|
50
54
|
}
|
|
51
55
|
else {
|
|
52
|
-
await session.send(
|
|
56
|
+
await session.send(`无法获取游戏"${id}"的详细信息,但仍会尝试获取下载链接...`);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
const downloads = await touchgal.getDownloads(id);
|
|
@@ -58,24 +62,37 @@ function apply(ctx, config, deps) {
|
|
|
58
62
|
}
|
|
59
63
|
const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
|
|
60
64
|
const imageBuffer = gameInfo ? await touchgal.downloadAndConvertImage(gameInfo.banner) : null;
|
|
61
|
-
//
|
|
65
|
+
// 构建合并转发消息
|
|
66
|
+
const forwardMessages = [];
|
|
67
|
+
// 第一条消息:游戏标题和封面
|
|
62
68
|
if (imageBuffer) {
|
|
63
|
-
|
|
69
|
+
const headerContent = [
|
|
70
|
+
koishi_1.h.image(imageBuffer, 'image/jpeg'),
|
|
71
|
+
gameTitle,
|
|
72
|
+
`共找到 ${downloads.length} 个下载资源`,
|
|
73
|
+
].join('\n');
|
|
74
|
+
forwardMessages.push((0, koishi_1.h)('message', {}, headerContent));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const headerContent = [
|
|
78
|
+
gameTitle,
|
|
79
|
+
`共找到 ${downloads.length} 个下载资源`,
|
|
80
|
+
].join('\n');
|
|
81
|
+
forwardMessages.push((0, koishi_1.h)('message', {}, headerContent));
|
|
64
82
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
` 提取码: ${res.code || '无'}`,
|
|
75
|
-
` 解压码: ${res.password || '无'}`,
|
|
76
|
-
` 备注: ${res.note || '无'}`,
|
|
83
|
+
// 后续消息:每个下载资源一条消息
|
|
84
|
+
for (const res of downloads) {
|
|
85
|
+
const resContent = [
|
|
86
|
+
`名称: ${res.name}`,
|
|
87
|
+
`平台: ${res.platform.join(', ')} | 大小: ${res.size}`,
|
|
88
|
+
`下载地址: ${res.content}`,
|
|
89
|
+
`提取码: ${res.code || '无'}`,
|
|
90
|
+
`解压码: ${res.password || '无'}`,
|
|
91
|
+
`备注: ${res.note || '无'}`,
|
|
77
92
|
].join('\n');
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
forwardMessages.push((0, koishi_1.h)('message', {}, resContent));
|
|
94
|
+
}
|
|
95
|
+
// 发送合并转发消息
|
|
96
|
+
await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
|
|
80
97
|
});
|
|
81
98
|
}
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const api_1 = require("./api");
|
|
|
8
8
|
const cache_1 = require("./cache");
|
|
9
9
|
const commands_1 = require("./commands");
|
|
10
10
|
exports.name = 'checkgal';
|
|
11
|
-
exports.inject = ['
|
|
11
|
+
exports.inject = ['ffmpeg'];
|
|
12
12
|
function apply(ctx, config) {
|
|
13
13
|
// 初始化服务
|
|
14
14
|
const api = new api_1.TouchGalAPI(ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-checkgal",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.4",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsc"
|
|
6
6
|
},
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"galgame"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"koishi": "^4.18.9"
|
|
33
|
+
"koishi": "^4.18.9",
|
|
34
|
+
"koishi-plugin-ffmpeg": "^1.1.0"
|
|
34
35
|
},
|
|
35
36
|
"koishi": {
|
|
36
37
|
"description": {
|
|
@@ -38,12 +39,13 @@
|
|
|
38
39
|
},
|
|
39
40
|
"service": {
|
|
40
41
|
"required": [
|
|
41
|
-
"
|
|
42
|
+
"ffmpeg"
|
|
42
43
|
]
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
47
|
+
"koishi-plugin-ffmpeg": "^1.1.0",
|
|
46
48
|
"typescript": "^5.4.0",
|
|
47
49
|
"@types/node": "^18.0.0"
|
|
48
50
|
}
|
|
49
|
-
}
|
|
51
|
+
}
|