koishi-plugin-gl-bot 0.0.10 → 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 (90) hide show
  1. package/lib/gl/index.d.ts +9 -0
  2. package/lib/gl/index.js +9 -2
  3. package/lib/index.d.ts +0 -1
  4. package/lib/index.js +0 -2
  5. package/lib/mcsManager/api.d.ts +15 -2
  6. package/lib/mcsManager/api.js +136 -1
  7. package/lib/mcsManager/bot.d.ts +5 -3
  8. package/lib/mcsManager/bot.js +17 -9
  9. package/lib/mcsManager/commands/ark/create.d.ts +15 -0
  10. package/lib/mcsManager/commands/ark/create.js +66 -0
  11. package/lib/mcsManager/commands/ark/list.d.ts +14 -0
  12. package/lib/mcsManager/commands/ark/list.js +35 -0
  13. package/lib/mcsManager/commands/ark/restart.d.ts +15 -0
  14. package/lib/mcsManager/commands/ark/restart.js +62 -0
  15. package/lib/mcsManager/commands/ark/start.d.ts +15 -0
  16. package/lib/mcsManager/commands/ark/start.js +54 -0
  17. package/lib/mcsManager/commands/ark/stop.d.ts +15 -0
  18. package/lib/mcsManager/commands/ark/stop.js +54 -0
  19. package/lib/mcsManager/commands/base.d.ts +21 -0
  20. package/lib/mcsManager/commands/base.js +44 -0
  21. package/lib/mcsManager/commands/create.d.ts +16 -0
  22. package/lib/mcsManager/commands/create.js +135 -0
  23. package/lib/mcsManager/commands/index.d.ts +10 -10
  24. package/lib/mcsManager/commands/index.js +19 -14
  25. package/lib/mcsManager/commands/list copy.d.ts +13 -0
  26. package/lib/mcsManager/commands/list copy.js +34 -0
  27. package/lib/mcsManager/commands/list.d.ts +6 -3
  28. package/lib/mcsManager/commands/list.js +18 -9
  29. package/lib/mcsManager/commands/mc/create.d.ts +15 -0
  30. package/lib/mcsManager/commands/mc/create.js +79 -0
  31. package/lib/mcsManager/commands/mc/list.d.ts +14 -0
  32. package/lib/mcsManager/commands/mc/list.js +39 -0
  33. package/lib/mcsManager/commands/mc/online.d.ts +24 -0
  34. package/lib/mcsManager/commands/mc/online.js +112 -0
  35. package/lib/mcsManager/commands/mc/restart copy.d.ts +15 -0
  36. package/lib/mcsManager/commands/mc/restart copy.js +62 -0
  37. package/lib/mcsManager/commands/mc/restart.d.ts +15 -0
  38. package/lib/mcsManager/commands/mc/restart.js +62 -0
  39. package/lib/mcsManager/commands/mc/start.d.ts +15 -0
  40. package/lib/mcsManager/commands/mc/start.js +54 -0
  41. package/lib/mcsManager/commands/mc/stop.d.ts +15 -0
  42. package/lib/mcsManager/commands/mc/stop.js +54 -0
  43. package/lib/mcsManager/commands/mc copy/create.d.ts +16 -0
  44. package/lib/mcsManager/commands/mc copy/create.js +135 -0
  45. package/lib/mcsManager/commands/mc copy/list.d.ts +14 -0
  46. package/lib/mcsManager/commands/mc copy/list.js +35 -0
  47. package/lib/mcsManager/commands/mc copy/restart.d.ts +15 -0
  48. package/lib/mcsManager/commands/mc copy/restart.js +62 -0
  49. package/lib/mcsManager/commands/mc copy/start.d.ts +15 -0
  50. package/lib/mcsManager/commands/mc copy/start.js +54 -0
  51. package/lib/mcsManager/commands/mc copy/stop.d.ts +15 -0
  52. package/lib/mcsManager/commands/mc copy/stop.js +54 -0
  53. package/lib/mcsManager/commands/restart.d.ts +7 -4
  54. package/lib/mcsManager/commands/restart.js +11 -10
  55. package/lib/mcsManager/commands/start copy.d.ts +14 -0
  56. package/lib/mcsManager/commands/start copy.js +53 -0
  57. package/lib/mcsManager/commands/start.d.ts +7 -4
  58. package/lib/mcsManager/commands/start.js +10 -9
  59. package/lib/mcsManager/commands/stop.d.ts +15 -0
  60. package/lib/mcsManager/commands/stop.js +54 -0
  61. package/lib/mcsManager/index.d.ts +4 -3
  62. package/lib/mcsManager/index.js +5 -2
  63. package/lib/mcsManager/json/createInstanceUpload.json +49 -0
  64. package/lib/mcsManager/panel.d.ts +1 -1
  65. package/lib/mcsManager/panel.js +1 -1
  66. package/lib/mcsManager/schedules/index.d.ts +8 -0
  67. package/lib/mcsManager/schedules/index.js +41 -0
  68. package/lib/mcsManager/schedules/mc.schedule.d.ts +11 -0
  69. package/lib/mcsManager/schedules/mc.schedule.js +15 -0
  70. package/lib/mcsManager/type.d.ts +102 -0
  71. package/lib/mcsManager/ws.js +1 -1
  72. package/lib/napCat/api.d.ts +21 -0
  73. package/lib/napCat/api.js +43 -0
  74. package/lib/napCat/config.d.ts +10 -0
  75. package/lib/napCat/config.js +16 -0
  76. package/lib/napCat/index.d.ts +16 -0
  77. package/lib/napCat/index.js +15 -0
  78. package/lib/queQiao/index.d.ts +1 -0
  79. package/lib/queQiao/index.js +68 -1
  80. package/lib/queQiao/locale/zh-CN.json +1 -1
  81. package/lib/queQiao/locale/zh-CN.yml +6 -6
  82. package/lib/utils/file.download.d.ts +47 -0
  83. package/lib/utils/file.download.js +142 -0
  84. package/lib/utils/file.examples.d.ts +12 -0
  85. package/lib/utils/file.examples.js +73 -0
  86. package/lib/utils/index.d.ts +7 -0
  87. package/lib/utils/index.js +58 -0
  88. package/lib/utils/napcat.file.d.ts +63 -0
  89. package/lib/utils/napcat.file.js +133 -0
  90. package/package.json +2 -1
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCBotOnlineTimeCommand = exports.MCBotGameOnline = void 0;
4
+ const utils_1 = require("../../../utils");
5
+ const base_1 = require("../base");
6
+ class MCBotGameOnline extends base_1.BotCommandBase {
7
+ constructor(bot) {
8
+ super(bot);
9
+ this.bot = bot;
10
+ this.command = ['服务器.在线 <status>', 'MC.在线 <status>'];
11
+ this.roles = [];
12
+ this.initialize();
13
+ }
14
+ async handle() {
15
+ try {
16
+ const users = await this.bot.ctx.database.get('mcUser', {});
17
+ const userRankings = Object.values(MCBotGameOnline.list)
18
+ .map(user => {
19
+ const dbUser = users.find(u => u.uuid === user.uuid);
20
+ const totalOnlineTime = +((Date.now() - (dbUser?.lastTime?.getTime() || 0)) /
21
+ 1000).toFixed(0);
22
+ return {
23
+ ...user,
24
+ totalOnlineTime,
25
+ };
26
+ })
27
+ .sort((a, b) => b.totalOnlineTime - a.totalOnlineTime)
28
+ .slice(0, 10);
29
+ let result = '==== 服务器在线玩家 ====\n';
30
+ const tag = [, '🥇', '🥈', '🥉'];
31
+ userRankings.forEach((user, index) => {
32
+ const rank = index + 1;
33
+ const medal = tag[rank] || `${rank}.`;
34
+ const onlineTimeStr = (0, utils_1.formatOnlineTime)(user.totalOnlineTime);
35
+ result += `${medal} ${user.nickname} [HP: ${user.health.toFixed(1)} | LV: ${user.experience_level}] 「${onlineTimeStr}」\n`;
36
+ if (index < userRankings.length - 1) {
37
+ result += '\n';
38
+ }
39
+ });
40
+ result += '====================';
41
+ return result;
42
+ }
43
+ catch (error) {
44
+ console.error('查询在线玩家失败:', error);
45
+ return '查询在线玩家时发生错误,请稍后重试';
46
+ }
47
+ }
48
+ }
49
+ exports.MCBotGameOnline = MCBotGameOnline;
50
+ MCBotGameOnline.list = {};
51
+ /**
52
+ * 服务器在线榜单指令
53
+ * 查询服务器在线时长排行
54
+ *
55
+ * @example 服务器 在线榜单
56
+ */
57
+ class MCBotOnlineTimeCommand extends base_1.BotCommandBase {
58
+ constructor(bot) {
59
+ super(bot);
60
+ this.bot = bot;
61
+ this.command = ['服务器.在线榜单 <status>', 'MC.在线榜单 <status>'];
62
+ this.roles = [];
63
+ this.initialize();
64
+ }
65
+ async handle() {
66
+ try {
67
+ const users = await this.bot.ctx.database.get('mcUser', {});
68
+ if (users.length === 0) {
69
+ return '暂无玩家在线时长数据';
70
+ }
71
+ const userRankings = users
72
+ .map(user => {
73
+ let totalOnlineTime = 0;
74
+ const onlineTimeData = JSON.parse(user.onlineTimeJSON || '{}');
75
+ if (onlineTimeData?.mc?.[user.uuid]) {
76
+ totalOnlineTime = onlineTimeData.mc[user.uuid];
77
+ }
78
+ if (MCBotGameOnline.list[user.uuid]) {
79
+ totalOnlineTime += +((Date.now() - user.lastTime.getTime()) /
80
+ 1000).toFixed(0);
81
+ }
82
+ return {
83
+ nickname: user.nickname,
84
+ uuid: user.uuid,
85
+ level: user.level,
86
+ totalOnlineTime,
87
+ lastTime: user.lastTime,
88
+ };
89
+ })
90
+ .sort((a, b) => b.totalOnlineTime - a.totalOnlineTime)
91
+ .slice(0, 10);
92
+ let result = '==== 服务器在线时长排行榜 ====\n';
93
+ const tag = [, '🥇', '🥈', '🥉'];
94
+ userRankings.forEach((user, index) => {
95
+ const rank = index + 1;
96
+ const medal = tag[rank] || `${rank}.`;
97
+ const onlineTimeStr = (0, utils_1.formatOnlineTime)(user.totalOnlineTime);
98
+ result += `${medal} ${user.nickname} 「${onlineTimeStr}」\n`;
99
+ if (index < userRankings.length - 1) {
100
+ result += '\n';
101
+ }
102
+ });
103
+ result += '========================';
104
+ return result;
105
+ }
106
+ catch (error) {
107
+ console.error('查询在线时长排行榜失败:', error);
108
+ return '查询在线时长排行榜时发生错误,请稍后重试';
109
+ }
110
+ }
111
+ }
112
+ 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 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;
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,135 @@
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;
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,35 @@
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;
@@ -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
+ }