koishi-plugin-gl-bot 0.0.11 → 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.
Files changed (66) hide show
  1. package/lib/gl/index.d.ts +36 -55
  2. package/lib/gl/index.js +4 -6
  3. package/lib/gl/queqiao.adapter.d.ts +11 -0
  4. package/lib/gl/queqiao.adapter.js +41 -0
  5. package/lib/mcsManager/api.d.ts +1 -0
  6. package/lib/mcsManager/api.js +13 -1
  7. package/lib/mcsManager/bot.d.ts +2 -2
  8. package/lib/mcsManager/bot.js +1 -0
  9. package/lib/mcsManager/commands/index.d.ts +1 -0
  10. package/lib/mcsManager/commands/index.js +3 -1
  11. package/lib/mcsManager/commands/mc/health.d.ts +16 -0
  12. package/lib/mcsManager/commands/mc/health.js +46 -0
  13. package/lib/mcsManager/commands/mc/list.d.ts +1 -0
  14. package/lib/mcsManager/commands/mc/list.js +21 -6
  15. package/lib/mcsManager/commands/mc/online.d.ts +6 -1
  16. package/lib/mcsManager/commands/mc/online.js +49 -12
  17. package/lib/mcsManager/config.d.ts +39 -0
  18. package/lib/mcsManager/config.js +21 -0
  19. package/lib/mcsManager/index.d.ts +32 -1
  20. package/lib/mcsManager/index.js +4 -1
  21. package/lib/mcsManager/type.d.ts +2 -0
  22. package/lib/queQiao/index.d.ts +47 -38
  23. package/lib/queQiao/index.js +82 -47
  24. package/lib/queQiao/locale/zh-CN.json +1 -1
  25. package/lib/queQiao/locale/zh-CN.yml +4 -4
  26. package/lib/queQiao/mcwss.d.ts +12 -9
  27. package/lib/queQiao/mcwss.js +34 -2
  28. package/lib/queQiao/values.js +2 -2
  29. package/lib/utils/game.mc.js +5 -4
  30. package/package.json +1 -1
  31. package/lib/constants/env.d.ts +0 -0
  32. package/lib/constants/env.js +0 -0
  33. package/lib/gl/index.type.d.ts +0 -0
  34. package/lib/gl/index.type.js +0 -0
  35. package/lib/mcsManager/commands/create.d.ts +0 -16
  36. package/lib/mcsManager/commands/create.js +0 -135
  37. package/lib/mcsManager/commands/list copy.d.ts +0 -13
  38. package/lib/mcsManager/commands/list copy.js +0 -34
  39. package/lib/mcsManager/commands/list.d.ts +0 -14
  40. package/lib/mcsManager/commands/list.js +0 -35
  41. package/lib/mcsManager/commands/mc/restart copy.d.ts +0 -15
  42. package/lib/mcsManager/commands/mc/restart copy.js +0 -62
  43. package/lib/mcsManager/commands/mc copy/create.d.ts +0 -16
  44. package/lib/mcsManager/commands/mc copy/create.js +0 -135
  45. package/lib/mcsManager/commands/mc copy/list.d.ts +0 -14
  46. package/lib/mcsManager/commands/mc copy/list.js +0 -35
  47. package/lib/mcsManager/commands/mc copy/restart.d.ts +0 -15
  48. package/lib/mcsManager/commands/mc copy/restart.js +0 -62
  49. package/lib/mcsManager/commands/mc copy/start.d.ts +0 -15
  50. package/lib/mcsManager/commands/mc copy/start.js +0 -54
  51. package/lib/mcsManager/commands/mc copy/stop.d.ts +0 -15
  52. package/lib/mcsManager/commands/mc copy/stop.js +0 -54
  53. package/lib/mcsManager/commands/restart.d.ts +0 -15
  54. package/lib/mcsManager/commands/restart.js +0 -62
  55. package/lib/mcsManager/commands/start copy.d.ts +0 -14
  56. package/lib/mcsManager/commands/start copy.js +0 -53
  57. package/lib/mcsManager/commands/start.d.ts +0 -15
  58. package/lib/mcsManager/commands/start.js +0 -54
  59. package/lib/mcsManager/commands/stop.d.ts +0 -15
  60. package/lib/mcsManager/commands/stop.js +0 -54
  61. package/lib/utils/file.download.d.ts +0 -47
  62. package/lib/utils/file.download.js +0 -142
  63. package/lib/utils/file.examples.d.ts +0 -12
  64. package/lib/utils/file.examples.js +0 -73
  65. package/lib/utils/napcat.file.d.ts +0 -63
  66. package/lib/utils/napcat.file.js +0 -133
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotCreateCommand = void 0;
4
- const fs_1 = require("fs");
5
- const koishi_1 = require("koishi");
6
- const utils_1 = require("../../utils");
7
- const base_1 = require("./base");
8
- /**
9
- * 服务器创建指令
10
- *
11
- * @example 服务器 创建
12
- */
13
- class MCBotCreateCommand extends base_1.MCBotCommandBase {
14
- constructor(bot) {
15
- super(bot);
16
- this.bot = bot;
17
- this.command = ['服务器.创建 <name...>', 'MC.创建 <name...>'];
18
- this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
- this.initialize();
20
- }
21
- async handle({ args, session, ...opt }, status) {
22
- const { elements } = session?.event?.message?.quote ?? {};
23
- if (elements.length > 0) {
24
- const fileElements = koishi_1.h.select(elements, 'file');
25
- if (fileElements.length > 0) {
26
- const results = [`检测到 ${fileElements.length} 个文件:`];
27
- for (const [index, element] of fileElements.entries()) {
28
- const fileInfo = {
29
- src: element.attrs?.src,
30
- fileName: element.attrs?.file || element.attrs?.src,
31
- fileId: element.attrs?.['fileId'],
32
- fileSize: element.attrs?.['fileSize'],
33
- };
34
- results.push(`\n文件 ${index + 1}:`);
35
- results.push(` 名称: ${fileInfo.fileName}`);
36
- results.push(` 文件ID: ${fileInfo.fileId}`);
37
- if (fileInfo.fileSize) {
38
- const sizeInMB = (parseInt(fileInfo.fileSize, 10) /
39
- 1024 /
40
- 1024).toFixed(2);
41
- results.push(` 大小: ${sizeInMB} MB`);
42
- }
43
- results.push(`-> 开始尝试下载群文件...`);
44
- session.send(results.join('\n'));
45
- results.length = 0;
46
- // 尝试下载文件
47
- try {
48
- const result = await this.bot.manager.gl.napCat.api.getFile(fileInfo.fileId);
49
- const fileExists = result ? (0, fs_1.existsSync)(result?.file) : false;
50
- if (result && fileExists) {
51
- session.send('下载完毕,正在解压并创建服务器实例...');
52
- }
53
- else {
54
- results.push(`状态: 处理失败`);
55
- }
56
- }
57
- catch (error) {
58
- results.push(` 状态: 处理失败 ${error}`);
59
- }
60
- }
61
- return results.join('\n');
62
- }
63
- }
64
- return `需要引用包含服务端压缩包的文件喵~`;
65
- }
66
- async downloadAndProcessFile(fileInfo, session) {
67
- const { fileId, fileName } = fileInfo;
68
- console.log(`开始处理文件: ${fileName}, fileId: ${fileId}, platform: ${session.platform}`);
69
- // 方法1: 如果fileId是URL,直接下载
70
- if (fileId && fileId.startsWith('http')) {
71
- try {
72
- const response = await this.bot.ctx.http.get(fileId, {
73
- responseType: 'arraybuffer',
74
- timeout: 60000, // 60秒超时
75
- });
76
- console.log(`直接URL下载文件成功: ${fileName}, 大小: ${response.byteLength} 字节`);
77
- return;
78
- }
79
- catch (error) {
80
- console.warn(`直接URL下载失败: ${error.message}`);
81
- return `直接URL下载失败: ${error.message}`;
82
- }
83
- }
84
- // 方法2: NapCat/OneBot 群文件下载支持
85
- if (session.platform === 'onebot') {
86
- try {
87
- console.log(`使用 NapCat 工具下载群文件...`);
88
- const buffer = await utils_1.NapCatFileDownloader.downloadGroupFile(session, fileId, fileName, this.bot.ctx);
89
- if (buffer) {
90
- console.log(`通过 NapCat 下载文件成功: ${fileName}, 大小: ${buffer.length} 字节`);
91
- // 可选: 保存文件到本地
92
- // const savePath = `./downloads/server-files/${fileName}`;
93
- // const fs = require('fs');
94
- // const path = require('path');
95
- // if (!fs.existsSync(path.dirname(savePath))) {
96
- // fs.mkdirSync(path.dirname(savePath), { recursive: true });
97
- // }
98
- // fs.writeFileSync(savePath, buffer);
99
- return;
100
- }
101
- }
102
- catch (error) {
103
- console.warn('NapCat 下载失败:', error.message);
104
- // 继续尝试其他方法
105
- }
106
- }
107
- // 方法3: 尝试构造可能的QQ群文件URL
108
- if (fileId && (fileId.startsWith('/') || fileId.includes('-'))) {
109
- const possibleUrls = [
110
- `https://groupfiles.qq.com${fileId}`,
111
- `https://grouptalk.c2c.qq.com${fileId}`,
112
- `https://gchat.qpic.cn${fileId}`,
113
- ];
114
- for (const url of possibleUrls) {
115
- try {
116
- const response = await this.bot.ctx.http.get(url, {
117
- responseType: 'arraybuffer',
118
- timeout: 10000,
119
- });
120
- console.log(`通过构造URL下载文件成功: ${fileName}, URL: ${url}`);
121
- return;
122
- }
123
- catch (error) {
124
- console.warn(`URL ${url} 下载失败:`, error.message);
125
- continue;
126
- }
127
- }
128
- }
129
- // 方法4: 记录文件信息但无法下载
130
- console.log(`文件信息记录: ${fileName}, fileId: ${fileId}`);
131
- console.log(`平台: ${session.platform}, 当前配置下无法自动下载此文件`);
132
- return '无法获取文件下载链接,请检查 NapCat 配置或手动下载';
133
- }
134
- }
135
- exports.MCBotCreateCommand = MCBotCreateCommand;
@@ -1,13 +0,0 @@
1
- import { MCSManagerBot } from '../bot';
2
- import { MCBotCommandBase } from './base';
3
- /**
4
- * 服务器列表指令
5
- *
6
- * @example 服务器 列表
7
- */
8
- export declare class MCBotListCommand extends MCBotCommandBase {
9
- readonly bot: MCSManagerBot;
10
- command: string;
11
- constructor(bot: MCSManagerBot);
12
- handle(_: any, status?: string[]): Promise<string>;
13
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotListCommand = void 0;
4
- const utils_1 = require("../../utils");
5
- const constants_1 = require("../constants");
6
- const base_1 = require("./base");
7
- /**
8
- * 服务器列表指令
9
- *
10
- * @example 服务器 列表
11
- */
12
- class MCBotListCommand extends base_1.MCBotCommandBase {
13
- constructor(bot) {
14
- super(bot);
15
- this.bot = bot;
16
- this.command = '服务器.列表 <status>';
17
- this.initialize();
18
- }
19
- async handle(_, status) {
20
- await this.bot.panel.handleRemoteServices();
21
- const filteredStatus = status?.at(0);
22
- const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
23
- constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
24
- return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
25
- .map(item => {
26
- const { cfg } = item.instance;
27
- const duration = (0, utils_1.formatDuration)(cfg.config.lastDatetime -
28
- new Date(cfg.config.createDatetime).getTime());
29
- return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
30
- })
31
- .join('\n')}\n ${'='.repeat(28)} `;
32
- }
33
- }
34
- exports.MCBotListCommand = MCBotListCommand;
@@ -1,14 +0,0 @@
1
- import { MCSManagerBot } from '../bot';
2
- import { MCBotCommandBase } from './base';
3
- /**
4
- * 服务器列表指令
5
- *
6
- * @example 服务器 列表
7
- */
8
- export declare class MCBotListCommand extends MCBotCommandBase {
9
- readonly bot: MCSManagerBot;
10
- command: string[];
11
- roles: any[];
12
- constructor(bot: MCSManagerBot);
13
- handle(_: any, status?: string[]): Promise<string>;
14
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotListCommand = void 0;
4
- const utils_1 = require("../../utils");
5
- const constants_1 = require("../constants");
6
- const base_1 = require("./base");
7
- /**
8
- * 服务器列表指令
9
- *
10
- * @example 服务器 列表
11
- */
12
- class MCBotListCommand extends base_1.MCBotCommandBase {
13
- constructor(bot) {
14
- super(bot);
15
- this.bot = bot;
16
- this.command = ['服务器.列表 <status>', 'MC.列表 <status>'];
17
- this.roles = [];
18
- this.initialize();
19
- }
20
- async handle(_, status) {
21
- await this.bot.panel.handleRemoteServices();
22
- const filteredStatus = status?.at(0);
23
- const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
24
- constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
25
- return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
26
- .map(item => {
27
- const { cfg } = item.instance;
28
- const duration = (0, utils_1.formatDuration)(cfg.config.lastDatetime -
29
- new Date(cfg.config.createDatetime).getTime());
30
- return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
31
- })
32
- .join('\n')}\n ${'='.repeat(28)} `;
33
- }
34
- }
35
- exports.MCBotListCommand = MCBotListCommand;
@@ -1,15 +0,0 @@
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
- }
@@ -1,62 +0,0 @@
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;
@@ -1,16 +0,0 @@
1
- import { Argv } from 'koishi';
2
- import { MCSManagerBot } from '../../bot';
3
- import { MCBotCommandBase, MCBotCommandRole } from '../base';
4
- /**
5
- * 服务器创建指令
6
- *
7
- * @example 服务器 创建
8
- */
9
- export declare class MCBotCreateCommand extends MCBotCommandBase {
10
- readonly bot: MCSManagerBot;
11
- command: string[];
12
- roles: MCBotCommandRole[];
13
- constructor(bot: MCSManagerBot);
14
- handle({ args, session, ...opt }: Argv, status?: string[]): Promise<string>;
15
- private downloadAndProcessFile;
16
- }
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotCreateCommand = void 0;
4
- const fs_1 = require("fs");
5
- const koishi_1 = require("koishi");
6
- const utils_1 = require("../../../utils");
7
- const base_1 = require("../base");
8
- /**
9
- * 服务器创建指令
10
- *
11
- * @example 服务器 创建
12
- */
13
- class MCBotCreateCommand extends base_1.MCBotCommandBase {
14
- constructor(bot) {
15
- super(bot);
16
- this.bot = bot;
17
- this.command = ['服务器.创建 <name...>', 'MC.创建 <name...>'];
18
- this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
- this.initialize();
20
- }
21
- async handle({ args, session, ...opt }, status) {
22
- const { elements } = session?.event?.message?.quote ?? {};
23
- if (elements.length > 0) {
24
- const fileElements = koishi_1.h.select(elements, 'file');
25
- if (fileElements.length > 0) {
26
- const results = [`检测到 ${fileElements.length} 个文件:`];
27
- for (const [index, element] of fileElements.entries()) {
28
- const fileInfo = {
29
- src: element.attrs?.src,
30
- fileName: element.attrs?.file || element.attrs?.src,
31
- fileId: element.attrs?.['fileId'],
32
- fileSize: element.attrs?.['fileSize'],
33
- };
34
- results.push(`\n文件 ${index + 1}:`);
35
- results.push(` 名称: ${fileInfo.fileName}`);
36
- results.push(` 文件ID: ${fileInfo.fileId}`);
37
- if (fileInfo.fileSize) {
38
- const sizeInMB = (parseInt(fileInfo.fileSize, 10) /
39
- 1024 /
40
- 1024).toFixed(2);
41
- results.push(` 大小: ${sizeInMB} MB`);
42
- }
43
- results.push(`-> 开始尝试下载群文件...`);
44
- session.send(results.join('\n'));
45
- results.length = 0;
46
- // 尝试下载文件
47
- try {
48
- const result = await this.bot.manager.gl.napCat.api.getFile(fileInfo.fileId);
49
- const fileExists = result ? (0, fs_1.existsSync)(result?.file) : false;
50
- if (result && fileExists) {
51
- session.send('下载完毕,正在解压并创建服务器实例...');
52
- }
53
- else {
54
- results.push(`状态: 处理失败`);
55
- }
56
- }
57
- catch (error) {
58
- results.push(` 状态: 处理失败 ${error}`);
59
- }
60
- }
61
- return results.join('\n');
62
- }
63
- }
64
- return `需要引用包含服务端压缩包的文件喵~`;
65
- }
66
- async downloadAndProcessFile(fileInfo, session) {
67
- const { fileId, fileName } = fileInfo;
68
- console.log(`开始处理文件: ${fileName}, fileId: ${fileId}, platform: ${session.platform}`);
69
- // 方法1: 如果fileId是URL,直接下载
70
- if (fileId && fileId.startsWith('http')) {
71
- try {
72
- const response = await this.bot.ctx.http.get(fileId, {
73
- responseType: 'arraybuffer',
74
- timeout: 60000, // 60秒超时
75
- });
76
- console.log(`直接URL下载文件成功: ${fileName}, 大小: ${response.byteLength} 字节`);
77
- return;
78
- }
79
- catch (error) {
80
- console.warn(`直接URL下载失败: ${error.message}`);
81
- return `直接URL下载失败: ${error.message}`;
82
- }
83
- }
84
- // 方法2: NapCat/OneBot 群文件下载支持
85
- if (session.platform === 'onebot') {
86
- try {
87
- console.log(`使用 NapCat 工具下载群文件...`);
88
- const buffer = await utils_1.NapCatFileDownloader.downloadGroupFile(session, fileId, fileName, this.bot.ctx);
89
- if (buffer) {
90
- console.log(`通过 NapCat 下载文件成功: ${fileName}, 大小: ${buffer.length} 字节`);
91
- // 可选: 保存文件到本地
92
- // const savePath = `./downloads/server-files/${fileName}`;
93
- // const fs = require('fs');
94
- // const path = require('path');
95
- // if (!fs.existsSync(path.dirname(savePath))) {
96
- // fs.mkdirSync(path.dirname(savePath), { recursive: true });
97
- // }
98
- // fs.writeFileSync(savePath, buffer);
99
- return;
100
- }
101
- }
102
- catch (error) {
103
- console.warn('NapCat 下载失败:', error.message);
104
- // 继续尝试其他方法
105
- }
106
- }
107
- // 方法3: 尝试构造可能的QQ群文件URL
108
- if (fileId && (fileId.startsWith('/') || fileId.includes('-'))) {
109
- const possibleUrls = [
110
- `https://groupfiles.qq.com${fileId}`,
111
- `https://grouptalk.c2c.qq.com${fileId}`,
112
- `https://gchat.qpic.cn${fileId}`,
113
- ];
114
- for (const url of possibleUrls) {
115
- try {
116
- const response = await this.bot.ctx.http.get(url, {
117
- responseType: 'arraybuffer',
118
- timeout: 10000,
119
- });
120
- console.log(`通过构造URL下载文件成功: ${fileName}, URL: ${url}`);
121
- return;
122
- }
123
- catch (error) {
124
- console.warn(`URL ${url} 下载失败:`, error.message);
125
- continue;
126
- }
127
- }
128
- }
129
- // 方法4: 记录文件信息但无法下载
130
- console.log(`文件信息记录: ${fileName}, fileId: ${fileId}`);
131
- console.log(`平台: ${session.platform}, 当前配置下无法自动下载此文件`);
132
- return '无法获取文件下载链接,请检查 NapCat 配置或手动下载';
133
- }
134
- }
135
- exports.MCBotCreateCommand = MCBotCreateCommand;
@@ -1,14 +0,0 @@
1
- import { MCSManagerBot } from '../../bot';
2
- import { MCBotCommandBase } from '../base';
3
- /**
4
- * 服务器列表指令
5
- *
6
- * @example 服务器 列表
7
- */
8
- export declare class MCBotListCommand extends MCBotCommandBase {
9
- readonly bot: MCSManagerBot;
10
- command: string[];
11
- roles: any[];
12
- constructor(bot: MCSManagerBot);
13
- handle(_: any, status?: string[]): Promise<string>;
14
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotListCommand = void 0;
4
- const utils_1 = require("../../../utils");
5
- const constants_1 = require("../../constants");
6
- const base_1 = require("../base");
7
- /**
8
- * 服务器列表指令
9
- *
10
- * @example 服务器 列表
11
- */
12
- class MCBotListCommand extends base_1.MCBotCommandBase {
13
- constructor(bot) {
14
- super(bot);
15
- this.bot = bot;
16
- this.command = ['服务器.列表 <status>', 'MC.列表 <status>'];
17
- this.roles = [];
18
- this.initialize();
19
- }
20
- async handle(_, status) {
21
- await this.bot.panel.handleRemoteServices();
22
- const filteredStatus = status?.at(0);
23
- const nameInstances = (await this.bot.panel.searchInstanceByName('')).filter(item => !filteredStatus ||
24
- constants_1.RemoteInstanceStatusName[item.instance.cfg.status] === filteredStatus);
25
- return `${'='.repeat(10)}服务器列表${'='.repeat(10)}\n${nameInstances
26
- .map(item => {
27
- const { cfg } = item.instance;
28
- const duration = (0, utils_1.formatDuration)(cfg.config.lastDatetime -
29
- new Date(cfg.config.createDatetime).getTime());
30
- return `- [${constants_1.RemoteInstanceStatusName[cfg.status]}] ${cfg.config.nickname} 「${duration}」`;
31
- })
32
- .join('\n')}\n ${'='.repeat(28)} `;
33
- }
34
- }
35
- exports.MCBotListCommand = MCBotListCommand;
@@ -1,15 +0,0 @@
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 MCBotRestartCommand 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
- }
@@ -1,62 +0,0 @@
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;
@@ -1,15 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
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;