koishi-plugin-gl-bot 0.0.10 → 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/gl/index.d.ts +9 -0
- package/lib/gl/index.js +9 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
- package/lib/mcsManager/api.d.ts +15 -2
- package/lib/mcsManager/api.js +136 -1
- package/lib/mcsManager/bot.d.ts +5 -3
- package/lib/mcsManager/bot.js +17 -9
- 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 +21 -0
- package/lib/mcsManager/commands/base.js +44 -0
- 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 -10
- package/lib/mcsManager/commands/index.js +19 -14
- 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 +6 -3
- package/lib/mcsManager/commands/list.js +18 -9
- 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 +7 -4
- package/lib/mcsManager/commands/restart.js +11 -10
- package/lib/mcsManager/commands/start copy.d.ts +14 -0
- package/lib/mcsManager/commands/start copy.js +53 -0
- package/lib/mcsManager/commands/start.d.ts +7 -4
- package/lib/mcsManager/commands/start.js +10 -9
- package/lib/mcsManager/commands/stop.d.ts +15 -0
- package/lib/mcsManager/commands/stop.js +54 -0
- package/lib/mcsManager/index.d.ts +4 -3
- package/lib/mcsManager/index.js +5 -2
- package/lib/mcsManager/json/createInstanceUpload.json +49 -0
- package/lib/mcsManager/panel.d.ts +1 -1
- package/lib/mcsManager/panel.js +1 -1
- 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 +1 -1
- 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 +68 -1
- package/lib/queQiao/locale/zh-CN.json +1 -1
- package/lib/queQiao/locale/zh-CN.yml +6 -6
- 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 +2 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotRestartCommand = 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 MCBotRestartCommand 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({ 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
|
+
switch (cfg.status) {
|
|
47
|
+
// 关闭状态:启动
|
|
48
|
+
case constants_1.RemoteInstanceStatusEnum.RUNNING:
|
|
49
|
+
await targetInstance.instance.restartInstance();
|
|
50
|
+
this.bot.panel.handleRemoteServices();
|
|
51
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送重启操作`;
|
|
52
|
+
// 启动状态:重启
|
|
53
|
+
case constants_1.RemoteInstanceStatusEnum.STOPPED:
|
|
54
|
+
await targetInstance.instance.startInstance();
|
|
55
|
+
this.bot.panel.handleRemoteServices();
|
|
56
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
|
|
57
|
+
default:
|
|
58
|
+
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行重启操作`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.MCBotRestartCommand = MCBotRestartCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 MCBotStartCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
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.MCBotStartCommand = 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 MCBotStartCommand 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({ 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.MCBotStartCommand = MCBotStartCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 MCBotStopCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
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.MCBotStopCommand = 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 MCBotStopCommand 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({ 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.MCBotStopCommand = MCBotStopCommand;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
2
|
import { MCSManagerBot } from '../bot';
|
|
3
|
+
import { MCBotCommandBase, MCBotCommandRole } from './base';
|
|
3
4
|
/**
|
|
4
5
|
* 服务器重启指令
|
|
5
6
|
*
|
|
6
7
|
* @example 服务器 重启 神话
|
|
7
8
|
*/
|
|
8
|
-
export declare class MCBotRestartCommand {
|
|
9
|
-
|
|
9
|
+
export declare class MCBotRestartCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
10
13
|
constructor(bot: MCSManagerBot);
|
|
11
|
-
handle(session:
|
|
14
|
+
handle({ session }: Argv, args: string[]): Promise<string>;
|
|
12
15
|
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MCBotRestartCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const constants_1 = require("../constants");
|
|
5
|
-
|
|
6
|
+
const base_1 = require("./base");
|
|
6
7
|
const tempSelections = new Map();
|
|
7
8
|
/**
|
|
8
9
|
* 服务器重启指令
|
|
9
10
|
*
|
|
10
11
|
* @example 服务器 重启 神话
|
|
11
12
|
*/
|
|
12
|
-
class MCBotRestartCommand {
|
|
13
|
+
class MCBotRestartCommand extends base_1.MCBotCommandBase {
|
|
13
14
|
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
14
16
|
this.bot = bot;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return await this.handle(session, name.join(' '));
|
|
19
|
-
});
|
|
17
|
+
this.command = ['服务器.重启 <name...>', 'MC.重启 <name...>'];
|
|
18
|
+
this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
|
|
19
|
+
this.initialize();
|
|
20
20
|
}
|
|
21
|
-
async handle(session,
|
|
21
|
+
async handle({ session }, args) {
|
|
22
|
+
let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
|
|
22
23
|
let selectIndex = -1;
|
|
23
24
|
const userId = Number(session.event.user.id);
|
|
24
25
|
// 溯源前搜索项
|
|
@@ -29,7 +30,7 @@ class MCBotRestartCommand {
|
|
|
29
30
|
tempSelections.delete(userId);
|
|
30
31
|
const nameInstances = await this.bot.panel.searchInstanceByName(name);
|
|
31
32
|
if (nameInstances.length === 0) {
|
|
32
|
-
return `未找到名称包含 "${name}"
|
|
33
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
33
34
|
}
|
|
34
35
|
if (nameInstances.length > 1 && selectIndex === -1) {
|
|
35
36
|
tempSelections.set(userId, name);
|
|
@@ -39,7 +40,7 @@ class MCBotRestartCommand {
|
|
|
39
40
|
}
|
|
40
41
|
const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
|
|
41
42
|
if (!targetInstance || !targetInstance.instance) {
|
|
42
|
-
return `未找到名称包含 "${name}"
|
|
43
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
43
44
|
}
|
|
44
45
|
const { cfg } = targetInstance.instance;
|
|
45
46
|
switch (cfg.status) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../bot';
|
|
3
|
+
import { MCBotCommandBase } from './base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器启动指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 启动 神话
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotStartCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string;
|
|
12
|
+
constructor(bot: MCSManagerBot);
|
|
13
|
+
handle({ session }: Argv, args: string[]): Promise<string>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotStartCommand = 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 MCBotStartCommand extends base_1.MCBotCommandBase {
|
|
14
|
+
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
16
|
+
this.bot = bot;
|
|
17
|
+
this.command = '服务器.启动 <name...>';
|
|
18
|
+
this.initialize();
|
|
19
|
+
}
|
|
20
|
+
async handle({ session }, args) {
|
|
21
|
+
let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
|
|
22
|
+
let selectIndex = -1;
|
|
23
|
+
const userId = Number(session.event.user.id);
|
|
24
|
+
// 溯源前搜索项
|
|
25
|
+
if (tempSelections.has(userId) && !isNaN(Number(name))) {
|
|
26
|
+
selectIndex = Number(name) - 1;
|
|
27
|
+
name = tempSelections.get(userId);
|
|
28
|
+
}
|
|
29
|
+
tempSelections.delete(userId);
|
|
30
|
+
const nameInstances = await this.bot.panel.searchInstanceByName(name);
|
|
31
|
+
if (nameInstances.length === 0) {
|
|
32
|
+
return `未找到名称包含 "${name}" 的服务器实例`;
|
|
33
|
+
}
|
|
34
|
+
if (nameInstances.length > 1 && selectIndex === -1) {
|
|
35
|
+
tempSelections.set(userId, name);
|
|
36
|
+
return `请输入序号以选择:\n\n${nameInstances
|
|
37
|
+
.map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
|
|
38
|
+
.join('\n')}\n ==== 例如发送: (服务器 启动 1) ====`;
|
|
39
|
+
}
|
|
40
|
+
const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
|
|
41
|
+
if (!targetInstance || !targetInstance.instance) {
|
|
42
|
+
return `未找到名称包含 "${name}" 的服务器实例`;
|
|
43
|
+
}
|
|
44
|
+
const { cfg } = targetInstance.instance;
|
|
45
|
+
if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.STOPPED)) {
|
|
46
|
+
await targetInstance.instance.startInstance();
|
|
47
|
+
this.bot.panel.handleRemoteServices();
|
|
48
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
|
|
49
|
+
}
|
|
50
|
+
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行启动操作`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MCBotStartCommand = MCBotStartCommand;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Argv } from 'koishi';
|
|
2
2
|
import { MCSManagerBot } from '../bot';
|
|
3
|
+
import { MCBotCommandBase, MCBotCommandRole } from './base';
|
|
3
4
|
/**
|
|
4
5
|
* 服务器启动指令
|
|
5
6
|
*
|
|
6
7
|
* @example 服务器 启动 神话
|
|
7
8
|
*/
|
|
8
|
-
export declare class MCBotStartCommand {
|
|
9
|
-
|
|
9
|
+
export declare class MCBotStartCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
10
13
|
constructor(bot: MCSManagerBot);
|
|
11
|
-
handle(session:
|
|
14
|
+
handle({ session }: Argv, args: string[]): Promise<string>;
|
|
12
15
|
}
|
|
@@ -3,22 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MCBotStartCommand = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
|
+
const base_1 = require("./base");
|
|
6
7
|
const tempSelections = new Map();
|
|
7
8
|
/**
|
|
8
9
|
* 服务器启动指令
|
|
9
10
|
*
|
|
10
11
|
* @example 服务器 启动 神话
|
|
11
12
|
*/
|
|
12
|
-
class MCBotStartCommand {
|
|
13
|
+
class MCBotStartCommand extends base_1.MCBotCommandBase {
|
|
13
14
|
constructor(bot) {
|
|
15
|
+
super(bot);
|
|
14
16
|
this.bot = bot;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return await this.handle(session, name.join(' '));
|
|
19
|
-
});
|
|
17
|
+
this.command = ['服务器.启动 <name...>', 'MC.启动 <name...>'];
|
|
18
|
+
this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
|
|
19
|
+
this.initialize();
|
|
20
20
|
}
|
|
21
|
-
async handle(session,
|
|
21
|
+
async handle({ session }, args) {
|
|
22
|
+
let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
|
|
22
23
|
let selectIndex = -1;
|
|
23
24
|
const userId = Number(session.event.user.id);
|
|
24
25
|
// 溯源前搜索项
|
|
@@ -29,7 +30,7 @@ class MCBotStartCommand {
|
|
|
29
30
|
tempSelections.delete(userId);
|
|
30
31
|
const nameInstances = await this.bot.panel.searchInstanceByName(name);
|
|
31
32
|
if (nameInstances.length === 0) {
|
|
32
|
-
return `未找到名称包含 "${name}"
|
|
33
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
33
34
|
}
|
|
34
35
|
if (nameInstances.length > 1 && selectIndex === -1) {
|
|
35
36
|
tempSelections.set(userId, name);
|
|
@@ -39,7 +40,7 @@ class MCBotStartCommand {
|
|
|
39
40
|
}
|
|
40
41
|
const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
|
|
41
42
|
if (!targetInstance || !targetInstance.instance) {
|
|
42
|
-
return `未找到名称包含 "${name}"
|
|
43
|
+
return `未找到名称包含 "${name}" 的服务器`;
|
|
43
44
|
}
|
|
44
45
|
const { cfg } = targetInstance.instance;
|
|
45
46
|
if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.STOPPED)) {
|
|
@@ -0,0 +1,15 @@
|
|
|
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 MCBotStopCommand extends MCBotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: MCBotCommandRole[];
|
|
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.MCBotStopCommand = 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 MCBotStopCommand 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({ 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.MCBotStopCommand = MCBotStopCommand;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
|
-
import { GLBotConfigType } from '../gl';
|
|
2
|
+
import { GLBot, GLBotConfigType } from '../gl';
|
|
3
3
|
export declare class MCManager {
|
|
4
|
-
|
|
4
|
+
readonly gl: GLBot;
|
|
5
|
+
readonly ctx: Context;
|
|
5
6
|
private readonly config;
|
|
6
7
|
static Config: Schema<Schemastery.ObjectS<{
|
|
7
8
|
mcManagerUsername: Schema<string, string>;
|
|
@@ -20,7 +21,7 @@ export declare class MCManager {
|
|
|
20
21
|
} & import("cosmokit").Dict>;
|
|
21
22
|
private panel;
|
|
22
23
|
private bot;
|
|
23
|
-
constructor(ctx: Context, config: GLBotConfigType);
|
|
24
|
+
constructor(gl: GLBot, ctx: Context, config: GLBotConfigType);
|
|
24
25
|
initialize(): Promise<void>;
|
|
25
26
|
}
|
|
26
27
|
export type MCManagerConfigType = typeof MCManager.Config;
|
package/lib/mcsManager/index.js
CHANGED
|
@@ -5,12 +5,15 @@ const koishi_1 = require("koishi");
|
|
|
5
5
|
const bot_1 = require("./bot");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
7
|
const panel_1 = require("./panel");
|
|
8
|
+
const schedules_1 = require("./schedules");
|
|
8
9
|
class MCManager {
|
|
9
|
-
constructor(ctx, config) {
|
|
10
|
+
constructor(gl, ctx, config) {
|
|
11
|
+
this.gl = gl;
|
|
10
12
|
this.ctx = ctx;
|
|
11
13
|
this.config = config;
|
|
14
|
+
(0, schedules_1.registerMcSchedule)(ctx);
|
|
12
15
|
this.panel = new panel_1.MCSManagerPanel(ctx, config);
|
|
13
|
-
this.bot = new bot_1.MCSManagerBot(ctx, config, this.panel);
|
|
16
|
+
this.bot = new bot_1.MCSManagerBot(this, ctx, config, this.panel);
|
|
14
17
|
ctx.on('ready', this.initialize.bind(this));
|
|
15
18
|
}
|
|
16
19
|
async initialize() {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nickname": "",
|
|
3
|
+
"startCommand": "",
|
|
4
|
+
"stopCommand": "stop",
|
|
5
|
+
"cwd": ".",
|
|
6
|
+
"ie": "UTF-8",
|
|
7
|
+
"oe": "UTF-8",
|
|
8
|
+
"createDatetime": 0,
|
|
9
|
+
"lastDatetime": 0,
|
|
10
|
+
"type": "minecraft/java",
|
|
11
|
+
"tag": [],
|
|
12
|
+
"endTime": 0,
|
|
13
|
+
"fileCode": "UTF-8",
|
|
14
|
+
"processType": "general",
|
|
15
|
+
"updateCommand": "",
|
|
16
|
+
"runAs": "",
|
|
17
|
+
"actionCommandList": [],
|
|
18
|
+
"crlf": 1,
|
|
19
|
+
"category": 0,
|
|
20
|
+
"enableRcon": false,
|
|
21
|
+
"rconPassword": "",
|
|
22
|
+
"rconIp": "",
|
|
23
|
+
"terminalOption": {
|
|
24
|
+
"haveColor": true,
|
|
25
|
+
"pty": false,
|
|
26
|
+
"ptyWindowCol": 164,
|
|
27
|
+
"ptyWindowRow": 40
|
|
28
|
+
},
|
|
29
|
+
"eventTask": {
|
|
30
|
+
"autoStart": false,
|
|
31
|
+
"autoRestart": false,
|
|
32
|
+
"autoRestartMaxTimes": 3,
|
|
33
|
+
"ignore": false
|
|
34
|
+
},
|
|
35
|
+
"docker": {
|
|
36
|
+
"containerName": "",
|
|
37
|
+
"image": "",
|
|
38
|
+
"ports": [],
|
|
39
|
+
"extraVolumes": [],
|
|
40
|
+
"networkMode": "bridge",
|
|
41
|
+
"networkAliases": [],
|
|
42
|
+
"cpusetCpus": "",
|
|
43
|
+
"workingDir": "/data",
|
|
44
|
+
"env": [],
|
|
45
|
+
"changeWorkdir": true
|
|
46
|
+
},
|
|
47
|
+
"pingConfig": { "ip": "", "type": 1 },
|
|
48
|
+
"extraServiceConfig": { "openFrpTunnelId": "", "openFrpToken": "" }
|
|
49
|
+
}
|
|
@@ -8,7 +8,7 @@ export declare class MCSManagerPanel {
|
|
|
8
8
|
readonly ctx: Context;
|
|
9
9
|
readonly config: GLBotConfigType;
|
|
10
10
|
private isInitialized;
|
|
11
|
-
api: MCSManagerAPI;
|
|
11
|
+
readonly api: MCSManagerAPI;
|
|
12
12
|
remotes: ServiceRemoteItemCustom[];
|
|
13
13
|
remoteConnectionsMap: Map<string, MCSManagerWebSocketIO>;
|
|
14
14
|
constructor(ctx: Context, config: GLBotConfigType);
|
package/lib/mcsManager/panel.js
CHANGED
|
@@ -17,7 +17,7 @@ class MCSManagerPanel {
|
|
|
17
17
|
this.remotes = [];
|
|
18
18
|
// 远程连接Map表
|
|
19
19
|
this.remoteConnectionsMap = new Map();
|
|
20
|
-
this.api = new api_1.MCSManagerAPI(ctx.http, config.mcManagerHost);
|
|
20
|
+
this.api = new api_1.MCSManagerAPI(ctx.http, config.mcManagerHost, config.mcManagerWs);
|
|
21
21
|
this.initialize();
|
|
22
22
|
}
|
|
23
23
|
async initialize() {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.registerMcSchedule = void 0;
|
|
37
|
+
const McSchedule = __importStar(require("./mc.schedule"));
|
|
38
|
+
const registerMcSchedule = (ctx) => {
|
|
39
|
+
McSchedule.default(ctx);
|
|
40
|
+
};
|
|
41
|
+
exports.registerMcSchedule = registerMcSchedule;
|