koishi-plugin-checkgal 1.1.1 → 1.2.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/api.js +3 -6
- package/lib/commands.js +16 -16
- package/package.json +4 -2
package/lib/api.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.TouchGalAPI = void 0;
|
|
7
|
-
const
|
|
4
|
+
const Jimp = require('jimp');
|
|
8
5
|
class TouchGalAPI {
|
|
9
6
|
constructor(ctx) {
|
|
10
7
|
this.http = ctx.http;
|
|
@@ -69,10 +66,10 @@ class TouchGalAPI {
|
|
|
69
66
|
const response = await this.http.get(url, {
|
|
70
67
|
responseType: 'arraybuffer',
|
|
71
68
|
});
|
|
72
|
-
// 类型守卫,确保 response 是 ArrayBuffer
|
|
73
69
|
if (!(response instanceof ArrayBuffer))
|
|
74
70
|
return null;
|
|
75
|
-
|
|
71
|
+
const image = await Jimp.read(Buffer.from(response));
|
|
72
|
+
return await image.getBufferAsync('image/jpeg');
|
|
76
73
|
}
|
|
77
74
|
catch (error) {
|
|
78
75
|
this.logger.error(`Failed to download or convert image from ${url}:`, error);
|
package/lib/commands.js
CHANGED
|
@@ -18,24 +18,25 @@ function apply(ctx, config) {
|
|
|
18
18
|
}
|
|
19
19
|
// 缓存结果
|
|
20
20
|
results.forEach(game => ctx.gameCache.set(game.id, game));
|
|
21
|
-
//
|
|
22
|
-
const
|
|
23
|
-
const forwardMessages = results.map((game, index) => {
|
|
24
|
-
const imagePath = imagePaths[index];
|
|
25
|
-
const imageElement = imagePath
|
|
26
|
-
? (0, koishi_1.h)('image', { url: `file://${imagePath}` })
|
|
27
|
-
: (0, koishi_1.h)('text', { content: '封面图加载失败' });
|
|
21
|
+
// 仅在合并转发中发送文本信息
|
|
22
|
+
const forwardMessages = results.map(game => {
|
|
28
23
|
const content = [
|
|
29
|
-
imageElement,
|
|
30
24
|
`ID: ${game.id}`,
|
|
31
25
|
`名称: ${game.name}`,
|
|
32
26
|
`平台: ${game.platform.join(', ')}`,
|
|
33
27
|
`语言: ${game.language.join(', ')}`,
|
|
34
28
|
].join('\n');
|
|
35
|
-
// 使用固定的机器人名称和 ID,避免 bot.username 可能不存在的问题
|
|
36
29
|
return (0, koishi_1.h)('message', { userId: session.bot.selfId, nickname: 'CheckGal Bot' }, content);
|
|
37
30
|
});
|
|
38
31
|
await session.send((0, koishi_1.h)('message', { forward: true }, forwardMessages));
|
|
32
|
+
await session.send('封面图将单独发送:');
|
|
33
|
+
// 单独逐张发送图片
|
|
34
|
+
for (const game of results) {
|
|
35
|
+
const imageBuffer = await ctx.touchgal.downloadAndConvertImage(game.banner);
|
|
36
|
+
if (imageBuffer) {
|
|
37
|
+
await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
39
40
|
});
|
|
40
41
|
ctx.command('下载gal <id:number>', '获取Galgame下载地址')
|
|
41
42
|
.action(async ({ session }, id) => {
|
|
@@ -44,7 +45,7 @@ function apply(ctx, config) {
|
|
|
44
45
|
if (!id)
|
|
45
46
|
return '请输入游戏ID。';
|
|
46
47
|
let gameInfo = ctx.gameCache.get(id);
|
|
47
|
-
//
|
|
48
|
+
// 如果缓存中没有,尝试重新获取
|
|
48
49
|
if (!gameInfo) {
|
|
49
50
|
await session.send('缓存中未找到该游戏信息,正在尝试重新搜索...');
|
|
50
51
|
const results = await ctx.touchgal.searchGame(String(id), config);
|
|
@@ -54,7 +55,6 @@ function apply(ctx, config) {
|
|
|
54
55
|
ctx.gameCache.set(id, gameInfo);
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
57
|
-
// 如果通过ID也搜不到,就直接获取下载链接
|
|
58
58
|
await session.send(`无法获取游戏“${id}”的详细信息,但仍会尝试获取下载链接...`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -63,12 +63,12 @@ function apply(ctx, config) {
|
|
|
63
63
|
return `未找到ID为 ${id} 的下载资源。`;
|
|
64
64
|
}
|
|
65
65
|
const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
const imageBuffer = gameInfo ? await ctx.touchgal.downloadAndConvertImage(gameInfo.banner) : null;
|
|
67
|
+
// 对于单条消息,直接发送 Buffer 是最高效的
|
|
68
|
+
if (imageBuffer) {
|
|
69
|
+
await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
|
|
70
|
+
}
|
|
70
71
|
const header = [
|
|
71
|
-
imageElement,
|
|
72
72
|
gameTitle,
|
|
73
73
|
`共找到 ${downloads.length} 个下载资源:`,
|
|
74
74
|
].filter(Boolean).join('\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-checkgal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "个人测试请勿使用",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"typescript": "^5.9.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"
|
|
29
|
+
"@jimp/core": "^1.6.0",
|
|
30
|
+
"@jimp/wasm-avif": "^1.6.0",
|
|
31
|
+
"jimp": "^1.6.0"
|
|
30
32
|
}
|
|
31
33
|
}
|