koishi-plugin-checkgal 1.6.3 → 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 CHANGED
@@ -13,23 +13,51 @@ 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 `未找到关于“${keyword}”的任何游戏。`;
16
+ return `未找到关于"${keyword}"的任何游戏。`;
17
17
  }
18
18
  // 缓存结果
19
19
  results.forEach(game => gameCache.set(game.id, game));
20
- for (const game of results) {
21
- const imageBuffer = await touchgal.downloadAndConvertImage(game.banner);
22
- const imageElement = imageBuffer
23
- ? koishi_1.h.image(imageBuffer, 'image/jpeg')
24
- : (0, koishi_1.h)('text', { content: '封面图加载失败' });
25
- const content = [
26
- imageElement,
27
- `ID: ${game.id}`,
28
- `名称: ${game.name}`,
29
- `平台: ${game.platform.join(', ')}`,
30
- `语言: ${game.language.join(', ')}`,
31
- ].join('\n');
32
- await session.send(content);
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
+ }
33
61
  }
34
62
  });
35
63
  ctx.command('下载gal <id:number>', '获取Galgame下载地址')
@@ -49,7 +77,7 @@ function apply(ctx, config, deps) {
49
77
  gameCache.set(id, gameInfo);
50
78
  }
51
79
  else {
52
- await session.send(`无法获取游戏“${id}”的详细信息,但仍会尝试获取下载链接...`);
80
+ await session.send(`无法获取游戏"${id}"的详细信息,但仍会尝试获取下载链接...`);
53
81
  }
54
82
  }
55
83
  const downloads = await touchgal.getDownloads(id);
@@ -58,24 +86,70 @@ function apply(ctx, config, deps) {
58
86
  }
59
87
  const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
60
88
  const imageBuffer = gameInfo ? await touchgal.downloadAndConvertImage(gameInfo.banner) : null;
61
- // 对于单条消息,直接发送 Buffer 是最高效的
62
- if (imageBuffer) {
63
- await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
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 }));
132
+ }
133
+ else {
134
+ // 普通发送方式
135
+ if (imageBuffer) {
136
+ await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
137
+ }
138
+ const header = [
139
+ gameTitle,
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}`;
64
153
  }
65
- const header = [
66
- gameTitle,
67
- `共找到 ${downloads.length} 个下载资源:`,
68
- ].filter(Boolean).join('\n');
69
- const downloadDetails = downloads.map(res => {
70
- return [
71
- `› 名称: ${res.name}`,
72
- ` 平台: ${res.platform.join(', ')} | 大小: ${res.size}`,
73
- ` 下载地址: ${res.content}`,
74
- ` 提取码: ${res.code || '无'}`,
75
- ` 解压码: ${res.password || '无'}`,
76
- ` 备注: ${res.note || '无'}`,
77
- ].join('\n');
78
- }).join('\n\n');
79
- return `${header}\n\n${downloadDetails}`;
80
154
  });
81
155
  }
package/lib/config.d.ts CHANGED
@@ -2,5 +2,6 @@ import { Schema } from 'koishi';
2
2
  export interface Config {
3
3
  searchLimit: number;
4
4
  enableNsfw: boolean;
5
+ isForward: boolean;
5
6
  }
6
7
  export declare const Config: Schema<Config>;
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-checkgal",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "scripts": {
5
5
  "build": "tsc"
6
6
  },
@@ -31,7 +31,7 @@
31
31
  ],
32
32
  "peerDependencies": {
33
33
  "koishi": "^4.18.9",
34
- "koishi-plugin-ffmpeg": ""
34
+ "koishi-plugin-ffmpeg": "^1.1.0"
35
35
  },
36
36
  "koishi": {
37
37
  "description": {
@@ -44,7 +44,8 @@
44
44
  }
45
45
  },
46
46
  "devDependencies": {
47
+ "koishi-plugin-ffmpeg": "^1.1.0",
47
48
  "typescript": "^5.4.0",
48
49
  "@types/node": "^18.0.0"
49
50
  }
50
- }
51
+ }