koishi-plugin-gl-bot 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/lib/constants/env.d.ts +0 -0
  2. package/lib/constants/env.js +0 -0
  3. package/lib/gl/index.d.ts +9 -0
  4. package/lib/gl/index.js +9 -2
  5. package/lib/gl/index.type.d.ts +0 -0
  6. package/lib/gl/index.type.js +0 -0
  7. package/lib/index.d.ts +0 -1
  8. package/lib/index.js +0 -2
  9. package/lib/mcsManager/api.d.ts +18 -3
  10. package/lib/mcsManager/api.js +157 -7
  11. package/lib/mcsManager/bot.d.ts +5 -3
  12. package/lib/mcsManager/bot.js +18 -10
  13. package/lib/mcsManager/commands/ark/create.d.ts +15 -0
  14. package/lib/mcsManager/commands/ark/create.js +66 -0
  15. package/lib/mcsManager/commands/ark/list.d.ts +14 -0
  16. package/lib/mcsManager/commands/ark/list.js +35 -0
  17. package/lib/mcsManager/commands/ark/restart.d.ts +15 -0
  18. package/lib/mcsManager/commands/ark/restart.js +62 -0
  19. package/lib/mcsManager/commands/ark/start.d.ts +15 -0
  20. package/lib/mcsManager/commands/ark/start.js +54 -0
  21. package/lib/mcsManager/commands/ark/stop.d.ts +15 -0
  22. package/lib/mcsManager/commands/ark/stop.js +54 -0
  23. package/lib/mcsManager/commands/base.d.ts +20 -1
  24. package/lib/mcsManager/commands/base.js +41 -3
  25. package/lib/mcsManager/commands/create.d.ts +16 -0
  26. package/lib/mcsManager/commands/create.js +135 -0
  27. package/lib/mcsManager/commands/index.d.ts +10 -7
  28. package/lib/mcsManager/commands/index.js +22 -11
  29. package/lib/mcsManager/commands/list copy.d.ts +13 -0
  30. package/lib/mcsManager/commands/list copy.js +34 -0
  31. package/lib/mcsManager/commands/list.d.ts +14 -0
  32. package/lib/mcsManager/commands/list.js +35 -0
  33. package/lib/mcsManager/commands/mc/create.d.ts +15 -0
  34. package/lib/mcsManager/commands/mc/create.js +79 -0
  35. package/lib/mcsManager/commands/mc/list.d.ts +14 -0
  36. package/lib/mcsManager/commands/mc/list.js +39 -0
  37. package/lib/mcsManager/commands/mc/online.d.ts +24 -0
  38. package/lib/mcsManager/commands/mc/online.js +112 -0
  39. package/lib/mcsManager/commands/mc/restart copy.d.ts +15 -0
  40. package/lib/mcsManager/commands/mc/restart copy.js +62 -0
  41. package/lib/mcsManager/commands/mc/restart.d.ts +15 -0
  42. package/lib/mcsManager/commands/mc/restart.js +62 -0
  43. package/lib/mcsManager/commands/mc/start.d.ts +15 -0
  44. package/lib/mcsManager/commands/mc/start.js +54 -0
  45. package/lib/mcsManager/commands/mc/stop.d.ts +15 -0
  46. package/lib/mcsManager/commands/mc/stop.js +54 -0
  47. package/lib/mcsManager/commands/mc copy/create.d.ts +16 -0
  48. package/lib/mcsManager/commands/mc copy/create.js +135 -0
  49. package/lib/mcsManager/commands/mc copy/list.d.ts +14 -0
  50. package/lib/mcsManager/commands/mc copy/list.js +35 -0
  51. package/lib/mcsManager/commands/mc copy/restart.d.ts +15 -0
  52. package/lib/mcsManager/commands/mc copy/restart.js +62 -0
  53. package/lib/mcsManager/commands/mc copy/start.d.ts +15 -0
  54. package/lib/mcsManager/commands/mc copy/start.js +54 -0
  55. package/lib/mcsManager/commands/mc copy/stop.d.ts +15 -0
  56. package/lib/mcsManager/commands/mc copy/stop.js +54 -0
  57. package/lib/mcsManager/commands/restart.d.ts +15 -0
  58. package/lib/mcsManager/commands/restart.js +62 -0
  59. package/lib/mcsManager/commands/start copy.d.ts +14 -0
  60. package/lib/mcsManager/commands/{reset.js → start copy.js } +23 -15
  61. package/lib/mcsManager/commands/start.d.ts +15 -0
  62. package/lib/mcsManager/commands/start.js +54 -0
  63. package/lib/mcsManager/commands/stop.d.ts +15 -0
  64. package/lib/mcsManager/commands/stop.js +54 -0
  65. package/lib/mcsManager/constants.d.ts +4 -0
  66. package/lib/mcsManager/constants.js +4 -0
  67. package/lib/mcsManager/index.d.ts +4 -3
  68. package/lib/mcsManager/index.js +5 -2
  69. package/lib/mcsManager/instance.d.ts +3 -1
  70. package/lib/mcsManager/instance.js +8 -2
  71. package/lib/mcsManager/json/createInstanceUpload.json +49 -0
  72. package/lib/mcsManager/panel.d.ts +1 -1
  73. package/lib/mcsManager/panel.js +7 -5
  74. package/lib/mcsManager/schedules/index.d.ts +8 -0
  75. package/lib/mcsManager/schedules/index.js +41 -0
  76. package/lib/mcsManager/schedules/mc.schedule.d.ts +11 -0
  77. package/lib/mcsManager/schedules/mc.schedule.js +15 -0
  78. package/lib/mcsManager/type.d.ts +102 -0
  79. package/lib/mcsManager/ws.js +6 -6
  80. package/lib/napCat/api.d.ts +21 -0
  81. package/lib/napCat/api.js +43 -0
  82. package/lib/napCat/config.d.ts +10 -0
  83. package/lib/napCat/config.js +16 -0
  84. package/lib/napCat/index.d.ts +16 -0
  85. package/lib/napCat/index.js +15 -0
  86. package/lib/queQiao/index.d.ts +1 -0
  87. package/lib/queQiao/index.js +70 -3
  88. package/lib/queQiao/locale/en-US.yml +9 -9
  89. package/lib/queQiao/locale/zh-CN.json +1 -1
  90. package/lib/queQiao/locale/zh-CN.yml +9 -9
  91. package/lib/utils/file.download.d.ts +47 -0
  92. package/lib/utils/file.download.js +142 -0
  93. package/lib/utils/file.examples.d.ts +12 -0
  94. package/lib/utils/file.examples.js +73 -0
  95. package/lib/utils/index.d.ts +7 -0
  96. package/lib/utils/index.js +58 -0
  97. package/lib/utils/napcat.file.d.ts +63 -0
  98. package/lib/utils/napcat.file.js +133 -0
  99. package/package.json +4 -3
  100. package/lib/mcsManager/commands/reset.d.ts +0 -12
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotRestartCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../../constants");
6
+ const base_1 = require("../base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器重启指令
10
+ *
11
+ * @example 服务器 重启 神话
12
+ */
13
+ class MCBotRestartCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.重启 <name...>', 'MC.重启 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 重启 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ switch (cfg.status) {
47
+ // 关闭状态:启动
48
+ case constants_1.RemoteInstanceStatusEnum.RUNNING:
49
+ await targetInstance.instance.restartInstance();
50
+ this.bot.panel.handleRemoteServices();
51
+ return `已向服务器实例 "${cfg.config.nickname}" 发送重启操作`;
52
+ // 启动状态:重启
53
+ case constants_1.RemoteInstanceStatusEnum.STOPPED:
54
+ await targetInstance.instance.startInstance();
55
+ this.bot.panel.handleRemoteServices();
56
+ return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
57
+ default:
58
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行重启操作`;
59
+ }
60
+ }
61
+ }
62
+ exports.MCBotRestartCommand = MCBotRestartCommand;
@@ -0,0 +1,15 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../../bot';
3
+ import { MCBotCommandBase, MCBotCommandRole } from '../base';
4
+ /**
5
+ * 服务器启动指令
6
+ *
7
+ * @example 服务器 启动 神话
8
+ */
9
+ export declare class MCBotStartCommand extends MCBotCommandBase {
10
+ readonly bot: MCSManagerBot;
11
+ command: string[];
12
+ roles: MCBotCommandRole[];
13
+ constructor(bot: MCSManagerBot);
14
+ handle({ session }: Argv, args: string[]): Promise<string>;
15
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotStartCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../../constants");
6
+ const base_1 = require("../base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器启动指令
10
+ *
11
+ * @example 服务器 启动 神话
12
+ */
13
+ class MCBotStartCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.启动 <name...>', 'MC.启动 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 启动 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.STOPPED)) {
47
+ await targetInstance.instance.startInstance();
48
+ this.bot.panel.handleRemoteServices();
49
+ return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
50
+ }
51
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行启动操作`;
52
+ }
53
+ }
54
+ exports.MCBotStartCommand = MCBotStartCommand;
@@ -0,0 +1,15 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../../bot';
3
+ import { MCBotCommandBase, MCBotCommandRole } from '../base';
4
+ /**
5
+ * 服务器关闭指令
6
+ *
7
+ * @example 服务器 关闭 神话
8
+ */
9
+ export declare class MCBotStopCommand extends MCBotCommandBase {
10
+ readonly bot: MCSManagerBot;
11
+ command: string[];
12
+ roles: MCBotCommandRole[];
13
+ constructor(bot: MCSManagerBot);
14
+ handle({ session }: Argv, args: string[]): Promise<string>;
15
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotStopCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../../constants");
6
+ const base_1 = require("../base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器关闭指令
10
+ *
11
+ * @example 服务器 关闭 神话
12
+ */
13
+ class MCBotStopCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.关闭 <name...>', 'MC.关闭 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 关闭 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.RUNNING)) {
47
+ await targetInstance.instance.stopInstance();
48
+ this.bot.panel.handleRemoteServices();
49
+ return `已向服务器实例 "${cfg.config.nickname}" 发送关闭操作`;
50
+ }
51
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行关闭操作`;
52
+ }
53
+ }
54
+ exports.MCBotStopCommand = MCBotStopCommand;
@@ -0,0 +1,15 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../bot';
3
+ import { MCBotCommandBase, MCBotCommandRole } from './base';
4
+ /**
5
+ * 服务器重启指令
6
+ *
7
+ * @example 服务器 重启 神话
8
+ */
9
+ export declare class 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
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotRestartCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../constants");
6
+ const base_1 = require("./base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器重启指令
10
+ *
11
+ * @example 服务器 重启 神话
12
+ */
13
+ class MCBotRestartCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.重启 <name...>', 'MC.重启 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 重启 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ switch (cfg.status) {
47
+ // 关闭状态:启动
48
+ case constants_1.RemoteInstanceStatusEnum.RUNNING:
49
+ await targetInstance.instance.restartInstance();
50
+ this.bot.panel.handleRemoteServices();
51
+ return `已向服务器实例 "${cfg.config.nickname}" 发送重启操作`;
52
+ // 启动状态:重启
53
+ case constants_1.RemoteInstanceStatusEnum.STOPPED:
54
+ await targetInstance.instance.startInstance();
55
+ this.bot.panel.handleRemoteServices();
56
+ return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
57
+ default:
58
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行重启操作`;
59
+ }
60
+ }
61
+ }
62
+ exports.MCBotRestartCommand = MCBotRestartCommand;
@@ -0,0 +1,14 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../bot';
3
+ import { MCBotCommandBase } from './base';
4
+ /**
5
+ * 服务器启动指令
6
+ *
7
+ * @example 服务器 启动 神话
8
+ */
9
+ export declare class MCBotStartCommand extends MCBotCommandBase {
10
+ readonly bot: MCSManagerBot;
11
+ command: string;
12
+ constructor(bot: MCSManagerBot);
13
+ handle({ session }: Argv, args: string[]): Promise<string>;
14
+ }
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MCBotResetCommand = void 0;
3
+ exports.MCBotStartCommand = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  const constants_1 = require("../constants");
5
- // const logger = new Logger('mcsmanager-reset');
6
+ const base_1 = require("./base");
6
7
  const tempSelections = new Map();
7
8
  /**
8
- * 服务器重启指令
9
+ * 服务器启动指令
9
10
  *
10
- * @example 服务器 重启 神话
11
+ * @example 服务器 启动 神话
11
12
  */
12
- class MCBotResetCommand {
13
+ class MCBotStartCommand extends base_1.MCBotCommandBase {
13
14
  constructor(bot) {
15
+ super(bot);
14
16
  this.bot = bot;
15
- bot.ctx
16
- .command('服务器 重启 <name...>')
17
- .action(async ({ session }, _action, ...name) => {
18
- return await this.handle(session, name.join(' '));
19
- });
17
+ this.command = '服务器.启动 <name...>';
18
+ this.initialize();
20
19
  }
21
- async handle(session, name) {
20
+ async handle({ session }, args) {
21
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
22
22
  let selectIndex = -1;
23
23
  const userId = Number(session.event.user.id);
24
24
  // 溯源前搜索项
@@ -35,11 +35,19 @@ class MCBotResetCommand {
35
35
  tempSelections.set(userId, name);
36
36
  return `请输入序号以选择:\n\n${nameInstances
37
37
  .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
38
- .join('\n')}\n ==== 例如发送: (服务器 重启 1) ====`;
38
+ .join('\n')}\n ==== 例如发送: (服务器 启动 1) ====`;
39
39
  }
40
40
  const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
41
- targetInstance.instance.restartInstance();
42
- return `已向服务器实例 "${targetInstance.instance.cfg.config.nickname}" 发送重启操作`;
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},无法执行启动操作`;
43
51
  }
44
52
  }
45
- exports.MCBotResetCommand = MCBotResetCommand;
53
+ exports.MCBotStartCommand = MCBotStartCommand;
@@ -0,0 +1,15 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../bot';
3
+ import { MCBotCommandBase, MCBotCommandRole } from './base';
4
+ /**
5
+ * 服务器启动指令
6
+ *
7
+ * @example 服务器 启动 神话
8
+ */
9
+ export declare class MCBotStartCommand extends MCBotCommandBase {
10
+ readonly bot: MCSManagerBot;
11
+ command: string[];
12
+ roles: MCBotCommandRole[];
13
+ constructor(bot: MCSManagerBot);
14
+ handle({ session }: Argv, args: string[]): Promise<string>;
15
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotStartCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../constants");
6
+ const base_1 = require("./base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器启动指令
10
+ *
11
+ * @example 服务器 启动 神话
12
+ */
13
+ class MCBotStartCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.启动 <name...>', 'MC.启动 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 启动 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.STOPPED)) {
47
+ await targetInstance.instance.startInstance();
48
+ this.bot.panel.handleRemoteServices();
49
+ return `已向服务器实例 "${cfg.config.nickname}" 发送启动操作`;
50
+ }
51
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行启动操作`;
52
+ }
53
+ }
54
+ exports.MCBotStartCommand = MCBotStartCommand;
@@ -0,0 +1,15 @@
1
+ import { Argv } from 'koishi';
2
+ import { MCSManagerBot } from '../bot';
3
+ import { MCBotCommandBase, MCBotCommandRole } from './base';
4
+ /**
5
+ * 服务器关闭指令
6
+ *
7
+ * @example 服务器 关闭 神话
8
+ */
9
+ export declare class MCBotStopCommand extends MCBotCommandBase {
10
+ readonly bot: MCSManagerBot;
11
+ command: string[];
12
+ roles: MCBotCommandRole[];
13
+ constructor(bot: MCSManagerBot);
14
+ handle({ session }: Argv, args: string[]): Promise<string>;
15
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotStopCommand = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const constants_1 = require("../constants");
6
+ const base_1 = require("./base");
7
+ const tempSelections = new Map();
8
+ /**
9
+ * 服务器关闭指令
10
+ *
11
+ * @example 服务器 关闭 神话
12
+ */
13
+ class MCBotStopCommand extends base_1.MCBotCommandBase {
14
+ constructor(bot) {
15
+ super(bot);
16
+ this.bot = bot;
17
+ this.command = ['服务器.关闭 <name...>', 'MC.关闭 <name...>'];
18
+ this.roles = [base_1.MCBotCommandRole.Admin, base_1.MCBotCommandRole.Owner];
19
+ this.initialize();
20
+ }
21
+ async handle({ session }, args) {
22
+ let name = (0, lodash_1.isString)(args) ? args : args.join(' ');
23
+ let selectIndex = -1;
24
+ const userId = Number(session.event.user.id);
25
+ // 溯源前搜索项
26
+ if (tempSelections.has(userId) && !isNaN(Number(name))) {
27
+ selectIndex = Number(name) - 1;
28
+ name = tempSelections.get(userId);
29
+ }
30
+ tempSelections.delete(userId);
31
+ const nameInstances = await this.bot.panel.searchInstanceByName(name);
32
+ if (nameInstances.length === 0) {
33
+ return `未找到名称包含 "${name}" 的服务器`;
34
+ }
35
+ if (nameInstances.length > 1 && selectIndex === -1) {
36
+ tempSelections.set(userId, name);
37
+ return `请输入序号以选择:\n\n${nameInstances
38
+ .map((item, index) => `${index + 1}. [${constants_1.RemoteInstanceStatusName[item.instance.cfg.status]}] ${item.instance.cfg.config.nickname}`)
39
+ .join('\n')}\n ==== 例如发送: (服务器 关闭 1) ====`;
40
+ }
41
+ const targetInstance = selectIndex !== -1 ? nameInstances[selectIndex] : nameInstances[0];
42
+ if (!targetInstance || !targetInstance.instance) {
43
+ return `未找到名称包含 "${name}" 的服务器`;
44
+ }
45
+ const { cfg } = targetInstance.instance;
46
+ if ((0, lodash_1.isEqual)(cfg.status, constants_1.RemoteInstanceStatusEnum.RUNNING)) {
47
+ await targetInstance.instance.stopInstance();
48
+ this.bot.panel.handleRemoteServices();
49
+ return `已向服务器实例 "${cfg.config.nickname}" 发送关闭操作`;
50
+ }
51
+ return `服务器实例 "${cfg.config.nickname}" 当前状态为 ${cfg.status},无法执行关闭操作`;
52
+ }
53
+ }
54
+ exports.MCBotStopCommand = MCBotStopCommand;
@@ -1,8 +1,12 @@
1
1
  export declare enum RemoteInstanceStatusEnum {
2
2
  STOPPED = 0,
3
+ STARTING = 1,
4
+ STOPPING = 2,
3
5
  RUNNING = 3
4
6
  }
5
7
  export declare const RemoteInstanceStatusName: {
6
8
  0: string;
9
+ 1: string;
10
+ 2: string;
7
11
  3: string;
8
12
  };
@@ -4,9 +4,13 @@ exports.RemoteInstanceStatusName = exports.RemoteInstanceStatusEnum = void 0;
4
4
  var RemoteInstanceStatusEnum;
5
5
  (function (RemoteInstanceStatusEnum) {
6
6
  RemoteInstanceStatusEnum[RemoteInstanceStatusEnum["STOPPED"] = 0] = "STOPPED";
7
+ RemoteInstanceStatusEnum[RemoteInstanceStatusEnum["STARTING"] = 1] = "STARTING";
8
+ RemoteInstanceStatusEnum[RemoteInstanceStatusEnum["STOPPING"] = 2] = "STOPPING";
7
9
  RemoteInstanceStatusEnum[RemoteInstanceStatusEnum["RUNNING"] = 3] = "RUNNING";
8
10
  })(RemoteInstanceStatusEnum || (exports.RemoteInstanceStatusEnum = RemoteInstanceStatusEnum = {}));
9
11
  exports.RemoteInstanceStatusName = {
10
12
  [RemoteInstanceStatusEnum.STOPPED]: '已停止',
13
+ [RemoteInstanceStatusEnum.STARTING]: '启动中',
14
+ [RemoteInstanceStatusEnum.STOPPING]: '停止中',
11
15
  [RemoteInstanceStatusEnum.RUNNING]: '运行中',
12
16
  };
@@ -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
- private readonly ctx;
4
+ readonly gl: GLBot;
5
+ readonly ctx: Context;
5
6
  private readonly config;
6
7
  static Config: Schema<Schemastery.ObjectS<{
7
8
  mcManagerUsername: Schema<string, string>;
@@ -20,7 +21,7 @@ export declare class MCManager {
20
21
  } & import("cosmokit").Dict>;
21
22
  private panel;
22
23
  private bot;
23
- constructor(ctx: Context, config: GLBotConfigType);
24
+ constructor(gl: GLBot, ctx: Context, config: GLBotConfigType);
24
25
  initialize(): Promise<void>;
25
26
  }
26
27
  export type MCManagerConfigType = typeof MCManager.Config;
@@ -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() {
@@ -12,5 +12,7 @@ export declare class MCSManagerInstance {
12
12
  cfg: ServiceRemoteInstanceItem;
13
13
  isAuthenticated: boolean;
14
14
  constructor(ctx: Context, config: GLBotConfigType, api: MCSManagerAPI, panel: MCSManagerPanel, remote: ServiceRemoteItem, cfg: ServiceRemoteInstanceItem);
15
- restartInstance(): void;
15
+ restartInstance(): Promise<boolean>;
16
+ stopInstance(): Promise<boolean>;
17
+ startInstance(): Promise<boolean>;
16
18
  }
@@ -11,8 +11,14 @@ class MCSManagerInstance {
11
11
  this.cfg = cfg;
12
12
  this.isAuthenticated = false;
13
13
  }
14
- restartInstance() {
15
- this.api.restartRemoteInstance(this.remote.uuid, this.cfg.instanceUuid);
14
+ async restartInstance() {
15
+ return await this.api.restartRemoteInstance(this.remote.uuid, this.cfg.instanceUuid);
16
+ }
17
+ async stopInstance() {
18
+ return await this.api.stopRemoteInstance(this.remote.uuid, this.cfg.instanceUuid);
19
+ }
20
+ async startInstance() {
21
+ return await this.api.startRemoteInstance(this.remote.uuid, this.cfg.instanceUuid);
16
22
  }
17
23
  }
18
24
  exports.MCSManagerInstance = MCSManagerInstance;
@@ -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);