koishi-plugin-gl-bot 0.0.9 → 0.0.11
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/constants/env.d.ts +0 -0
- package/lib/constants/env.js +0 -0
- package/lib/gl/index.d.ts +9 -0
- package/lib/gl/index.js +9 -2
- package/lib/gl/index.type.d.ts +0 -0
- package/lib/gl/index.type.js +0 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
- package/lib/mcsManager/api.d.ts +18 -3
- package/lib/mcsManager/api.js +157 -7
- package/lib/mcsManager/bot.d.ts +5 -3
- package/lib/mcsManager/bot.js +18 -10
- package/lib/mcsManager/commands/ark/create.d.ts +15 -0
- package/lib/mcsManager/commands/ark/create.js +66 -0
- package/lib/mcsManager/commands/ark/list.d.ts +14 -0
- package/lib/mcsManager/commands/ark/list.js +35 -0
- package/lib/mcsManager/commands/ark/restart.d.ts +15 -0
- package/lib/mcsManager/commands/ark/restart.js +62 -0
- package/lib/mcsManager/commands/ark/start.d.ts +15 -0
- package/lib/mcsManager/commands/ark/start.js +54 -0
- package/lib/mcsManager/commands/ark/stop.d.ts +15 -0
- package/lib/mcsManager/commands/ark/stop.js +54 -0
- package/lib/mcsManager/commands/base.d.ts +20 -1
- package/lib/mcsManager/commands/base.js +41 -3
- package/lib/mcsManager/commands/create.d.ts +16 -0
- package/lib/mcsManager/commands/create.js +135 -0
- package/lib/mcsManager/commands/index.d.ts +10 -7
- package/lib/mcsManager/commands/index.js +22 -11
- package/lib/mcsManager/commands/list copy.d.ts +13 -0
- package/lib/mcsManager/commands/list copy.js +34 -0
- package/lib/mcsManager/commands/list.d.ts +14 -0
- package/lib/mcsManager/commands/list.js +35 -0
- package/lib/mcsManager/commands/mc/create.d.ts +15 -0
- package/lib/mcsManager/commands/mc/create.js +79 -0
- package/lib/mcsManager/commands/mc/list.d.ts +14 -0
- package/lib/mcsManager/commands/mc/list.js +39 -0
- package/lib/mcsManager/commands/mc/online.d.ts +24 -0
- package/lib/mcsManager/commands/mc/online.js +112 -0
- package/lib/mcsManager/commands/mc/restart copy.d.ts +15 -0
- package/lib/mcsManager/commands/mc/restart copy.js +62 -0
- package/lib/mcsManager/commands/mc/restart.d.ts +15 -0
- package/lib/mcsManager/commands/mc/restart.js +62 -0
- package/lib/mcsManager/commands/mc/start.d.ts +15 -0
- package/lib/mcsManager/commands/mc/start.js +54 -0
- package/lib/mcsManager/commands/mc/stop.d.ts +15 -0
- package/lib/mcsManager/commands/mc/stop.js +54 -0
- package/lib/mcsManager/commands/mc copy/create.d.ts +16 -0
- package/lib/mcsManager/commands/mc copy/create.js +135 -0
- package/lib/mcsManager/commands/mc copy/list.d.ts +14 -0
- package/lib/mcsManager/commands/mc copy/list.js +35 -0
- package/lib/mcsManager/commands/mc copy/restart.d.ts +15 -0
- package/lib/mcsManager/commands/mc copy/restart.js +62 -0
- package/lib/mcsManager/commands/mc copy/start.d.ts +15 -0
- package/lib/mcsManager/commands/mc copy/start.js +54 -0
- package/lib/mcsManager/commands/mc copy/stop.d.ts +15 -0
- package/lib/mcsManager/commands/mc copy/stop.js +54 -0
- package/lib/mcsManager/commands/restart.d.ts +15 -0
- package/lib/mcsManager/commands/restart.js +62 -0
- package/lib/mcsManager/commands/start copy.d.ts +14 -0
- package/lib/mcsManager/commands/{reset.js → start copy.js } +23 -15
- package/lib/mcsManager/commands/start.d.ts +15 -0
- package/lib/mcsManager/commands/start.js +54 -0
- package/lib/mcsManager/commands/stop.d.ts +15 -0
- package/lib/mcsManager/commands/stop.js +54 -0
- package/lib/mcsManager/constants.d.ts +4 -0
- package/lib/mcsManager/constants.js +4 -0
- package/lib/mcsManager/index.d.ts +4 -3
- package/lib/mcsManager/index.js +5 -2
- package/lib/mcsManager/instance.d.ts +3 -1
- package/lib/mcsManager/instance.js +8 -2
- package/lib/mcsManager/json/createInstanceUpload.json +49 -0
- package/lib/mcsManager/panel.d.ts +1 -1
- package/lib/mcsManager/panel.js +7 -5
- package/lib/mcsManager/schedules/index.d.ts +8 -0
- package/lib/mcsManager/schedules/index.js +41 -0
- package/lib/mcsManager/schedules/mc.schedule.d.ts +11 -0
- package/lib/mcsManager/schedules/mc.schedule.js +15 -0
- package/lib/mcsManager/type.d.ts +102 -0
- package/lib/mcsManager/ws.js +6 -6
- package/lib/napCat/api.d.ts +21 -0
- package/lib/napCat/api.js +43 -0
- package/lib/napCat/config.d.ts +10 -0
- package/lib/napCat/config.js +16 -0
- package/lib/napCat/index.d.ts +16 -0
- package/lib/napCat/index.js +15 -0
- package/lib/queQiao/index.d.ts +1 -0
- package/lib/queQiao/index.js +70 -3
- package/lib/queQiao/locale/en-US.yml +9 -9
- package/lib/queQiao/locale/zh-CN.json +1 -1
- package/lib/queQiao/locale/zh-CN.yml +9 -9
- package/lib/utils/file.download.d.ts +47 -0
- package/lib/utils/file.download.js +142 -0
- package/lib/utils/file.examples.d.ts +12 -0
- package/lib/utils/file.examples.js +73 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +58 -0
- package/lib/utils/napcat.file.d.ts +63 -0
- package/lib/utils/napcat.file.js +133 -0
- package/package.json +4 -3
- package/lib/mcsManager/commands/reset.d.ts +0 -12
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARKBotStartCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
const tempSelections = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* 服务器启动指令
|
|
10
|
+
*
|
|
11
|
+
* @example 服务器 启动 神话
|
|
12
|
+
*/
|
|
13
|
+
class ARKBotStartCommand extends base_1.BotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = ['方舟.启动 <name...>', 'ARK.启动 <name...>'];
|
|
18
|
+
this.roles = [base_1.BotCommandRole.All];
|
|
19
|
+
this.initialize();
|
|
20
|
+
}
|
|
21
|
+
async handle({ session }, args) {
|
|
22
|
+
let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
|
|
23
|
+
let selectIndex = -1;
|
|
24
|
+
const userId = Number(session.event.user.id);
|
|
25
|
+
// 溯源前搜索项
|
|
26
|
+
if (tempSelections.has(userId) && !isNaN(Number(name))) {
|
|
27
|
+
selectIndex = Number(name) - 1;
|
|
28
|
+
name = tempSelections.get(userId);
|
|
29
|
+
}
|
|
30
|
+
tempSelections.delete(userId);
|
|
31
|
+
const nameInstances = await this.bot.panel.searchInstanceByName(name);
|
|
32
|
+
if (nameInstances.length === 0) {
|
|
33
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
34
|
+
}
|
|
35
|
+
if (nameInstances.length > 1 && selectIndex === -1) {
|
|
36
|
+
tempSelections.set(userId, name);
|
|
37
|
+
return `请输入序号以选择:\n\n${nameInstances
|
|
38
|
+
.map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
|
|
39
|
+
.join('\n')}\n ==== 例如发送: (服务器 启动 1) ====`;
|
|
40
|
+
}
|
|
41
|
+
const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
|
|
42
|
+
if (!targetInstance || !targetInstance.instance) {
|
|
43
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
44
|
+
}
|
|
45
|
+
const { cfg } = targetInstance.instance;
|
|
46
|
+
if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.STOPPED)) {
|
|
47
|
+
await targetInstance.instance.startInstance();
|
|
48
|
+
this.bot.panel.handleRemoteServices();
|
|
49
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
|
|
50
|
+
}
|
|
51
|
+
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行启动操作`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ARKBotStartCommand = ARKBotStartCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../../bot';
|
|
3
|
+
import { BotCommandBase, BotCommandRole } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器关闭指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 关闭 神话
|
|
8
|
+
*/
|
|
9
|
+
export declare class ARKBotStopCommand extends BotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: BotCommandRole[];
|
|
13
|
+
constructor(bot: MCSManagerBot);
|
|
14
|
+
handle({ session }: Argv, args: string[]): Promise<string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARKBotStopCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
const tempSelections = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* 服务器关闭指令
|
|
10
|
+
*
|
|
11
|
+
* @example 服务器 关闭 神话
|
|
12
|
+
*/
|
|
13
|
+
class ARKBotStopCommand extends base_1.BotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = ['方舟.关闭 <name...>', 'ARK.关闭 <name...>'];
|
|
18
|
+
this.roles = [base_1.BotCommandRole.All];
|
|
19
|
+
this.initialize();
|
|
20
|
+
}
|
|
21
|
+
async handle({ session }, args) {
|
|
22
|
+
let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
|
|
23
|
+
let selectIndex = -1;
|
|
24
|
+
const userId = Number(session.event.user.id);
|
|
25
|
+
// 溯源前搜索项
|
|
26
|
+
if (tempSelections.has(userId) && !isNaN(Number(name))) {
|
|
27
|
+
selectIndex = Number(name) - 1;
|
|
28
|
+
name = tempSelections.get(userId);
|
|
29
|
+
}
|
|
30
|
+
tempSelections.delete(userId);
|
|
31
|
+
const nameInstances = await this.bot.panel.searchInstanceByName(name);
|
|
32
|
+
if (nameInstances.length === 0) {
|
|
33
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
34
|
+
}
|
|
35
|
+
if (nameInstances.length > 1 && selectIndex === -1) {
|
|
36
|
+
tempSelections.set(userId, name);
|
|
37
|
+
return `请输入序号以选择:\n\n${nameInstances
|
|
38
|
+
.map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
|
|
39
|
+
.join('\n')}\n ==== 例如发送: (服务器 关闭 1) ====`;
|
|
40
|
+
}
|
|
41
|
+
const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
|
|
42
|
+
if (!targetInstance || !targetInstance.instance) {
|
|
43
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
44
|
+
}
|
|
45
|
+
const { cfg } = targetInstance.instance;
|
|
46
|
+
if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.RUNNING)) {
|
|
47
|
+
await targetInstance.instance.stopInstance();
|
|
48
|
+
this.bot.panel.handleRemoteServices();
|
|
49
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送关闭操作`;
|
|
50
|
+
}
|
|
51
|
+
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行关闭操作`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ARKBotStopCommand = ARKBotStopCommand;
|
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../bot';
|
|
3
|
+
export declare enum BotCommandRole {
|
|
4
|
+
/** 群主 */
|
|
5
|
+
Owner = "owner",
|
|
6
|
+
/** 管理员 */
|
|
7
|
+
Admin = "admin",
|
|
8
|
+
/** 成员 */
|
|
9
|
+
Member = "member",
|
|
10
|
+
/** 所有人 */
|
|
11
|
+
All = "all"
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class BotCommandBase {
|
|
14
|
+
readonly bot: MCSManagerBot;
|
|
15
|
+
abstract command: string[];
|
|
16
|
+
abstract roles: BotCommandRole[];
|
|
17
|
+
constructor(bot: MCSManagerBot);
|
|
18
|
+
protected initialize(): void;
|
|
19
|
+
private authenticate;
|
|
20
|
+
abstract handle?(cmd: Argv, args: string[]): Promise<string>;
|
|
2
21
|
}
|
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.BotCommandBase = exports.BotCommandRole = void 0;
|
|
4
|
+
const koishi_1 = require("koishi");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const logger = new koishi_1.Logger('mcsmanager-command');
|
|
7
|
+
var BotCommandRole;
|
|
8
|
+
(function (BotCommandRole) {
|
|
9
|
+
/** 群主 */
|
|
10
|
+
BotCommandRole["Owner"] = "owner";
|
|
11
|
+
/** 管理员 */
|
|
12
|
+
BotCommandRole["Admin"] = "admin";
|
|
13
|
+
/** 成员 */
|
|
14
|
+
BotCommandRole["Member"] = "member";
|
|
15
|
+
/** 所有人 */
|
|
16
|
+
BotCommandRole["All"] = "all";
|
|
17
|
+
})(BotCommandRole || (exports.BotCommandRole = BotCommandRole = {}));
|
|
18
|
+
class BotCommandBase {
|
|
19
|
+
constructor(bot) {
|
|
20
|
+
this.bot = bot;
|
|
21
|
+
}
|
|
22
|
+
initialize() {
|
|
23
|
+
if (constants_1.IS_DEV) {
|
|
24
|
+
logger.info(`注册 ${this.command} 指令...`);
|
|
25
|
+
}
|
|
26
|
+
for (const cmdStr of this.command) {
|
|
27
|
+
this.bot.ctx.command(cmdStr).action(async (argv, ...args) => {
|
|
28
|
+
return await this.authenticate(argv, args);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// 鉴定权限
|
|
33
|
+
async authenticate(cmd, args) {
|
|
34
|
+
// console.log(cmd.session.event);
|
|
35
|
+
const userRole = cmd.session.event.member?.roles?.at(0);
|
|
36
|
+
if (this.roles.length > 0 &&
|
|
37
|
+
!this.roles.includes(userRole)) {
|
|
38
|
+
logger.error(`用户 ${cmd.session.event.user.id}[${userRole}] 没有权限使用指令 ${this.command}`);
|
|
39
|
+
return '您没有权限使用此指令。';
|
|
40
|
+
}
|
|
41
|
+
return await this.handle?.(cmd, args);
|
|
42
|
+
}
|
|
5
43
|
}
|
|
6
|
-
exports.
|
|
44
|
+
exports.BotCommandBase = BotCommandBase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../bot';
|
|
3
|
+
import { MCBotCommandBase, MCBotCommandRole } from './base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器创建指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 创建
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotCreateCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
13
|
+
constructor(bot: MCSManagerBot);
|
|
14
|
+
handle({ args, session, ...opt }: Argv, status?: string[]): Promise<string>;
|
|
15
|
+
private downloadAndProcessFile;
|
|
16
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotCreateCommand = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const koishi_1 = require("koishi");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
/**
|
|
9
|
+
* 服务器创建指令
|
|
10
|
+
*
|
|
11
|
+
* @example 服务器 创建
|
|
12
|
+
*/
|
|
13
|
+
class MCBotCreateCommand extends base_1.MCBotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = ['服务器.创建 <name...>', 'MC.创建 <name...>'];
|
|
18
|
+
this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
|
|
19
|
+
this.initialize();
|
|
20
|
+
}
|
|
21
|
+
async handle({ args, session, ...opt }, status) {
|
|
22
|
+
const { elements } = session?.event?.message?.quote ?? {};
|
|
23
|
+
if (elements.length > 0) {
|
|
24
|
+
const fileElements = koishi_1.h.select(elements, 'file');
|
|
25
|
+
if (fileElements.length > 0) {
|
|
26
|
+
const results = [`检测到 ${fileElements.length} 个文件:`];
|
|
27
|
+
for (const [index, element] of fileElements.entries()) {
|
|
28
|
+
const fileInfo = {
|
|
29
|
+
src: element.attrs?.src,
|
|
30
|
+
fileName: element.attrs?.file || element.attrs?.src,
|
|
31
|
+
fileId: element.attrs?.['fileId'],
|
|
32
|
+
fileSize: element.attrs?.['fileSize'],
|
|
33
|
+
};
|
|
34
|
+
results.push(`\n文件 ${index + 1}:`);
|
|
35
|
+
results.push(` 名称: ${fileInfo.fileName}`);
|
|
36
|
+
results.push(` 文件ID: ${fileInfo.fileId}`);
|
|
37
|
+
if (fileInfo.fileSize) {
|
|
38
|
+
const sizeInMB = (parseInt(fileInfo.fileSize, 10) /
|
|
39
|
+
1024 /
|
|
40
|
+
1024).toFixed(2);
|
|
41
|
+
results.push(` 大小: ${sizeInMB} MB`);
|
|
42
|
+
}
|
|
43
|
+
results.push(`-> 开始尝试下载群文件...`);
|
|
44
|
+
session.send(results.join('\n'));
|
|
45
|
+
results.length = 0;
|
|
46
|
+
// 尝试下载文件
|
|
47
|
+
try {
|
|
48
|
+
const result = await this.bot.manager.gl.napCat.api.getFile(fileInfo.fileId);
|
|
49
|
+
const fileExists = result ? (0, fs_1.existsSync)(result?.file) : false;
|
|
50
|
+
if (result && fileExists) {
|
|
51
|
+
session.send('下载完毕,正在解压并创建服务器实例...');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
results.push(`状态: 处理失败`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
results.push(` 状态: 处理失败 ${error}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return results.join('\n');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return `需要引用包含服务端压缩包的文件喵~`;
|
|
65
|
+
}
|
|
66
|
+
async downloadAndProcessFile(fileInfo, session) {
|
|
67
|
+
const { fileId, fileName } = fileInfo;
|
|
68
|
+
console.log(`开始处理文件: ${fileName}, fileId: ${fileId}, platform: ${session.platform}`);
|
|
69
|
+
// 方法1: 如果fileId是URL,直接下载
|
|
70
|
+
if (fileId && fileId.startsWith('http')) {
|
|
71
|
+
try {
|
|
72
|
+
const response = await this.bot.ctx.http.get(fileId, {
|
|
73
|
+
responseType: 'arraybuffer',
|
|
74
|
+
timeout: 60000, // 60秒超时
|
|
75
|
+
});
|
|
76
|
+
console.log(`直接URL下载文件成功: ${fileName}, 大小: ${response.byteLength} 字节`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.warn(`直接URL下载失败: ${error.message}`);
|
|
81
|
+
return `直接URL下载失败: ${error.message}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// 方法2: NapCat/OneBot 群文件下载支持
|
|
85
|
+
if (session.platform === 'onebot') {
|
|
86
|
+
try {
|
|
87
|
+
console.log(`使用 NapCat 工具下载群文件...`);
|
|
88
|
+
const buffer = await utils_1.NapCatFileDownloader.downloadGroupFile(session, fileId, fileName, this.bot.ctx);
|
|
89
|
+
if (buffer) {
|
|
90
|
+
console.log(`通过 NapCat 下载文件成功: ${fileName}, 大小: ${buffer.length} 字节`);
|
|
91
|
+
// 可选: 保存文件到本地
|
|
92
|
+
// const savePath = `./downloads/server-files/${fileName}`;
|
|
93
|
+
// const fs = require('fs');
|
|
94
|
+
// const path = require('path');
|
|
95
|
+
// if (!fs.existsSync(path.dirname(savePath))) {
|
|
96
|
+
// fs.mkdirSync(path.dirname(savePath), { recursive: true });
|
|
97
|
+
// }
|
|
98
|
+
// fs.writeFileSync(savePath, buffer);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.warn('NapCat 下载失败:', error.message);
|
|
104
|
+
// 继续尝试其他方法
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// 方法3: 尝试构造可能的QQ群文件URL
|
|
108
|
+
if (fileId && (fileId.startsWith('/') || fileId.includes('-'))) {
|
|
109
|
+
const possibleUrls = [
|
|
110
|
+
`https://groupfiles.qq.com${fileId}`,
|
|
111
|
+
`https://grouptalk.c2c.qq.com${fileId}`,
|
|
112
|
+
`https://gchat.qpic.cn${fileId}`,
|
|
113
|
+
];
|
|
114
|
+
for (const url of possibleUrls) {
|
|
115
|
+
try {
|
|
116
|
+
const response = await this.bot.ctx.http.get(url, {
|
|
117
|
+
responseType: 'arraybuffer',
|
|
118
|
+
timeout: 10000,
|
|
119
|
+
});
|
|
120
|
+
console.log(`通过构造URL下载文件成功: ${fileName}, URL: ${url}`);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.warn(`URL ${url} 下载失败:`, error.message);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// 方法4: 记录文件信息但无法下载
|
|
130
|
+
console.log(`文件信息记录: ${fileName}, fileId: ${fileId}`);
|
|
131
|
+
console.log(`平台: ${session.platform}, 当前配置下无法自动下载此文件`);
|
|
132
|
+
return '无法获取文件下载链接,请检查 NapCat 配置或手动下载';
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.MCBotCreateCommand = MCBotCreateCommand;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
export { BotCommandBase } from './base';
|
|
2
|
+
export { MCBotListCommand } from './mc/list';
|
|
3
|
+
export { MCBotGameOnline, MCBotOnlineTimeCommand } from './mc/online';
|
|
4
|
+
export { MCBotRestartCommand } from './mc/restart';
|
|
5
|
+
export { MCBotStartCommand } from './mc/start';
|
|
6
|
+
export { MCBotStopCommand } from './mc/stop';
|
|
7
|
+
export { ARKBotListCommand } from './ark/list';
|
|
8
|
+
export { ARKBotRestartCommand } from './ark/restart';
|
|
9
|
+
export { ARKBotStartCommand } from './ark/start';
|
|
10
|
+
export { ARKBotStopCommand } from './ark/stop';
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
3
|
+
exports.ARKBotStopCommand = exports.ARKBotStartCommand = exports.ARKBotRestartCommand = exports.ARKBotListCommand = exports.MCBotStopCommand = exports.MCBotStartCommand = exports.MCBotRestartCommand = exports.MCBotOnlineTimeCommand = exports.MCBotGameOnline = exports.MCBotListCommand = exports.BotCommandBase = void 0;
|
|
4
|
+
var base_1 = require("./base");
|
|
5
|
+
Object.defineProperty(exports, "BotCommandBase", { enumerable: true, get: function () { return base_1.BotCommandBase; } });
|
|
6
|
+
var list_1 = require("./mc/list");
|
|
7
|
+
Object.defineProperty(exports, "MCBotListCommand", { enumerable: true, get: function () { return list_1.MCBotListCommand; } });
|
|
8
|
+
var online_1 = require("./mc/online");
|
|
9
|
+
Object.defineProperty(exports, "MCBotGameOnline", { enumerable: true, get: function () { return online_1.MCBotGameOnline; } });
|
|
10
|
+
Object.defineProperty(exports, "MCBotOnlineTimeCommand", { enumerable: true, get: function () { return online_1.MCBotOnlineTimeCommand; } });
|
|
11
|
+
var restart_1 = require("./mc/restart");
|
|
12
|
+
Object.defineProperty(exports, "MCBotRestartCommand", { enumerable: true, get: function () { return restart_1.MCBotRestartCommand; } });
|
|
13
|
+
var start_1 = require("./mc/start");
|
|
14
|
+
Object.defineProperty(exports, "MCBotStartCommand", { enumerable: true, get: function () { return start_1.MCBotStartCommand; } });
|
|
15
|
+
var stop_1 = require("./mc/stop");
|
|
16
|
+
Object.defineProperty(exports, "MCBotStopCommand", { enumerable: true, get: function () { return stop_1.MCBotStopCommand; } });
|
|
17
|
+
var list_2 = require("./ark/list");
|
|
18
|
+
Object.defineProperty(exports, "ARKBotListCommand", { enumerable: true, get: function () { return list_2.ARKBotListCommand; } });
|
|
19
|
+
var restart_2 = require("./ark/restart");
|
|
20
|
+
Object.defineProperty(exports, "ARKBotRestartCommand", { enumerable: true, get: function () { return restart_2.ARKBotRestartCommand; } });
|
|
21
|
+
var start_2 = require("./ark/start");
|
|
22
|
+
Object.defineProperty(exports, "ARKBotStartCommand", { enumerable: true, get: function () { return start_2.ARKBotStartCommand; } });
|
|
23
|
+
var stop_2 = require("./ark/stop");
|
|
24
|
+
Object.defineProperty(exports, "ARKBotStopCommand", { enumerable: true, get: function () { return stop_2.ARKBotStopCommand; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MCSManagerBot } from '../bot';
|
|
2
|
+
import { MCBotCommandBase } from './base';
|
|
3
|
+
/**
|
|
4
|
+
* 服务器列表指令
|
|
5
|
+
*
|
|
6
|
+
* @example 服务器 列表
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCBotListCommand extends MCBotCommandBase {
|
|
9
|
+
readonly bot: MCSManagerBot;
|
|
10
|
+
command: string;
|
|
11
|
+
constructor(bot: MCSManagerBot);
|
|
12
|
+
handle(_: any, status?: string[]): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotListCommand = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
/**
|
|
8
|
+
* 服务器列表指令
|
|
9
|
+
*
|
|
10
|
+
* @example 服务器 列表
|
|
11
|
+
*/
|
|
12
|
+
class MCBotListCommand extends base_1.MCBotCommandBase {
|
|
13
|
+
constructor(bot) {
|
|
14
|
+
super(bot);
|
|
15
|
+
this.bot = bot;
|
|
16
|
+
this.command = '服务器.列表 <status>';
|
|
17
|
+
this.initialize();
|
|
18
|
+
}
|
|
19
|
+
async handle(_, status) {
|
|
20
|
+
await this.bot.panel.handleRemoteServices();
|
|
21
|
+
const filteredStatus = status?.at(0);
|
|
22
|
+
const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
|
|
23
|
+
constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
|
|
24
|
+
return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
|
|
25
|
+
.map(item => {
|
|
26
|
+
const { cfg } = item.instance;
|
|
27
|
+
const duration = (0, utils_1.formatDuration)(cfg.config.lastDatetime -
|
|
28
|
+
new Date(cfg.config.createDatetime).getTime());
|
|
29
|
+
return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
|
|
30
|
+
})
|
|
31
|
+
.join('\n')}\n ${'='.repeat(28)} `;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.MCBotListCommand = MCBotListCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MCSManagerBot } from '../bot';
|
|
2
|
+
import { MCBotCommandBase } from './base';
|
|
3
|
+
/**
|
|
4
|
+
* 服务器列表指令
|
|
5
|
+
*
|
|
6
|
+
* @example 服务器 列表
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCBotListCommand extends MCBotCommandBase {
|
|
9
|
+
readonly bot: MCSManagerBot;
|
|
10
|
+
command: string[];
|
|
11
|
+
roles: any[];
|
|
12
|
+
constructor(bot: MCSManagerBot);
|
|
13
|
+
handle(_: any, status?: string[]): Promise<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotListCommand = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
/**
|
|
8
|
+
* 服务器列表指令
|
|
9
|
+
*
|
|
10
|
+
* @example 服务器 列表
|
|
11
|
+
*/
|
|
12
|
+
class MCBotListCommand extends base_1.MCBotCommandBase {
|
|
13
|
+
constructor(bot) {
|
|
14
|
+
super(bot);
|
|
15
|
+
this.bot = bot;
|
|
16
|
+
this.command = ['服务器.列表 <status>', 'MC.列表 <status>'];
|
|
17
|
+
this.roles = [];
|
|
18
|
+
this.initialize();
|
|
19
|
+
}
|
|
20
|
+
async handle(_, status) {
|
|
21
|
+
await this.bot.panel.handleRemoteServices();
|
|
22
|
+
const filteredStatus = status?.at(0);
|
|
23
|
+
const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
|
|
24
|
+
constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
|
|
25
|
+
return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
|
|
26
|
+
.map(item => {
|
|
27
|
+
const { cfg } = item.instance;
|
|
28
|
+
const duration = (0, utils_1.formatDuration)(cfg.config.lastDatetime -
|
|
29
|
+
new Date(cfg.config.createDatetime).getTime());
|
|
30
|
+
return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
|
|
31
|
+
})
|
|
32
|
+
.join('\n')}\n ${'='.repeat(28)} `;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MCBotListCommand = MCBotListCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../../bot';
|
|
3
|
+
import { BotCommandBase, BotCommandRole } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器创建指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 创建
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotCreateCommand extends BotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: BotCommandRole[];
|
|
13
|
+
constructor(bot: MCSManagerBot);
|
|
14
|
+
handle({ args, session }: Argv, status?: string[]): Promise<string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotCreateCommand = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const koishi_1 = require("koishi");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
/**
|
|
9
|
+
* 服务器创建指令
|
|
10
|
+
*
|
|
11
|
+
* @example 服务器 创建
|
|
12
|
+
*/
|
|
13
|
+
class MCBotCreateCommand extends base_1.BotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = ['服务器.创建 <name...>', 'MC.创建 <name...>'];
|
|
18
|
+
this.roles = [base_1.BotCommandRole.Admin, base_1.BotCommandRole.Owner];
|
|
19
|
+
this.initialize();
|
|
20
|
+
}
|
|
21
|
+
async handle({ args, session }, status) {
|
|
22
|
+
const { elements } = session?.event?.message?.quote ?? {};
|
|
23
|
+
if (elements.length > 0) {
|
|
24
|
+
const fileElements = koishi_1.h.select(elements, 'file');
|
|
25
|
+
if (fileElements.length > 0) {
|
|
26
|
+
const results = [];
|
|
27
|
+
for (const [index, element] of fileElements.entries()) {
|
|
28
|
+
const fileInfo = {
|
|
29
|
+
src: element.attrs?.src,
|
|
30
|
+
fileName: element.attrs?.file || element.attrs?.src,
|
|
31
|
+
fileId: element.attrs?.['fileId'],
|
|
32
|
+
fileSize: element.attrs?.['fileSize'],
|
|
33
|
+
};
|
|
34
|
+
results.push(`目标文件:`);
|
|
35
|
+
results.push(` 名称: ${fileInfo.fileName}`);
|
|
36
|
+
if (fileInfo.fileSize) {
|
|
37
|
+
const sizeInMB = (parseInt(fileInfo.fileSize, 10) /
|
|
38
|
+
1024 /
|
|
39
|
+
1024).toFixed(2);
|
|
40
|
+
results.push(` 大小: ${sizeInMB} MB`);
|
|
41
|
+
}
|
|
42
|
+
await session.send(results.join('\n'));
|
|
43
|
+
results.length = 0;
|
|
44
|
+
// 尝试下载文件
|
|
45
|
+
try {
|
|
46
|
+
const result = await this.bot.manager.gl.napCat.api.getFile(fileInfo.fileId);
|
|
47
|
+
const fileExists = result ? (0, fs_1.existsSync)(result?.file) : false;
|
|
48
|
+
if (result && fileExists) {
|
|
49
|
+
session.send('下载完毕,即将创建服务器实例并解压文件...');
|
|
50
|
+
await this.bot.panel.api.instanceUploadByZip(this.bot.panel.remotes.find(r => (0, lodash_1.isEqual)(r.remarks, '节点1'))
|
|
51
|
+
.uuid, {
|
|
52
|
+
nickname: status
|
|
53
|
+
.filter(r => !(0, lodash_1.isEqual)(r.at(0), '<'))
|
|
54
|
+
.join(' '),
|
|
55
|
+
createDatetime: Date.now(),
|
|
56
|
+
}, {
|
|
57
|
+
filename: fileInfo.fileName,
|
|
58
|
+
size: fileInfo.fileSize,
|
|
59
|
+
path: result.file,
|
|
60
|
+
}, msg => {
|
|
61
|
+
session.send(msg);
|
|
62
|
+
});
|
|
63
|
+
return '服务器已创建';
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
results.push(`状态: 处理失败`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
results.push(` 状态: 处理失败 ${error}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return results.join('\n');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return `需要引用包含服务端压缩包的文件喵~`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.MCBotCreateCommand = MCBotCreateCommand;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MCSManagerBot } from '../../bot';
|
|
2
|
+
import { BotCommandBase } from '../base';
|
|
3
|
+
/**
|
|
4
|
+
* 服务器列表指令
|
|
5
|
+
*
|
|
6
|
+
* @example 服务器 列表
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCBotListCommand extends BotCommandBase {
|
|
9
|
+
readonly bot: MCSManagerBot;
|
|
10
|
+
command: string[];
|
|
11
|
+
roles: any[];
|
|
12
|
+
constructor(bot: MCSManagerBot);
|
|
13
|
+
handle(_: any, status?: string[]): Promise<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotListCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const constants_1 = require("../../constants");
|
|
7
|
+
const base_1 = require("../base");
|
|
8
|
+
/**
|
|
9
|
+
* 服务器列表指令
|
|
10
|
+
*
|
|
11
|
+
* @example 服务器 列表
|
|
12
|
+
*/
|
|
13
|
+
class MCBotListCommand extends base_1.BotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = ['服务器.列表 <status>', 'MC.列表 <status>'];
|
|
18
|
+
this.roles = [];
|
|
19
|
+
this.initialize();
|
|
20
|
+
}
|
|
21
|
+
async handle(_, status) {
|
|
22
|
+
await this.bot.panel.handleRemoteServices();
|
|
23
|
+
const filteredStatus = status?.at(0);
|
|
24
|
+
const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
|
|
25
|
+
~item.instance.cfg.config.nickname.indexOf(filteredStatus) ||
|
|
26
|
+
constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
|
|
27
|
+
return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
|
|
28
|
+
.map(item => {
|
|
29
|
+
const { cfg } = item.instance;
|
|
30
|
+
const lastDatetime = (0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.RUNNING)
|
|
31
|
+
? Date.now()
|
|
32
|
+
: cfg.config.lastDatetime;
|
|
33
|
+
const duration = (0, utils_1.formatDuration)(lastDatetime - new Date(cfg.config.createDatetime).getTime());
|
|
34
|
+
return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
|
|
35
|
+
})
|
|
36
|
+
.join('\n')}\n ${'='.repeat(28)} `;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.MCBotListCommand = MCBotListCommand;
|