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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotOnlineTimeCommand = exports.MCBotGameOnline = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const base_1 = require("../base");
|
|
7
|
+
class MCBotGameOnline extends base_1.BotCommandBase {
|
|
8
|
+
constructor(bot) {
|
|
9
|
+
super(bot);
|
|
10
|
+
this.bot = bot;
|
|
11
|
+
this.command = ['服务器.在线 <status>', 'MC.在线 <status>'];
|
|
12
|
+
this.roles = [];
|
|
13
|
+
this.initialize();
|
|
14
|
+
}
|
|
15
|
+
async getOnlinePlayers(connect) {
|
|
16
|
+
// There are 2 of a max of 2026 players online: xxx, xxxx
|
|
17
|
+
return ((await connect.sendRconCommand('list'))
|
|
18
|
+
?.match(/There are \d+ of a max of \d+ players online: (.*)/)?.[1]
|
|
19
|
+
?.split(',')
|
|
20
|
+
?.map(name => name.trim())
|
|
21
|
+
?.filter(name => name.length > 0) ?? []);
|
|
22
|
+
}
|
|
23
|
+
async handle() {
|
|
24
|
+
// 先获取在线人数
|
|
25
|
+
const rconPlayersResults = {};
|
|
26
|
+
for (const [name, server] of Object.entries(this.bot.manager.gl.queQiaoAdapter.servers)) {
|
|
27
|
+
const online = await this.getOnlinePlayers(server);
|
|
28
|
+
const serverConfig = server.config;
|
|
29
|
+
rconPlayersResults[server.config.serverName || ''] = {
|
|
30
|
+
config: serverConfig,
|
|
31
|
+
list: online.reduce((acc, nickname) => {
|
|
32
|
+
acc[nickname] = {
|
|
33
|
+
nickname,
|
|
34
|
+
uuid: '', // UUID 需要通过其他方式获取
|
|
35
|
+
server: serverConfig,
|
|
36
|
+
};
|
|
37
|
+
return acc;
|
|
38
|
+
}, {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// 内存中的在线玩家
|
|
42
|
+
try {
|
|
43
|
+
const users = await this.bot.ctx.database.get('mcUser', {});
|
|
44
|
+
const allOnlineUsers = Object.values((0, lodash_1.merge)({}, rconPlayersResults, MCBotGameOnline.list)).flatMap(server => {
|
|
45
|
+
return Object.values(server.list).map(user => {
|
|
46
|
+
user.server = server.config;
|
|
47
|
+
return user;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
const userRankings = allOnlineUsers
|
|
51
|
+
.map(user => {
|
|
52
|
+
const dbUser = users.find(u => u.uuid === user.uuid || u.nickname === user.nickname);
|
|
53
|
+
let totalOnlineTime = +((Date.now() - (dbUser?.lastTime?.getTime() || 0)) /
|
|
54
|
+
1000).toFixed(0);
|
|
55
|
+
// rcon 未获取到 UUID 情况
|
|
56
|
+
if ((0, lodash_1.isEmpty)(user.uuid)) {
|
|
57
|
+
totalOnlineTime = -1;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...user,
|
|
61
|
+
totalOnlineTime,
|
|
62
|
+
};
|
|
63
|
+
})
|
|
64
|
+
.sort((a, b) => b.totalOnlineTime - a.totalOnlineTime)
|
|
65
|
+
.slice(0, 10);
|
|
66
|
+
let result = `==== 在线 玩家 ====\n`;
|
|
67
|
+
userRankings.forEach((user, index) => {
|
|
68
|
+
const rank = index + 1;
|
|
69
|
+
const onlineTimeStr = (0, lodash_1.isEqual)(user.totalOnlineTime, -1)
|
|
70
|
+
? ''
|
|
71
|
+
: `「${(0, utils_1.formatOnlineTime)(user.totalOnlineTime)}」`;
|
|
72
|
+
result += `[${user.server.serverName ?? '-'}] ${rank}. ${user.nickname} ${onlineTimeStr}\n`;
|
|
73
|
+
});
|
|
74
|
+
result += '=================';
|
|
75
|
+
if (userRankings.length === 0) {
|
|
76
|
+
return '当前没有在线玩家';
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('查询在线玩家失败:', error);
|
|
82
|
+
return '查询在线玩家时发生错误,请稍后重试';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.MCBotGameOnline = MCBotGameOnline;
|
|
87
|
+
MCBotGameOnline.list = {};
|
|
88
|
+
/**
|
|
89
|
+
* 服务器在线榜单指令
|
|
90
|
+
* 查询服务器在线时长排行
|
|
91
|
+
*
|
|
92
|
+
* @example 服务器 在线榜单
|
|
93
|
+
*/
|
|
94
|
+
class MCBotOnlineTimeCommand extends base_1.BotCommandBase {
|
|
95
|
+
constructor(bot) {
|
|
96
|
+
super(bot);
|
|
97
|
+
this.bot = bot;
|
|
98
|
+
this.command = ['服务器.在线榜单 <status>', 'MC.在线榜单 <status>'];
|
|
99
|
+
this.roles = [];
|
|
100
|
+
this.initialize();
|
|
101
|
+
}
|
|
102
|
+
async handle() {
|
|
103
|
+
try {
|
|
104
|
+
const users = await this.bot.ctx.database.get('mcUser', {});
|
|
105
|
+
if (users.length === 0) {
|
|
106
|
+
return '暂无玩家在线时长数据';
|
|
107
|
+
}
|
|
108
|
+
const userRankings = users
|
|
109
|
+
.map(user => {
|
|
110
|
+
let totalOnlineTime = 0;
|
|
111
|
+
const onlineTimeData = JSON.parse(user.onlineTimeJSON || '{}');
|
|
112
|
+
if (onlineTimeData?.mc?.[user.uuid]) {
|
|
113
|
+
totalOnlineTime = onlineTimeData.mc[user.uuid];
|
|
114
|
+
}
|
|
115
|
+
if (MCBotGameOnline.list[user.uuid]) {
|
|
116
|
+
totalOnlineTime += +((Date.now() - user.lastTime.getTime()) /
|
|
117
|
+
1000).toFixed(0);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
nickname: user.nickname,
|
|
121
|
+
uuid: user.uuid,
|
|
122
|
+
level: user.level,
|
|
123
|
+
totalOnlineTime,
|
|
124
|
+
lastTime: user.lastTime,
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
.sort((a, b) => b.totalOnlineTime - a.totalOnlineTime)
|
|
128
|
+
.slice(0, 10);
|
|
129
|
+
let result = '==== 服务器在线时长排行榜 ====\n';
|
|
130
|
+
const tag = [, '🥇', '🥈', '🥉'];
|
|
131
|
+
userRankings.forEach((user, index) => {
|
|
132
|
+
const rank = index + 1;
|
|
133
|
+
const medal = tag[rank] || `${rank}.`;
|
|
134
|
+
const onlineTimeStr = (0, utils_1.formatOnlineTime)(user.totalOnlineTime);
|
|
135
|
+
result += `${medal} ${user.nickname} 「${onlineTimeStr}」\n`;
|
|
136
|
+
if (index < userRankings.length - 1) {
|
|
137
|
+
result += '\n';
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
result += '========================';
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error('查询在线时长排行榜失败:', error);
|
|
145
|
+
return '查询在线时长排行榜时发生错误,请稍后重试';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.MCBotOnlineTimeCommand = MCBotOnlineTimeCommand;
|
|
@@ -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 MCBotRestartCommand 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,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.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({ 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 { BotCommandBase, BotCommandRole } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器启动指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 启动 神话
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotStartCommand 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.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.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({ 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 { BotCommandBase, BotCommandRole } from '../base';
|
|
4
|
+
/**
|
|
5
|
+
* 服务器关闭指令
|
|
6
|
+
*
|
|
7
|
+
* @example 服务器 关闭 神话
|
|
8
|
+
*/
|
|
9
|
+
export declare class MCBotStopCommand 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.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.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({ 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;
|
|
@@ -15,4 +15,43 @@ export declare class MCManagerConfig {
|
|
|
15
15
|
mcManagerWs: Schema<string, string>;
|
|
16
16
|
mcManagerMaxConnectWs: Schema<number, number>;
|
|
17
17
|
}>>;
|
|
18
|
+
static QueQiao: Schema<Schemastery.ObjectS<{
|
|
19
|
+
queQiaoEnable: Schema<boolean, boolean>;
|
|
20
|
+
queQiaoSendToChannel: Schema<string[], string[]>;
|
|
21
|
+
queQiaoWatchChannel: Schema<string[], string[]>;
|
|
22
|
+
queQiaoServers: Schema<Schemastery.ObjectS<{
|
|
23
|
+
enable: Schema<boolean, boolean>;
|
|
24
|
+
rconServerHost: Schema<string, string>;
|
|
25
|
+
rconPassword: Schema<string, string>;
|
|
26
|
+
wsHost: Schema<string, string>;
|
|
27
|
+
Token: Schema<string, string>;
|
|
28
|
+
serverName: Schema<string, string>;
|
|
29
|
+
}>[], Schemastery.ObjectT<{
|
|
30
|
+
enable: Schema<boolean, boolean>;
|
|
31
|
+
rconServerHost: Schema<string, string>;
|
|
32
|
+
rconPassword: Schema<string, string>;
|
|
33
|
+
wsHost: Schema<string, string>;
|
|
34
|
+
Token: Schema<string, string>;
|
|
35
|
+
serverName: Schema<string, string>;
|
|
36
|
+
}>[]>;
|
|
37
|
+
}>, Schemastery.ObjectT<{
|
|
38
|
+
queQiaoEnable: Schema<boolean, boolean>;
|
|
39
|
+
queQiaoSendToChannel: Schema<string[], string[]>;
|
|
40
|
+
queQiaoWatchChannel: Schema<string[], string[]>;
|
|
41
|
+
queQiaoServers: Schema<Schemastery.ObjectS<{
|
|
42
|
+
enable: Schema<boolean, boolean>;
|
|
43
|
+
rconServerHost: Schema<string, string>;
|
|
44
|
+
rconPassword: Schema<string, string>;
|
|
45
|
+
wsHost: Schema<string, string>;
|
|
46
|
+
Token: Schema<string, string>;
|
|
47
|
+
serverName: Schema<string, string>;
|
|
48
|
+
}>[], Schemastery.ObjectT<{
|
|
49
|
+
enable: Schema<boolean, boolean>;
|
|
50
|
+
rconServerHost: Schema<string, string>;
|
|
51
|
+
rconPassword: Schema<string, string>;
|
|
52
|
+
wsHost: Schema<string, string>;
|
|
53
|
+
Token: Schema<string, string>;
|
|
54
|
+
serverName: Schema<string, string>;
|
|
55
|
+
}>[]>;
|
|
56
|
+
}>>;
|
|
18
57
|
}
|
package/lib/mcsManager/config.js
CHANGED
|
@@ -22,3 +22,24 @@ MCManagerConfig.Base = koishi_1.Schema.object({
|
|
|
22
22
|
.default(20)
|
|
23
23
|
.description('最大连接实例数'),
|
|
24
24
|
}).description('MCSMANAGER 基础配置');
|
|
25
|
+
MCManagerConfig.QueQiao = koishi_1.Schema.object({
|
|
26
|
+
queQiaoEnable: koishi_1.Schema.boolean().default(false).description('是否启用鹊桥'),
|
|
27
|
+
queQiaoSendToChannel: koishi_1.Schema.array(String).description('消息发送到目标群组格式{platform}:{groupId}'),
|
|
28
|
+
queQiaoWatchChannel: koishi_1.Schema.array(String).description('消息观察频道目标群组格式{platform}:{groupId}'),
|
|
29
|
+
queQiaoServers: koishi_1.Schema.array(koishi_1.Schema.object({
|
|
30
|
+
enable: koishi_1.Schema.boolean().default(false).description('-- 是否启用'),
|
|
31
|
+
rconServerHost: koishi_1.Schema.string()
|
|
32
|
+
.default('127.0.0.1:25575')
|
|
33
|
+
.description('-- rcon地址'),
|
|
34
|
+
rconPassword: koishi_1.Schema.string()
|
|
35
|
+
.role('secret')
|
|
36
|
+
.description('-- rcon服务器的密码(推荐设置)'),
|
|
37
|
+
wsHost: koishi_1.Schema.string()
|
|
38
|
+
.default('127.0.0.1:8080')
|
|
39
|
+
.description('-- websocket服务器的地址(服务器监听地址)'),
|
|
40
|
+
Token: koishi_1.Schema.string().description('-- websocket服务器的验证Token'),
|
|
41
|
+
serverName: koishi_1.Schema.string().description('-- 鹊桥配置文件中对应的server_name'),
|
|
42
|
+
}))
|
|
43
|
+
.default([])
|
|
44
|
+
.description('启用鹊桥的服务器列表,留空表示全部启用'),
|
|
45
|
+
}).description('MCSMANAGER 鹊桥配置');
|
|
@@ -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>;
|
|
@@ -10,6 +11,25 @@ export declare class MCManager {
|
|
|
10
11
|
mcManagerHost: Schema<string, string>;
|
|
11
12
|
mcManagerWs: Schema<string, string>;
|
|
12
13
|
mcManagerMaxConnectWs: Schema<number, number>;
|
|
14
|
+
}> | Schemastery.ObjectS<{
|
|
15
|
+
queQiaoEnable: Schema<boolean, boolean>;
|
|
16
|
+
queQiaoSendToChannel: Schema<string[], string[]>;
|
|
17
|
+
queQiaoWatchChannel: Schema<string[], string[]>;
|
|
18
|
+
queQiaoServers: Schema<Schemastery.ObjectS<{
|
|
19
|
+
enable: Schema<boolean, boolean>;
|
|
20
|
+
rconServerHost: Schema<string, string>;
|
|
21
|
+
rconPassword: Schema<string, string>;
|
|
22
|
+
wsHost: Schema<string, string>;
|
|
23
|
+
Token: Schema<string, string>;
|
|
24
|
+
serverName: Schema<string, string>;
|
|
25
|
+
}>[], Schemastery.ObjectT<{
|
|
26
|
+
enable: Schema<boolean, boolean>;
|
|
27
|
+
rconServerHost: Schema<string, string>;
|
|
28
|
+
rconPassword: Schema<string, string>;
|
|
29
|
+
wsHost: Schema<string, string>;
|
|
30
|
+
Token: Schema<string, string>;
|
|
31
|
+
serverName: Schema<string, string>;
|
|
32
|
+
}>[]>;
|
|
13
33
|
}>, {
|
|
14
34
|
mcManagerUsername: string;
|
|
15
35
|
mcManagerPassword: string;
|
|
@@ -17,10 +37,22 @@ export declare class MCManager {
|
|
|
17
37
|
mcManagerHost: string;
|
|
18
38
|
mcManagerWs: string;
|
|
19
39
|
mcManagerMaxConnectWs: number;
|
|
20
|
-
} & import("cosmokit").Dict
|
|
40
|
+
} & import("cosmokit").Dict & {
|
|
41
|
+
queQiaoEnable: boolean;
|
|
42
|
+
queQiaoSendToChannel: string[];
|
|
43
|
+
queQiaoWatchChannel: string[];
|
|
44
|
+
queQiaoServers: Schemastery.ObjectT<{
|
|
45
|
+
enable: Schema<boolean, boolean>;
|
|
46
|
+
rconServerHost: Schema<string, string>;
|
|
47
|
+
rconPassword: Schema<string, string>;
|
|
48
|
+
wsHost: Schema<string, string>;
|
|
49
|
+
Token: Schema<string, string>;
|
|
50
|
+
serverName: Schema<string, string>;
|
|
51
|
+
}>[];
|
|
52
|
+
}>;
|
|
21
53
|
private panel;
|
|
22
54
|
private bot;
|
|
23
|
-
constructor(ctx: Context, config: GLBotConfigType);
|
|
55
|
+
constructor(gl: GLBot, ctx: Context, config: GLBotConfigType);
|
|
24
56
|
initialize(): Promise<void>;
|
|
25
57
|
}
|
|
26
58
|
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() {
|
|
@@ -18,4 +21,7 @@ class MCManager {
|
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
exports.MCManager = MCManager;
|
|
21
|
-
MCManager.Config = koishi_1.Schema.intersect([
|
|
24
|
+
MCManager.Config = koishi_1.Schema.intersect([
|
|
25
|
+
config_1.MCManagerConfig.Base,
|
|
26
|
+
config_1.MCManagerConfig.QueQiao,
|
|
27
|
+
]);
|
|
@@ -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;
|