koishi-plugin-gl-bot 0.0.10 → 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 +44 -54
- package/lib/gl/index.js +12 -7
- package/lib/gl/queqiao.adapter.d.ts +11 -0
- package/lib/gl/queqiao.adapter.js +41 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
- package/lib/mcsManager/api.d.ts +16 -2
- package/lib/mcsManager/api.js +149 -2
- package/lib/mcsManager/bot.d.ts +5 -3
- package/lib/mcsManager/bot.js +18 -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/{restart.js → ark/restart.js} +14 -13
- package/lib/mcsManager/commands/ark/start.d.ts +15 -0
- package/lib/mcsManager/commands/{start.js → ark/start.js} +13 -12
- 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/index.d.ts +11 -10
- package/lib/mcsManager/commands/index.js +21 -14
- package/lib/mcsManager/commands/mc/create.d.ts +15 -0
- package/lib/mcsManager/commands/mc/create.js +79 -0
- 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 +15 -0
- package/lib/mcsManager/commands/mc/list.js +54 -0
- package/lib/mcsManager/commands/mc/online.d.ts +29 -0
- package/lib/mcsManager/commands/mc/online.js +149 -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/config.d.ts +39 -0
- package/lib/mcsManager/config.js +21 -0
- package/lib/mcsManager/index.d.ts +36 -4
- package/lib/mcsManager/index.js +9 -3
- 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 +104 -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 +47 -37
- package/lib/queQiao/index.js +141 -39
- package/lib/queQiao/locale/zh-CN.json +1 -1
- package/lib/queQiao/locale/zh-CN.yml +6 -6
- 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/lib/utils/index.d.ts +7 -0
- package/lib/utils/index.js +58 -0
- package/package.json +2 -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/list.d.ts +0 -11
- package/lib/mcsManager/commands/list.js +0 -26
- package/lib/mcsManager/commands/restart.d.ts +0 -12
- package/lib/mcsManager/commands/start.d.ts +0 -12
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
exports.ARKBotRestartCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
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
|
|
13
|
+
class ARKBotRestartCommand extends base_1.BotCommandBase {
|
|
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...>', 'ARK.重启 <name...>'];
|
|
18
|
+
this.roles = [base_1.BotCommandRole.All];
|
|
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) {
|
|
@@ -58,4 +59,4 @@ class MCBotRestartCommand {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
exports.
|
|
62
|
+
exports.ARKBotRestartCommand = ARKBotRestartCommand;
|
|
@@ -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 ARKBotStartCommand 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
|
+
}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ARKBotStartCommand = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const constants_1 = require("
|
|
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
|
|
13
|
+
class ARKBotStartCommand extends base_1.BotCommandBase {
|
|
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...>', 'ARK.启动 <name...>'];
|
|
18
|
+
this.roles = [base_1.BotCommandRole.All];
|
|
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)) {
|
|
@@ -50,4 +51,4 @@ class MCBotStartCommand {
|
|
|
50
51
|
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行启动操作`;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
exports.
|
|
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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.BotCommandBase = BotCommandBase;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { MCBotListCommand } from './list';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
export { BotCommandBase } from './base';
|
|
2
|
+
export { MCBotHealthCommand } from './mc/health';
|
|
3
|
+
export { MCBotListCommand } from './mc/list';
|
|
4
|
+
export { MCBotGameOnline, MCBotOnlineTimeCommand } from './mc/online';
|
|
5
|
+
export { MCBotRestartCommand } from './mc/restart';
|
|
6
|
+
export { MCBotStartCommand } from './mc/start';
|
|
7
|
+
export { MCBotStopCommand } from './mc/stop';
|
|
8
|
+
export { ARKBotListCommand } from './ark/list';
|
|
9
|
+
export { ARKBotRestartCommand } from './ark/restart';
|
|
10
|
+
export { ARKBotStartCommand } from './ark/start';
|
|
11
|
+
export { ARKBotStopCommand } from './ark/stop';
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.ARKBotStopCommand = exports.ARKBotStartCommand = exports.ARKBotRestartCommand = exports.ARKBotListCommand = exports.MCBotStopCommand = exports.MCBotStartCommand = exports.MCBotRestartCommand = exports.MCBotOnlineTimeCommand = exports.MCBotGameOnline = exports.MCBotListCommand = exports.MCBotHealthCommand = 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 health_1 = require("./mc/health");
|
|
7
|
+
Object.defineProperty(exports, "MCBotHealthCommand", { enumerable: true, get: function () { return health_1.MCBotHealthCommand; } });
|
|
8
|
+
var list_1 = require("./mc/list");
|
|
6
9
|
Object.defineProperty(exports, "MCBotListCommand", { enumerable: true, get: function () { return list_1.MCBotListCommand; } });
|
|
7
|
-
var
|
|
10
|
+
var online_1 = require("./mc/online");
|
|
11
|
+
Object.defineProperty(exports, "MCBotGameOnline", { enumerable: true, get: function () { return online_1.MCBotGameOnline; } });
|
|
12
|
+
Object.defineProperty(exports, "MCBotOnlineTimeCommand", { enumerable: true, get: function () { return online_1.MCBotOnlineTimeCommand; } });
|
|
13
|
+
var restart_1 = require("./mc/restart");
|
|
8
14
|
Object.defineProperty(exports, "MCBotRestartCommand", { enumerable: true, get: function () { return restart_1.MCBotRestartCommand; } });
|
|
9
|
-
var start_1 = require("./start");
|
|
15
|
+
var start_1 = require("./mc/start");
|
|
10
16
|
Object.defineProperty(exports, "MCBotStartCommand", { enumerable: true, get: function () { return start_1.MCBotStartCommand; } });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
var stop_1 = require("./mc/stop");
|
|
18
|
+
Object.defineProperty(exports, "MCBotStopCommand", { enumerable: true, get: function () { return stop_1.MCBotStopCommand; } });
|
|
19
|
+
var list_2 = require("./ark/list");
|
|
20
|
+
Object.defineProperty(exports, "ARKBotListCommand", { enumerable: true, get: function () { return list_2.ARKBotListCommand; } });
|
|
21
|
+
var restart_2 = require("./ark/restart");
|
|
22
|
+
Object.defineProperty(exports, "ARKBotRestartCommand", { enumerable: true, get: function () { return restart_2.ARKBotRestartCommand; } });
|
|
23
|
+
var start_2 = require("./ark/start");
|
|
24
|
+
Object.defineProperty(exports, "ARKBotStartCommand", { enumerable: true, get: function () { return start_2.ARKBotStartCommand; } });
|
|
25
|
+
var stop_2 = require("./ark/stop");
|
|
26
|
+
Object.defineProperty(exports, "ARKBotStopCommand", { enumerable: true, get: function () { return stop_2.ARKBotStopCommand; } });
|
|
@@ -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,16 @@
|
|
|
1
|
+
import MinecraftSyncMsg from '../../../queQiao';
|
|
2
|
+
import { MCSManagerBot } from '../../bot';
|
|
3
|
+
import { BotCommandBase } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器 健康 指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 健康
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotHealthCommand extends BotCommandBase {
|
|
10
|
+
readonly bot: MCSManagerBot;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: any[];
|
|
13
|
+
constructor(bot: MCSManagerBot);
|
|
14
|
+
getHealthStatus(connect: MinecraftSyncMsg): Promise<any[]>;
|
|
15
|
+
handle(_: any, status?: string[]): Promise<string>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotHealthCommand = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const base_1 = require("../base");
|
|
6
|
+
/**
|
|
7
|
+
* 服务器 健康 指令
|
|
8
|
+
*
|
|
9
|
+
* @example 服务器 健康
|
|
10
|
+
*/
|
|
11
|
+
class MCBotHealthCommand extends base_1.BotCommandBase {
|
|
12
|
+
constructor(bot) {
|
|
13
|
+
super(bot);
|
|
14
|
+
this.bot = bot;
|
|
15
|
+
this.command = ['服务器.健康 <status>', 'MC.健康 <status>'];
|
|
16
|
+
this.roles = [];
|
|
17
|
+
this.initialize();
|
|
18
|
+
}
|
|
19
|
+
async getHealthStatus(connect) {
|
|
20
|
+
const healths = [];
|
|
21
|
+
if (!connect.rcon || !connect.rcon.authenticated) {
|
|
22
|
+
return healths;
|
|
23
|
+
}
|
|
24
|
+
// FIXME: 此处需适配
|
|
25
|
+
const result = await connect.sendRconCommand('forge tps');
|
|
26
|
+
// Overall: Mean tick time: 3.314 ms. Mean TPS: 20.000
|
|
27
|
+
const [, tickTimeMatch, tpsMatch] = result.match(/Mean tick time: ([\d.]+) ms\. Mean TPS: ([\d.]+)/) || [];
|
|
28
|
+
if (tickTimeMatch && (0, lodash_1.isNumber)(Number(tickTimeMatch))) {
|
|
29
|
+
healths.push(`Tick:${Number(tickTimeMatch).toFixed(2)} ms [${Number(tickTimeMatch) <= 50 ? '优秀' : '过高'}]`);
|
|
30
|
+
}
|
|
31
|
+
if (tpsMatch && (0, lodash_1.isNumber)(Number(tpsMatch))) {
|
|
32
|
+
healths.push(`TPS:${Number(tpsMatch).toFixed(2)} [${Number(tpsMatch) >= 15 ? '优秀' : '过低'}]`);
|
|
33
|
+
}
|
|
34
|
+
return healths;
|
|
35
|
+
}
|
|
36
|
+
async handle(_, status) {
|
|
37
|
+
const result = ['服务器 健康 状态:'];
|
|
38
|
+
for (const [name, server] of Object.entries(this.bot.manager.gl.queQiaoAdapter.servers)) {
|
|
39
|
+
const headers = await this.getHealthStatus(server);
|
|
40
|
+
const queQIaoConnected = server.ws?.readyState === 1;
|
|
41
|
+
result.push(`- [${name}] 互通:${queQIaoConnected ? 'OK' : 'NO'} | 后端:${server.rcon.authenticated ? 'OK' : 'NO'} | ${headers.join(' | ')}`);
|
|
42
|
+
}
|
|
43
|
+
return result.join('\n');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MCBotHealthCommand = MCBotHealthCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
readServerProperties(daemonId: string, instanceId: string): Promise<Record<string, never>>;
|
|
14
|
+
handle(_: any, status?: string[]): Promise<string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 readServerProperties(daemonId, instanceId) {
|
|
22
|
+
return this.bot.panel.api.readServerProperties(daemonId, instanceId);
|
|
23
|
+
}
|
|
24
|
+
async handle(_, status) {
|
|
25
|
+
await this.bot.panel.handleRemoteServices();
|
|
26
|
+
let filteredStatus = status?.at(0) ?? '运行中';
|
|
27
|
+
if (filteredStatus === '全部') {
|
|
28
|
+
filteredStatus = '';
|
|
29
|
+
}
|
|
30
|
+
const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
|
|
31
|
+
~item.instance.cfg.config.nickname.indexOf(filteredStatus) ||
|
|
32
|
+
constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
|
|
33
|
+
const list = [];
|
|
34
|
+
for (const item of nameInstances) {
|
|
35
|
+
let properties = {};
|
|
36
|
+
const { cfg } = item.instance;
|
|
37
|
+
const lastDatetime = (0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.RUNNING)
|
|
38
|
+
? Date.now()
|
|
39
|
+
: cfg.config.lastDatetime;
|
|
40
|
+
const duration = (0, utils_1.formatDuration)(lastDatetime - new Date(cfg.config.createDatetime).getTime());
|
|
41
|
+
try {
|
|
42
|
+
properties = await this.readServerProperties(item.remote.uuid, item.instance.cfg.instanceUuid);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
properties = {};
|
|
46
|
+
}
|
|
47
|
+
list.push(`- ${constants_1.RemoteInstanceStatusName[cfg.status]} ${cfg.config.nickname} 「${duration}」[端口 ${properties?.['server-port'] || '--'}]`
|
|
48
|
+
.replace('运行中', '✅')
|
|
49
|
+
.replace('已停止', '❌'));
|
|
50
|
+
}
|
|
51
|
+
return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${list.join('\n')}\n ${'='.repeat(28)} `;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.MCBotListCommand = MCBotListCommand;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import MinecraftSyncMsg from '../../../queQiao';
|
|
2
|
+
import { MCSManagerBot } from '../../bot';
|
|
3
|
+
import { McUser } from '../../type';
|
|
4
|
+
import { BotCommandBase } from '../base';
|
|
5
|
+
export declare class MCBotGameOnline extends BotCommandBase {
|
|
6
|
+
readonly bot: MCSManagerBot;
|
|
7
|
+
static list: Record<string, {
|
|
8
|
+
config: Schemastery.TypeS<typeof MinecraftSyncMsg.Config>;
|
|
9
|
+
list: Record<string, McUser>;
|
|
10
|
+
}>;
|
|
11
|
+
command: string[];
|
|
12
|
+
roles: any[];
|
|
13
|
+
constructor(bot: MCSManagerBot);
|
|
14
|
+
getOnlinePlayers(connect: MinecraftSyncMsg): Promise<string[]>;
|
|
15
|
+
handle(): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 服务器在线榜单指令
|
|
19
|
+
* 查询服务器在线时长排行
|
|
20
|
+
*
|
|
21
|
+
* @example 服务器 在线榜单
|
|
22
|
+
*/
|
|
23
|
+
export declare class MCBotOnlineTimeCommand extends BotCommandBase {
|
|
24
|
+
readonly bot: MCSManagerBot;
|
|
25
|
+
command: string[];
|
|
26
|
+
roles: any[];
|
|
27
|
+
constructor(bot: MCSManagerBot);
|
|
28
|
+
handle(): Promise<string>;
|
|
29
|
+
}
|