koishi-plugin-checkgal 1.4.4 → 1.4.6
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 +5 -7
- package/lib/commands.js +10 -11
- package/lib/index.js +2 -5
- package/package.json +31 -31
package/lib/commands.d.ts
CHANGED
|
@@ -2,11 +2,9 @@ import { Context } from 'koishi';
|
|
|
2
2
|
import { Config } from './config';
|
|
3
3
|
import { TouchGalAPI } from './api';
|
|
4
4
|
import { GameCache } from './cache';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
gameCache: GameCache;
|
|
9
|
-
}
|
|
5
|
+
interface Dependencies {
|
|
6
|
+
touchgal: TouchGalAPI;
|
|
7
|
+
gameCache: GameCache;
|
|
10
8
|
}
|
|
11
|
-
export declare
|
|
12
|
-
export
|
|
9
|
+
export declare function apply(ctx: Context, config: Config, deps: Dependencies): void;
|
|
10
|
+
export {};
|
package/lib/commands.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inject = void 0;
|
|
4
3
|
exports.apply = apply;
|
|
5
4
|
const koishi_1 = require("koishi");
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function apply(ctx, config, deps) {
|
|
6
|
+
const { touchgal, gameCache } = deps;
|
|
8
7
|
ctx.command('查询gal <keyword:text>', '查询Galgame信息')
|
|
9
8
|
.action(async ({ session }, keyword) => {
|
|
10
9
|
if (!session)
|
|
@@ -12,14 +11,14 @@ function apply(ctx, config) {
|
|
|
12
11
|
if (!keyword)
|
|
13
12
|
return '请输入要查询的游戏名。';
|
|
14
13
|
await session.send('正在查询,请稍候...');
|
|
15
|
-
const results = await
|
|
14
|
+
const results = await touchgal.searchGame(keyword, config);
|
|
16
15
|
if (!results.length) {
|
|
17
16
|
return `未找到关于“${keyword}”的任何游戏。`;
|
|
18
17
|
}
|
|
19
18
|
// 缓存结果
|
|
20
|
-
results.forEach(game =>
|
|
19
|
+
results.forEach(game => gameCache.set(game.id, game));
|
|
21
20
|
for (const game of results) {
|
|
22
|
-
const imageBuffer = await
|
|
21
|
+
const imageBuffer = await touchgal.downloadAndConvertImage(game.banner);
|
|
23
22
|
const imageElement = imageBuffer
|
|
24
23
|
? koishi_1.h.image(imageBuffer, 'image/jpeg')
|
|
25
24
|
: (0, koishi_1.h)('text', { content: '封面图加载失败' });
|
|
@@ -39,26 +38,26 @@ function apply(ctx, config) {
|
|
|
39
38
|
return '该指令只能在聊天环境中使用。';
|
|
40
39
|
if (!id)
|
|
41
40
|
return '请输入游戏ID。';
|
|
42
|
-
let gameInfo =
|
|
41
|
+
let gameInfo = gameCache.get(id);
|
|
43
42
|
// 如果缓存中没有,尝试重新获取
|
|
44
43
|
if (!gameInfo) {
|
|
45
44
|
await session.send('缓存中未找到该游戏信息,正在尝试重新搜索...');
|
|
46
|
-
const results = await
|
|
45
|
+
const results = await touchgal.searchGame(String(id), config);
|
|
47
46
|
const foundGame = results.find(g => g.id === id);
|
|
48
47
|
if (foundGame) {
|
|
49
48
|
gameInfo = foundGame;
|
|
50
|
-
|
|
49
|
+
gameCache.set(id, gameInfo);
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
52
|
await session.send(`无法获取游戏“${id}”的详细信息,但仍会尝试获取下载链接...`);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
|
-
const downloads = await
|
|
55
|
+
const downloads = await touchgal.getDownloads(id);
|
|
57
56
|
if (!downloads.length) {
|
|
58
57
|
return `未找到ID为 ${id} 的下载资源。`;
|
|
59
58
|
}
|
|
60
59
|
const gameTitle = gameInfo ? `游戏: ${gameInfo.name} (ID: ${id})` : `游戏ID: ${id}`;
|
|
61
|
-
const imageBuffer = gameInfo ? await
|
|
60
|
+
const imageBuffer = gameInfo ? await touchgal.downloadAndConvertImage(gameInfo.banner) : null;
|
|
62
61
|
// 对于单条消息,直接发送 Buffer 是最高效的
|
|
63
62
|
if (imageBuffer) {
|
|
64
63
|
await session.send(koishi_1.h.image(imageBuffer, 'image/jpeg'));
|
package/lib/index.js
CHANGED
|
@@ -12,11 +12,8 @@ function apply(ctx, config) {
|
|
|
12
12
|
// 初始化服务
|
|
13
13
|
const api = new api_1.TouchGalAPI(ctx);
|
|
14
14
|
const cache = new cache_1.GameCache();
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
ctx.provide('gameCache', cache);
|
|
18
|
-
// 注册指令
|
|
19
|
-
ctx.plugin(commands_1.apply, config);
|
|
15
|
+
// 注册指令,并将 api 和 cache 作为依赖传入
|
|
16
|
+
(0, commands_1.apply)(ctx, config, { touchgal: api, gameCache: cache });
|
|
20
17
|
// 在插件停用时清理缓存
|
|
21
18
|
ctx.on('dispose', () => {
|
|
22
19
|
cache.clear();
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "koishi-plugin-checkgal",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"typings": "lib/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"lib"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "node --max-old-space-size=4096 ./node_modules/typescript/bin/tsc"
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"chatbot",
|
|
15
|
-
"koishi",
|
|
16
|
-
"plugin",
|
|
17
|
-
"galgame"
|
|
18
|
-
],
|
|
19
|
-
"author": "
|
|
20
|
-
"license": "AGPL-3.0",
|
|
21
|
-
"koishi": {
|
|
22
|
-
"name": "checkgal"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"koishi": "^4.18.9",
|
|
26
|
-
"typescript": "^5.9.3"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"sharp": "^0.34.4"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-checkgal",
|
|
3
|
+
"version": "1.4.6",
|
|
4
|
+
"description": "基于TouchGal API的Galgame信息查询与下载插件",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "node --max-old-space-size=4096 ./node_modules/typescript/bin/tsc"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"chatbot",
|
|
15
|
+
"koishi",
|
|
16
|
+
"plugin",
|
|
17
|
+
"galgame"
|
|
18
|
+
],
|
|
19
|
+
"author": "lumiawang",
|
|
20
|
+
"license": "AGPL-3.0",
|
|
21
|
+
"koishi": {
|
|
22
|
+
"name": "checkgal"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"koishi": "^4.18.9",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"sharp": "^0.34.4"
|
|
30
|
+
}
|
|
31
|
+
}
|