koishi-plugin-gl-bot 0.0.8 → 0.0.10
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/dist/index.js +1 -1
- package/lib/constants/env.d.ts +0 -0
- package/lib/constants/env.js +0 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +4 -0
- package/lib/gl/index.d.ts +83 -0
- package/lib/gl/index.js +51 -0
- package/lib/gl/index.type.d.ts +0 -0
- package/lib/gl/index.type.js +0 -0
- package/lib/gl/type.d.ts +0 -0
- package/lib/gl/type.js +0 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -20
- package/lib/mcsManager/api.d.ts +27 -0
- package/lib/mcsManager/api.js +111 -0
- package/lib/mcsManager/bot.d.ts +14 -0
- package/lib/mcsManager/bot.js +42 -0
- package/lib/mcsManager/commands/index.d.ts +10 -0
- package/lib/mcsManager/commands/index.js +19 -0
- package/lib/mcsManager/commands/list.d.ts +11 -0
- package/lib/mcsManager/commands/list.js +26 -0
- package/lib/mcsManager/commands/restart.d.ts +12 -0
- package/lib/mcsManager/commands/restart.js +61 -0
- package/lib/mcsManager/commands/start.d.ts +12 -0
- package/lib/mcsManager/commands/start.js +53 -0
- package/lib/mcsManager/config.d.ts +18 -0
- package/lib/mcsManager/config.js +24 -0
- package/lib/mcsManager/constants.d.ts +12 -0
- package/lib/mcsManager/constants.js +16 -0
- package/lib/mcsManager/index.d.ts +26 -0
- package/lib/mcsManager/index.js +21 -0
- package/lib/mcsManager/instance.d.ts +18 -0
- package/lib/mcsManager/instance.js +24 -0
- package/lib/mcsManager/panel.d.ts +24 -0
- package/lib/mcsManager/panel.js +123 -0
- package/lib/mcsManager/type.d.ts +115 -0
- package/lib/mcsManager/type.js +2 -0
- package/lib/mcsManager/ws.d.ts +24 -0
- package/lib/mcsManager/ws.js +116 -0
- package/lib/queQiao/index.d.ts +108 -0
- package/lib/queQiao/index.js +437 -0
- package/lib/queQiao/locale/en-US.json +1 -0
- package/lib/queQiao/locale/en-US.yml +9 -0
- package/lib/queQiao/locale/zh-CN.json +1 -0
- package/lib/queQiao/locale/zh-CN.yml +9 -0
- package/lib/queQiao/mcwss.d.ts +61 -0
- package/lib/queQiao/mcwss.js +260 -0
- package/lib/queQiao/values.d.ts +72 -0
- package/lib/queQiao/values.js +155 -0
- package/lib/utils/game.mc.d.ts +4 -0
- package/lib/utils/game.mc.js +29 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +17 -0
- package/package.json +11 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolveComponent as r,createBlock as a,openBlock as s,withCtx as _,createTextVNode as p}from"vue";const
|
|
1
|
+
import{resolveComponent as r,createBlock as a,openBlock as s,withCtx as _,createTextVNode as p}from"vue";const d=(t,e)=>{const o=t.__vccOpts||t;for(const[n,c]of e)o[n]=c;return o},f={};function l(t,e){const o=r("k-card");return s(),a(o,null,{default:_(()=>[...e[0]||(e[0]=[p("扩展内容22",-1)])]),_:1})}const m=d(f,[["render",l]]),x=t=>{t.page({name:"扩展页面",path:"/custom-page",component:m})};export{x as default};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IS_DEV: boolean;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare class GLBot {
|
|
3
|
+
private ctx;
|
|
4
|
+
private config;
|
|
5
|
+
static Config: Schema<Schemastery.ObjectS<{
|
|
6
|
+
wsServer: Schema<"客户端" | "服务端", "客户端" | "服务端">;
|
|
7
|
+
wsHost: Schema<string, string>;
|
|
8
|
+
wsPort: Schema<number, number>;
|
|
9
|
+
Token: Schema<string, string>;
|
|
10
|
+
serverName: Schema<string, string>;
|
|
11
|
+
joinMsg: Schema<string, string>;
|
|
12
|
+
event: Schema<number | readonly ("AsyncPlayerChatEvent" | "PlayerCommandPreprocessEvent" | "PlayerDeathEvent" | "PlayerJoinEvent" | "PlayerQuitEvent")[], number>;
|
|
13
|
+
maxReconnectCount: Schema<number, number>;
|
|
14
|
+
maxReconnectInterval: Schema<number, number>;
|
|
15
|
+
}> | Schemastery.ObjectS<{
|
|
16
|
+
rconEnable: Schema<boolean, boolean>;
|
|
17
|
+
rconServerHost: Schema<string, string>;
|
|
18
|
+
rconServerPort: Schema<number, number>;
|
|
19
|
+
rconPassword: Schema<string, string>;
|
|
20
|
+
alluser: Schema<boolean, boolean>;
|
|
21
|
+
superuser: Schema<string[], string[]>;
|
|
22
|
+
commonCmd: Schema<string[], string[]>;
|
|
23
|
+
cannotCmd: Schema<string[], string[]>;
|
|
24
|
+
}> | Schemastery.ObjectS<{
|
|
25
|
+
sendToChannel: Schema<string[], string[]>;
|
|
26
|
+
watchChannel: Schema<string[], string[]>;
|
|
27
|
+
sendprefix: Schema<string, string>;
|
|
28
|
+
cmdprefix: Schema<string, string>;
|
|
29
|
+
hideConnect: Schema<boolean, boolean>;
|
|
30
|
+
locale: Schema<"zh-CN" | "en-US", "zh-CN" | "en-US">;
|
|
31
|
+
}> | Schemastery.ObjectS<{
|
|
32
|
+
mcManagerUsername: Schema<string, string>;
|
|
33
|
+
mcManagerPassword: Schema<string, string>;
|
|
34
|
+
mcManagerKey: Schema<string, string>;
|
|
35
|
+
mcManagerHost: Schema<string, string>;
|
|
36
|
+
mcManagerWs: Schema<string, string>;
|
|
37
|
+
mcManagerMaxConnectWs: Schema<number, number>;
|
|
38
|
+
}>, {
|
|
39
|
+
wsServer: "客户端" | "服务端";
|
|
40
|
+
wsHost: string;
|
|
41
|
+
wsPort: number;
|
|
42
|
+
Token: string;
|
|
43
|
+
serverName: string;
|
|
44
|
+
joinMsg: string;
|
|
45
|
+
event: number;
|
|
46
|
+
maxReconnectCount: number;
|
|
47
|
+
maxReconnectInterval: number;
|
|
48
|
+
} & import("cosmokit").Dict & {
|
|
49
|
+
rconEnable: boolean;
|
|
50
|
+
rconServerHost: string;
|
|
51
|
+
rconServerPort: number;
|
|
52
|
+
rconPassword: string;
|
|
53
|
+
alluser: boolean;
|
|
54
|
+
superuser: string[];
|
|
55
|
+
commonCmd: string[];
|
|
56
|
+
cannotCmd: string[];
|
|
57
|
+
} & {
|
|
58
|
+
sendToChannel: string[];
|
|
59
|
+
watchChannel: string[];
|
|
60
|
+
sendprefix: string;
|
|
61
|
+
cmdprefix: string;
|
|
62
|
+
hideConnect: boolean;
|
|
63
|
+
locale: "zh-CN" | "en-US";
|
|
64
|
+
} & {
|
|
65
|
+
mcManagerUsername: string;
|
|
66
|
+
mcManagerPassword: string;
|
|
67
|
+
mcManagerKey: string;
|
|
68
|
+
mcManagerHost: string;
|
|
69
|
+
mcManagerWs: string;
|
|
70
|
+
mcManagerMaxConnectWs: number;
|
|
71
|
+
}>;
|
|
72
|
+
private mcSyncMsg;
|
|
73
|
+
private mcsManager;
|
|
74
|
+
constructor(ctx: Context, config: GLBotConfigType);
|
|
75
|
+
private initialize;
|
|
76
|
+
private globalCommand;
|
|
77
|
+
}
|
|
78
|
+
export declare class GLBotBase {
|
|
79
|
+
private ctx;
|
|
80
|
+
private config;
|
|
81
|
+
constructor(ctx: Context, config: GLBotConfigType);
|
|
82
|
+
}
|
|
83
|
+
export type GLBotConfigType = Schemastery.TypeS<typeof GLBot.Config>;
|
package/lib/gl/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GLBotBase = exports.GLBot = void 0;
|
|
7
|
+
const koishi_1 = require("koishi");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const mcsManager_1 = require("../mcsManager");
|
|
10
|
+
const queQiao_1 = __importDefault(require("../queQiao"));
|
|
11
|
+
const logger = new koishi_1.Logger('gl-bot');
|
|
12
|
+
class GLBot {
|
|
13
|
+
constructor(ctx, config) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.mcSyncMsg = new queQiao_1.default(ctx, config);
|
|
17
|
+
this.mcsManager = new mcsManager_1.MCManager(ctx, config);
|
|
18
|
+
this.initialize();
|
|
19
|
+
}
|
|
20
|
+
initialize() {
|
|
21
|
+
this.globalCommand();
|
|
22
|
+
}
|
|
23
|
+
globalCommand() {
|
|
24
|
+
this.ctx.on('message', session => {
|
|
25
|
+
if (constants_1.IS_DEV) {
|
|
26
|
+
// console.log(JSON.stringify(session, null, 2));
|
|
27
|
+
}
|
|
28
|
+
switch (session.content) {
|
|
29
|
+
case '环境变量':
|
|
30
|
+
session.send(`当前环境变量:${Object.entries(process.env)
|
|
31
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
32
|
+
.join('\n')}`);
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (~session.content.indexOf('群群')) {
|
|
38
|
+
session.send(`群群似杂鱼!大杂鱼喵`);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GLBot = GLBot;
|
|
44
|
+
GLBot.Config = koishi_1.Schema.intersect([queQiao_1.default.Config, mcsManager_1.MCManager.Config]);
|
|
45
|
+
class GLBotBase {
|
|
46
|
+
constructor(ctx, config) {
|
|
47
|
+
this.ctx = ctx;
|
|
48
|
+
this.config = config;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.GLBotBase = GLBotBase;
|
|
File without changes
|
|
File without changes
|
package/lib/gl/type.d.ts
ADDED
|
File without changes
|
package/lib/gl/type.js
ADDED
|
File without changes
|
package/lib/index.d.ts
ADDED
package/lib/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.name = "gl-bot";
|
|
8
|
-
exports.Config = koishi_1.Schema.object({});
|
|
9
|
-
function apply(ctx) {
|
|
10
|
-
ctx.inject(["console"], (ctx) => {
|
|
11
|
-
ctx.on("message", (session) => {
|
|
12
|
-
console.log(session.content);
|
|
13
|
-
if (session.content === "天王盖地虎1") {
|
|
14
|
-
session.send("宝塔镇河妖");
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
ctx.console.addEntry({
|
|
18
|
-
dev: (0, path_1.resolve)(__dirname, "../client/index.ts"),
|
|
19
|
-
prod: (0, path_1.resolve)(__dirname, "../lib"),
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
}
|
|
3
|
+
exports.name = void 0;
|
|
4
|
+
const gl_1 = require("./gl");
|
|
5
|
+
exports.name = 'gl-bot';
|
|
6
|
+
exports.default = gl_1.GLBot;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { HTTP } from 'koishi';
|
|
2
|
+
import { ServiceInstanceConnectAuth, ServiceRemoteInstanceItem, ServiceRemoteItem, UserInfo } from './type';
|
|
3
|
+
export declare class MCSManagerAPI {
|
|
4
|
+
private http;
|
|
5
|
+
private baseUrl;
|
|
6
|
+
private authCookie?;
|
|
7
|
+
userInfo: UserInfo;
|
|
8
|
+
get requestHeaders(): {
|
|
9
|
+
cookie: string;
|
|
10
|
+
'x-requested-with': string;
|
|
11
|
+
};
|
|
12
|
+
constructor(http: HTTP, baseUrl: string, authCookie?: string);
|
|
13
|
+
login(username: string, password: string): Promise<boolean>;
|
|
14
|
+
getUserInfo(): Promise<UserInfo>;
|
|
15
|
+
getServiceRemoteList(): Promise<ServiceRemoteItem[]>;
|
|
16
|
+
getServiceRemoteInstanceList(daemonId: string, options?: {
|
|
17
|
+
status?: string;
|
|
18
|
+
tag: string[];
|
|
19
|
+
instance_name?: string;
|
|
20
|
+
page?: number;
|
|
21
|
+
page_size?: number;
|
|
22
|
+
}): Promise<ServiceRemoteInstanceItem[]>;
|
|
23
|
+
getServiceInstanceConnectAuth(remoteUUID: string, instanceId: string): Promise<ServiceInstanceConnectAuth | null>;
|
|
24
|
+
restartRemoteInstance(daemonId: string, instanceId: string): Promise<boolean>;
|
|
25
|
+
stopRemoteInstance(daemonId: string, instanceId: string): Promise<boolean>;
|
|
26
|
+
startRemoteInstance(daemonId: string, instanceId: string): Promise<boolean>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCSManagerAPI = void 0;
|
|
4
|
+
class MCSManagerAPI {
|
|
5
|
+
get requestHeaders() {
|
|
6
|
+
return {
|
|
7
|
+
cookie: this.authCookie,
|
|
8
|
+
'x-requested-with': 'XMLHttpRequest',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
constructor(http, baseUrl, authCookie) {
|
|
12
|
+
this.http = http;
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
this.authCookie = authCookie;
|
|
15
|
+
}
|
|
16
|
+
async login(username, password) {
|
|
17
|
+
const result = await this.http(`${this.baseUrl}/auth/login`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
data: {
|
|
20
|
+
username,
|
|
21
|
+
password,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
if (result.status === 200 && result.headers.get('set-cookie')) {
|
|
25
|
+
const cookieString = result.headers.get('set-cookie');
|
|
26
|
+
this.authCookie = extractCookiesWithRegex(cookieString);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async getUserInfo() {
|
|
32
|
+
const result = await this.http(`${this.baseUrl}/auth/`, {
|
|
33
|
+
headers: this.requestHeaders,
|
|
34
|
+
});
|
|
35
|
+
if (result.status === 200) {
|
|
36
|
+
this.userInfo = result.data.data;
|
|
37
|
+
return this.userInfo;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
async getServiceRemoteList() {
|
|
42
|
+
return ((await this.http(`${this.baseUrl}/service/remote_services_list`, {
|
|
43
|
+
headers: this.requestHeaders,
|
|
44
|
+
params: {
|
|
45
|
+
token: this.userInfo.token,
|
|
46
|
+
},
|
|
47
|
+
})).data.data ?? []);
|
|
48
|
+
}
|
|
49
|
+
async getServiceRemoteInstanceList(daemonId, options) {
|
|
50
|
+
return ((await this.http(`${this.baseUrl}/service/remote_service_instances`, {
|
|
51
|
+
headers: this.requestHeaders,
|
|
52
|
+
params: {
|
|
53
|
+
daemonId,
|
|
54
|
+
page: options?.page || 1,
|
|
55
|
+
page_size: options?.page_size || 999,
|
|
56
|
+
status: options?.status || '',
|
|
57
|
+
instance_name: options?.instance_name || '',
|
|
58
|
+
tag: JSON.stringify(options?.tag || []),
|
|
59
|
+
token: this.userInfo.token,
|
|
60
|
+
},
|
|
61
|
+
})).data?.data?.data ?? []);
|
|
62
|
+
}
|
|
63
|
+
async getServiceInstanceConnectAuth(remoteUUID, instanceId) {
|
|
64
|
+
return ((await this.http(`${this.baseUrl}/protected_instance/stream_channel`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
headers: this.requestHeaders,
|
|
67
|
+
params: {
|
|
68
|
+
remote_uuid: remoteUUID,
|
|
69
|
+
uuid: instanceId,
|
|
70
|
+
token: this.userInfo.token,
|
|
71
|
+
},
|
|
72
|
+
})).data.data ?? null);
|
|
73
|
+
}
|
|
74
|
+
async restartRemoteInstance(daemonId, instanceId) {
|
|
75
|
+
return ((await this.http(`${this.baseUrl}/protected_instance/restart`, {
|
|
76
|
+
headers: this.requestHeaders,
|
|
77
|
+
params: {
|
|
78
|
+
daemonId,
|
|
79
|
+
uuid: instanceId,
|
|
80
|
+
token: this.userInfo.token,
|
|
81
|
+
},
|
|
82
|
+
})).data.data?.instanceUuid === instanceId);
|
|
83
|
+
}
|
|
84
|
+
async stopRemoteInstance(daemonId, instanceId) {
|
|
85
|
+
return ((await this.http(`${this.baseUrl}/protected_instance/stop`, {
|
|
86
|
+
headers: this.requestHeaders,
|
|
87
|
+
params: {
|
|
88
|
+
daemonId,
|
|
89
|
+
uuid: instanceId,
|
|
90
|
+
token: this.userInfo.token,
|
|
91
|
+
},
|
|
92
|
+
})).data.data?.instanceUuid === instanceId);
|
|
93
|
+
}
|
|
94
|
+
async startRemoteInstance(daemonId, instanceId) {
|
|
95
|
+
return ((await this.http(`${this.baseUrl}/protected_instance/open`, {
|
|
96
|
+
headers: this.requestHeaders,
|
|
97
|
+
params: {
|
|
98
|
+
daemonId,
|
|
99
|
+
uuid: instanceId,
|
|
100
|
+
token: this.userInfo.token,
|
|
101
|
+
},
|
|
102
|
+
})).data.data?.instanceUuid === instanceId);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.MCSManagerAPI = MCSManagerAPI;
|
|
106
|
+
function extractCookiesWithRegex(cookieStr) {
|
|
107
|
+
return cookieStr
|
|
108
|
+
.match(/(\S+=\S+;)/g)
|
|
109
|
+
.filter(v => v !== 'path=/;')
|
|
110
|
+
.join(' ');
|
|
111
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { GLBotConfigType } from '../gl';
|
|
3
|
+
import { MCBotListCommand, MCBotRestartCommand, MCBotStartCommand } from './commands';
|
|
4
|
+
import { MCSManagerPanel } from './panel';
|
|
5
|
+
export declare class MCSManagerBot {
|
|
6
|
+
readonly ctx: Context;
|
|
7
|
+
readonly config: GLBotConfigType;
|
|
8
|
+
readonly panel: MCSManagerPanel;
|
|
9
|
+
constructor(ctx: Context, config: GLBotConfigType, panel: MCSManagerPanel);
|
|
10
|
+
help(): string[];
|
|
11
|
+
commands(): (typeof MCBotListCommand | typeof MCBotRestartCommand | typeof MCBotStartCommand)[];
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
private registerCommands;
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCSManagerBot = void 0;
|
|
4
|
+
const commands_1 = require("./commands");
|
|
5
|
+
class MCSManagerBot {
|
|
6
|
+
constructor(ctx, config, panel) {
|
|
7
|
+
this.ctx = ctx;
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.panel = panel;
|
|
10
|
+
this.initialize();
|
|
11
|
+
}
|
|
12
|
+
help() {
|
|
13
|
+
return [
|
|
14
|
+
'服务器 管理指令:',
|
|
15
|
+
'/服务器 列表',
|
|
16
|
+
'/服务器 开启 <模糊名>',
|
|
17
|
+
'/服务器 关闭 <模糊名>',
|
|
18
|
+
'/服务器 重启 <模糊名>',
|
|
19
|
+
'/服务器 备份 <模糊名>',
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
commands() {
|
|
23
|
+
return [commands_1.MCBotRestartCommand, commands_1.MCBotListCommand, commands_1.MCBotStartCommand];
|
|
24
|
+
}
|
|
25
|
+
async initialize() {
|
|
26
|
+
this.ctx.on('ready', async () => {
|
|
27
|
+
this.registerCommands();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
registerCommands() {
|
|
31
|
+
for (const Command of this.commands()) {
|
|
32
|
+
new Command(this);
|
|
33
|
+
}
|
|
34
|
+
// this.ctx
|
|
35
|
+
// .command('/服务器 <action> [...name]')
|
|
36
|
+
// .option('debug', '-d')
|
|
37
|
+
// .action(({ options }, action, ...name) => {
|
|
38
|
+
// return `收到指令:${action} ${name.join(' ')},调试模式:${options.debug}`;
|
|
39
|
+
// });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.MCSManagerBot = MCSManagerBot;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { GLBotConfigType } from '../../gl';
|
|
3
|
+
export { MCBotListCommand } from './list';
|
|
4
|
+
export { MCBotRestartCommand } from './restart';
|
|
5
|
+
export { MCBotStartCommand } from './start';
|
|
6
|
+
export declare class MCBotCommandBase {
|
|
7
|
+
readonly ctx: Context;
|
|
8
|
+
readonly config: GLBotConfigType;
|
|
9
|
+
constructor(ctx: Context, config: GLBotConfigType);
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotCommandBase = exports.MCBotStartCommand = exports.MCBotRestartCommand = exports.MCBotListCommand = void 0;
|
|
4
|
+
const koishi_1 = require("koishi");
|
|
5
|
+
var list_1 = require("./list");
|
|
6
|
+
Object.defineProperty(exports, "MCBotListCommand", { enumerable: true, get: function () { return list_1.MCBotListCommand; } });
|
|
7
|
+
var restart_1 = require("./restart");
|
|
8
|
+
Object.defineProperty(exports, "MCBotRestartCommand", { enumerable: true, get: function () { return restart_1.MCBotRestartCommand; } });
|
|
9
|
+
var start_1 = require("./start");
|
|
10
|
+
Object.defineProperty(exports, "MCBotStartCommand", { enumerable: true, get: function () { return start_1.MCBotStartCommand; } });
|
|
11
|
+
const logger = new koishi_1.Logger('mcsmanager-command');
|
|
12
|
+
class MCBotCommandBase {
|
|
13
|
+
constructor(ctx, config) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.config = config;
|
|
16
|
+
// logger.info('注册 MCSManager 服务器管理指令...');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.MCBotCommandBase = MCBotCommandBase;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotListCommand = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
/**
|
|
6
|
+
* 服务器列表指令
|
|
7
|
+
*
|
|
8
|
+
* @example 服务器 列表
|
|
9
|
+
*/
|
|
10
|
+
class MCBotListCommand {
|
|
11
|
+
constructor(bot) {
|
|
12
|
+
this.bot = bot;
|
|
13
|
+
bot.ctx.command('服务器.列表 <status>').action(async (_, status) => {
|
|
14
|
+
return await this.handle(status);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async handle(status) {
|
|
18
|
+
await this.bot.panel.handleRemoteServices();
|
|
19
|
+
const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !status ||
|
|
20
|
+
constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === status);
|
|
21
|
+
return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
|
|
22
|
+
.map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
|
|
23
|
+
.join('\n')}\n ${'='.repeat(20)} `;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MCBotListCommand = MCBotListCommand;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../bot';
|
|
3
|
+
/**
|
|
4
|
+
* 服务器重启指令
|
|
5
|
+
*
|
|
6
|
+
* @example 服务器 重启 神话
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCBotRestartCommand {
|
|
9
|
+
private readonly bot;
|
|
10
|
+
constructor(bot: MCSManagerBot);
|
|
11
|
+
handle(session: Session<never, never, Context>, name: string): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCBotRestartCommand = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
// const logger = new Logger('mcsmanager-reset');
|
|
6
|
+
const tempSelections = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* 服务器重启指令
|
|
9
|
+
*
|
|
10
|
+
* @example 服务器 重启 神话
|
|
11
|
+
*/
|
|
12
|
+
class MCBotRestartCommand {
|
|
13
|
+
constructor(bot) {
|
|
14
|
+
this.bot = bot;
|
|
15
|
+
bot.ctx
|
|
16
|
+
.command('服务器.重启 <name...>')
|
|
17
|
+
.action(async ({ session }, ...name) => {
|
|
18
|
+
return await this.handle(session, name.join(' '));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async handle(session, name) {
|
|
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
|
+
switch (cfg.status) {
|
|
46
|
+
// 关闭状态:启动
|
|
47
|
+
case constants_1.RemoteInstanceStatusEnum.RUNNING:
|
|
48
|
+
await targetInstance.instance.restartInstance();
|
|
49
|
+
this.bot.panel.handleRemoteServices();
|
|
50
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送重启操作`;
|
|
51
|
+
// 启动状态:重启
|
|
52
|
+
case constants_1.RemoteInstanceStatusEnum.STOPPED:
|
|
53
|
+
await targetInstance.instance.startInstance();
|
|
54
|
+
this.bot.panel.handleRemoteServices();
|
|
55
|
+
return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
|
|
56
|
+
default:
|
|
57
|
+
return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行重启操作`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.MCBotRestartCommand = MCBotRestartCommand;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Context, Session } from 'koishi';
|
|
2
|
+
import { MCSManagerBot } from '../bot';
|
|
3
|
+
/**
|
|
4
|
+
* 服务器启动指令
|
|
5
|
+
*
|
|
6
|
+
* @example 服务器 启动 神话
|
|
7
|
+
*/
|
|
8
|
+
export declare class MCBotStartCommand {
|
|
9
|
+
private readonly bot;
|
|
10
|
+
constructor(bot: MCSManagerBot);
|
|
11
|
+
handle(session: Session<never, never, Context>, name: string): Promise<string>;
|
|
12
|
+
}
|
|
@@ -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 tempSelections = new Map();
|
|
7
|
+
/**
|
|
8
|
+
* 服务器启动指令
|
|
9
|
+
*
|
|
10
|
+
* @example 服务器 启动 神话
|
|
11
|
+
*/
|
|
12
|
+
class MCBotStartCommand {
|
|
13
|
+
constructor(bot) {
|
|
14
|
+
this.bot = bot;
|
|
15
|
+
bot.ctx
|
|
16
|
+
.command('服务器.启动 <name...>')
|
|
17
|
+
.action(async ({ session }, ...name) => {
|
|
18
|
+
return await this.handle(session, name.join(' '));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async handle(session, name) {
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from 'koishi';
|
|
2
|
+
export declare class MCManagerConfig {
|
|
3
|
+
static Base: Schema<Schemastery.ObjectS<{
|
|
4
|
+
mcManagerUsername: Schema<string, string>;
|
|
5
|
+
mcManagerPassword: Schema<string, string>;
|
|
6
|
+
mcManagerKey: Schema<string, string>;
|
|
7
|
+
mcManagerHost: Schema<string, string>;
|
|
8
|
+
mcManagerWs: Schema<string, string>;
|
|
9
|
+
mcManagerMaxConnectWs: Schema<number, number>;
|
|
10
|
+
}>, Schemastery.ObjectT<{
|
|
11
|
+
mcManagerUsername: Schema<string, string>;
|
|
12
|
+
mcManagerPassword: Schema<string, string>;
|
|
13
|
+
mcManagerKey: Schema<string, string>;
|
|
14
|
+
mcManagerHost: Schema<string, string>;
|
|
15
|
+
mcManagerWs: Schema<string, string>;
|
|
16
|
+
mcManagerMaxConnectWs: Schema<number, number>;
|
|
17
|
+
}>>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCManagerConfig = void 0;
|
|
4
|
+
const koishi_1 = require("koishi");
|
|
5
|
+
class MCManagerConfig {
|
|
6
|
+
}
|
|
7
|
+
exports.MCManagerConfig = MCManagerConfig;
|
|
8
|
+
MCManagerConfig.Base = koishi_1.Schema.object({
|
|
9
|
+
mcManagerUsername: koishi_1.Schema.string().default('admin').description('用户名'),
|
|
10
|
+
mcManagerPassword: koishi_1.Schema.string()
|
|
11
|
+
.role('secret')
|
|
12
|
+
.default('admin')
|
|
13
|
+
.description('密码'),
|
|
14
|
+
mcManagerKey: koishi_1.Schema.string().role('secret').description('KEY'),
|
|
15
|
+
mcManagerHost: koishi_1.Schema.string()
|
|
16
|
+
.default('http://localhost:23333/api')
|
|
17
|
+
.description('地址'),
|
|
18
|
+
mcManagerWs: koishi_1.Schema.string()
|
|
19
|
+
.default('ws://localhost:24444')
|
|
20
|
+
.description('WebSocket 地址'),
|
|
21
|
+
mcManagerMaxConnectWs: koishi_1.Schema.number()
|
|
22
|
+
.default(20)
|
|
23
|
+
.description('最大连接实例数'),
|
|
24
|
+
}).description('MCSMANAGER 基础配置');
|