koishi-plugin-gl-bot 0.0.11 → 0.0.12
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/gl/index.d.ts +36 -55
- package/lib/gl/index.js +4 -6
- package/lib/gl/queqiao.adapter.d.ts +11 -0
- package/lib/gl/queqiao.adapter.js +41 -0
- package/lib/mcsManager/api.d.ts +1 -0
- package/lib/mcsManager/api.js +13 -1
- package/lib/mcsManager/bot.d.ts +2 -2
- package/lib/mcsManager/bot.js +1 -0
- package/lib/mcsManager/commands/index.d.ts +1 -0
- package/lib/mcsManager/commands/index.js +3 -1
- package/lib/mcsManager/commands/mc/health.d.ts +16 -0
- package/lib/mcsManager/commands/mc/health.js +46 -0
- package/lib/mcsManager/commands/mc/list.d.ts +1 -0
- package/lib/mcsManager/commands/mc/list.js +21 -6
- package/lib/mcsManager/commands/mc/online.d.ts +6 -1
- package/lib/mcsManager/commands/mc/online.js +49 -12
- package/lib/mcsManager/config.d.ts +39 -0
- package/lib/mcsManager/config.js +21 -0
- package/lib/mcsManager/index.d.ts +32 -1
- package/lib/mcsManager/index.js +4 -1
- package/lib/mcsManager/type.d.ts +2 -0
- package/lib/queQiao/index.d.ts +47 -38
- package/lib/queQiao/index.js +82 -47
- package/lib/queQiao/locale/zh-CN.json +1 -1
- package/lib/queQiao/locale/zh-CN.yml +4 -4
- package/lib/queQiao/mcwss.d.ts +12 -9
- package/lib/queQiao/mcwss.js +34 -2
- package/lib/queQiao/values.js +2 -2
- package/lib/utils/game.mc.js +5 -4
- package/package.json +1 -1
- package/lib/constants/env.d.ts +0 -0
- package/lib/constants/env.js +0 -0
- package/lib/gl/index.type.d.ts +0 -0
- package/lib/gl/index.type.js +0 -0
- package/lib/mcsManager/commands/create.d.ts +0 -16
- package/lib/mcsManager/commands/create.js +0 -135
- package/lib/mcsManager/commands/list copy.d.ts +0 -13
- package/lib/mcsManager/commands/list copy.js +0 -34
- package/lib/mcsManager/commands/list.d.ts +0 -14
- package/lib/mcsManager/commands/list.js +0 -35
- package/lib/mcsManager/commands/mc/restart copy.d.ts +0 -15
- package/lib/mcsManager/commands/mc/restart copy.js +0 -62
- package/lib/mcsManager/commands/mc copy/create.d.ts +0 -16
- package/lib/mcsManager/commands/mc copy/create.js +0 -135
- package/lib/mcsManager/commands/mc copy/list.d.ts +0 -14
- package/lib/mcsManager/commands/mc copy/list.js +0 -35
- package/lib/mcsManager/commands/mc copy/restart.d.ts +0 -15
- package/lib/mcsManager/commands/mc copy/restart.js +0 -62
- package/lib/mcsManager/commands/mc copy/start.d.ts +0 -15
- package/lib/mcsManager/commands/mc copy/start.js +0 -54
- package/lib/mcsManager/commands/mc copy/stop.d.ts +0 -15
- package/lib/mcsManager/commands/mc copy/stop.js +0 -54
- package/lib/mcsManager/commands/restart.d.ts +0 -15
- package/lib/mcsManager/commands/restart.js +0 -62
- package/lib/mcsManager/commands/start copy.d.ts +0 -14
- package/lib/mcsManager/commands/start copy.js +0 -53
- package/lib/mcsManager/commands/start.d.ts +0 -15
- package/lib/mcsManager/commands/start.js +0 -54
- package/lib/mcsManager/commands/stop.d.ts +0 -15
- package/lib/mcsManager/commands/stop.js +0 -54
- package/lib/utils/file.download.d.ts +0 -47
- package/lib/utils/file.download.js +0 -142
- package/lib/utils/file.examples.d.ts +0 -12
- package/lib/utils/file.examples.js +0 -73
- package/lib/utils/napcat.file.d.ts +0 -63
- package/lib/utils/napcat.file.js +0 -133
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Session } from 'koishi';
|
|
2
|
-
/**
|
|
3
|
-
* NapCat 群文件下载工具
|
|
4
|
-
* 用于处理 NapCat OneBot 协议的群文件下载
|
|
5
|
-
*/
|
|
6
|
-
export declare class NapCatFileDownloader {
|
|
7
|
-
/**
|
|
8
|
-
* 获取群文件下载URL
|
|
9
|
-
* @param session Koishi Session 对象
|
|
10
|
-
* @param fileId 群文件ID
|
|
11
|
-
* @returns 文件下载URL或null
|
|
12
|
-
*/
|
|
13
|
-
static getGroupFileUrl(session: Session, fileId: string): Promise<string | null>;
|
|
14
|
-
/**
|
|
15
|
-
* 获取群文件信息
|
|
16
|
-
* @param session Koishi Session 对象
|
|
17
|
-
* @param fileId 群文件ID
|
|
18
|
-
* @returns 文件信息或null
|
|
19
|
-
*/
|
|
20
|
-
static getGroupFileInfo(session: Session, fileId: string): Promise<any | null>;
|
|
21
|
-
/**
|
|
22
|
-
* 下载群文件到内存
|
|
23
|
-
* @param session Koishi Session 对象
|
|
24
|
-
* @param fileId 群文件ID
|
|
25
|
-
* @param fileName 文件名(用于日志)
|
|
26
|
-
* @param ctx Koishi Context(用于HTTP请求)
|
|
27
|
-
* @returns 文件Buffer或null
|
|
28
|
-
*/
|
|
29
|
-
static downloadGroupFile(session: Session, fileId: string, fileName: string, ctx: any): Promise<Buffer | null>;
|
|
30
|
-
/**
|
|
31
|
-
* 保存群文件到本地
|
|
32
|
-
* @param session Koishi Session 对象
|
|
33
|
-
* @param fileId 群文件ID
|
|
34
|
-
* @param fileName 文件名
|
|
35
|
-
* @param savePath 保存路径
|
|
36
|
-
* @param ctx Koishi Context
|
|
37
|
-
* @returns 是否保存成功
|
|
38
|
-
*/
|
|
39
|
-
static saveGroupFile(session: Session, fileId: string, fileName: string, savePath: string, ctx: any): Promise<boolean>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* NapCat OneBot 协议相关的类型定义
|
|
43
|
-
*/
|
|
44
|
-
export interface NapCatFileInfo {
|
|
45
|
-
file_id: string;
|
|
46
|
-
file_name: string;
|
|
47
|
-
file_size: number;
|
|
48
|
-
busid: number;
|
|
49
|
-
upload_time: number;
|
|
50
|
-
dead_time: number;
|
|
51
|
-
modify_time: number;
|
|
52
|
-
download_times: number;
|
|
53
|
-
uploader: number;
|
|
54
|
-
uploader_name: string;
|
|
55
|
-
}
|
|
56
|
-
export interface NapCatFileUrlResponse {
|
|
57
|
-
url?: string;
|
|
58
|
-
file_url?: string;
|
|
59
|
-
data?: {
|
|
60
|
-
url?: string;
|
|
61
|
-
file_url?: string;
|
|
62
|
-
};
|
|
63
|
-
}
|
package/lib/utils/napcat.file.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NapCatFileDownloader = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* NapCat 群文件下载工具
|
|
6
|
-
* 用于处理 NapCat OneBot 协议的群文件下载
|
|
7
|
-
*/
|
|
8
|
-
class NapCatFileDownloader {
|
|
9
|
-
/**
|
|
10
|
-
* 获取群文件下载URL
|
|
11
|
-
* @param session Koishi Session 对象
|
|
12
|
-
* @param fileId 群文件ID
|
|
13
|
-
* @returns 文件下载URL或null
|
|
14
|
-
*/
|
|
15
|
-
static async getGroupFileUrl(session, fileId) {
|
|
16
|
-
try {
|
|
17
|
-
// 检查是否为 OneBot 平台且有内部API支持
|
|
18
|
-
if (session.platform !== 'onebot' || !session.bot?.internal) {
|
|
19
|
-
console.warn('当前平台不是 OneBot 或缺少内部API支持');
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
console.log(`尝试通过 NapCat API 获取群文件URL,群号: ${session.channelId}, 文件ID: ${fileId}`);
|
|
23
|
-
// 调用 NapCat 的 get_group_file_url API
|
|
24
|
-
const response = await session.bot.internal.getGroupFileUrl(session.channelId, // 群号
|
|
25
|
-
fileId);
|
|
26
|
-
console.log('NapCat API 响应:', JSON.stringify(response, null, 2));
|
|
27
|
-
// 不同版本的 NapCat 可能返回格式不同
|
|
28
|
-
const fileUrl = response?.url ||
|
|
29
|
-
response?.data?.url ||
|
|
30
|
-
response?.file_url ||
|
|
31
|
-
response?.data?.file_url;
|
|
32
|
-
if (fileUrl) {
|
|
33
|
-
console.log(`成功获取文件URL: ${fileUrl}`);
|
|
34
|
-
return fileUrl;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.warn('API响应中未找到有效的文件URL');
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error('获取群文件URL失败:', error);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 获取群文件信息
|
|
48
|
-
* @param session Koishi Session 对象
|
|
49
|
-
* @param fileId 群文件ID
|
|
50
|
-
* @returns 文件信息或null
|
|
51
|
-
*/
|
|
52
|
-
static async getGroupFileInfo(session, fileId) {
|
|
53
|
-
try {
|
|
54
|
-
if (session.platform !== 'onebot' || !session.bot?.internal) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
// 尝试获取文件信息(如果NapCat支持)
|
|
58
|
-
const response = await session.bot.internal.getGroupFileInfo?.(session.channelId, fileId);
|
|
59
|
-
return response?.data || response || null;
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
console.warn('获取群文件信息失败:', error);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 下载群文件到内存
|
|
68
|
-
* @param session Koishi Session 对象
|
|
69
|
-
* @param fileId 群文件ID
|
|
70
|
-
* @param fileName 文件名(用于日志)
|
|
71
|
-
* @param ctx Koishi Context(用于HTTP请求)
|
|
72
|
-
* @returns 文件Buffer或null
|
|
73
|
-
*/
|
|
74
|
-
static async downloadGroupFile(session, fileId, fileName, ctx) {
|
|
75
|
-
try {
|
|
76
|
-
// 获取文件下载URL
|
|
77
|
-
const fileUrl = await this.getGroupFileUrl(session, fileId);
|
|
78
|
-
if (!fileUrl) {
|
|
79
|
-
console.error(`无法获取文件 ${fileName} 的下载URL`);
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
console.log(`开始下载文件: ${fileName}`);
|
|
83
|
-
// 下载文件
|
|
84
|
-
const response = await ctx.http.get(fileUrl, {
|
|
85
|
-
responseType: 'arraybuffer',
|
|
86
|
-
timeout: 60000, // 60秒超时
|
|
87
|
-
headers: {
|
|
88
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
const buffer = Buffer.from(response);
|
|
92
|
-
console.log(`文件下载成功: ${fileName}, 大小: ${buffer.length} 字节`);
|
|
93
|
-
return buffer;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error(`下载文件 ${fileName} 失败:`, error);
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* 保存群文件到本地
|
|
102
|
-
* @param session Koishi Session 对象
|
|
103
|
-
* @param fileId 群文件ID
|
|
104
|
-
* @param fileName 文件名
|
|
105
|
-
* @param savePath 保存路径
|
|
106
|
-
* @param ctx Koishi Context
|
|
107
|
-
* @returns 是否保存成功
|
|
108
|
-
*/
|
|
109
|
-
static async saveGroupFile(session, fileId, fileName, savePath, ctx) {
|
|
110
|
-
try {
|
|
111
|
-
const buffer = await this.downloadGroupFile(session, fileId, fileName, ctx);
|
|
112
|
-
if (!buffer) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
// 确保目录存在
|
|
116
|
-
const fs = require('fs');
|
|
117
|
-
const path = require('path');
|
|
118
|
-
const dir = path.dirname(savePath);
|
|
119
|
-
if (!fs.existsSync(dir)) {
|
|
120
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
121
|
-
}
|
|
122
|
-
// 保存文件
|
|
123
|
-
fs.writeFileSync(savePath, buffer);
|
|
124
|
-
console.log(`文件保存成功: ${savePath}`);
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error(`保存文件失败:`, error);
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.NapCatFileDownloader = NapCatFileDownloader;
|