koishi-plugin-gl-bot 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib/gl/index.d.ts +44 -54
  2. package/lib/gl/index.js +12 -7
  3. package/lib/gl/queqiao.adapter.d.ts +11 -0
  4. package/lib/gl/queqiao.adapter.js +41 -0
  5. package/lib/index.d.ts +0 -1
  6. package/lib/index.js +0 -2
  7. package/lib/mcsManager/api.d.ts +16 -2
  8. package/lib/mcsManager/api.js +149 -2
  9. package/lib/mcsManager/bot.d.ts +5 -3
  10. package/lib/mcsManager/bot.js +18 -9
  11. package/lib/mcsManager/commands/ark/create.d.ts +15 -0
  12. package/lib/mcsManager/commands/ark/create.js +66 -0
  13. package/lib/mcsManager/commands/ark/list.d.ts +14 -0
  14. package/lib/mcsManager/commands/ark/list.js +35 -0
  15. package/lib/mcsManager/commands/ark/restart.d.ts +15 -0
  16. package/lib/mcsManager/commands/{restart.js → ark/restart.js} +14 -13
  17. package/lib/mcsManager/commands/ark/start.d.ts +15 -0
  18. package/lib/mcsManager/commands/{start.js → ark/start.js} +13 -12
  19. package/lib/mcsManager/commands/ark/stop.d.ts +15 -0
  20. package/lib/mcsManager/commands/ark/stop.js +54 -0
  21. package/lib/mcsManager/commands/base.d.ts +21 -0
  22. package/lib/mcsManager/commands/base.js +44 -0
  23. package/lib/mcsManager/commands/index.d.ts +11 -10
  24. package/lib/mcsManager/commands/index.js +21 -14
  25. package/lib/mcsManager/commands/mc/create.d.ts +15 -0
  26. package/lib/mcsManager/commands/mc/create.js +79 -0
  27. package/lib/mcsManager/commands/mc/health.d.ts +16 -0
  28. package/lib/mcsManager/commands/mc/health.js +46 -0
  29. package/lib/mcsManager/commands/mc/list.d.ts +15 -0
  30. package/lib/mcsManager/commands/mc/list.js +54 -0
  31. package/lib/mcsManager/commands/mc/online.d.ts +29 -0
  32. package/lib/mcsManager/commands/mc/online.js +149 -0
  33. package/lib/mcsManager/commands/mc/restart.d.ts +15 -0
  34. package/lib/mcsManager/commands/mc/restart.js +62 -0
  35. package/lib/mcsManager/commands/mc/start.d.ts +15 -0
  36. package/lib/mcsManager/commands/mc/start.js +54 -0
  37. package/lib/mcsManager/commands/mc/stop.d.ts +15 -0
  38. package/lib/mcsManager/commands/mc/stop.js +54 -0
  39. package/lib/mcsManager/config.d.ts +39 -0
  40. package/lib/mcsManager/config.js +21 -0
  41. package/lib/mcsManager/index.d.ts +36 -4
  42. package/lib/mcsManager/index.js +9 -3
  43. package/lib/mcsManager/json/createInstanceUpload.json +49 -0
  44. package/lib/mcsManager/panel.d.ts +1 -1
  45. package/lib/mcsManager/panel.js +1 -1
  46. package/lib/mcsManager/schedules/index.d.ts +8 -0
  47. package/lib/mcsManager/schedules/index.js +41 -0
  48. package/lib/mcsManager/schedules/mc.schedule.d.ts +11 -0
  49. package/lib/mcsManager/schedules/mc.schedule.js +15 -0
  50. package/lib/mcsManager/type.d.ts +104 -0
  51. package/lib/mcsManager/ws.js +1 -1
  52. package/lib/napCat/api.d.ts +21 -0
  53. package/lib/napCat/api.js +43 -0
  54. package/lib/napCat/config.d.ts +10 -0
  55. package/lib/napCat/config.js +16 -0
  56. package/lib/napCat/index.d.ts +16 -0
  57. package/lib/napCat/index.js +15 -0
  58. package/lib/queQiao/index.d.ts +47 -37
  59. package/lib/queQiao/index.js +141 -39
  60. package/lib/queQiao/locale/zh-CN.json +1 -1
  61. package/lib/queQiao/locale/zh-CN.yml +6 -6
  62. package/lib/queQiao/mcwss.d.ts +12 -9
  63. package/lib/queQiao/mcwss.js +34 -2
  64. package/lib/queQiao/values.js +2 -2
  65. package/lib/utils/game.mc.js +5 -4
  66. package/lib/utils/index.d.ts +7 -0
  67. package/lib/utils/index.js +58 -0
  68. package/package.json +2 -1
  69. package/lib/constants/env.d.ts +0 -0
  70. package/lib/constants/env.js +0 -0
  71. package/lib/gl/index.type.d.ts +0 -0
  72. package/lib/gl/index.type.js +0 -0
  73. package/lib/mcsManager/commands/list.d.ts +0 -11
  74. package/lib/mcsManager/commands/list.js +0 -26
  75. package/lib/mcsManager/commands/restart.d.ts +0 -12
  76. package/lib/mcsManager/commands/start.d.ts +0 -12
@@ -1 +1 @@
1
- {"minecraft-sync-msg":{"action":{"PlayerJoinEvent":"[加入]{0} 加入了服务器!","PlayerCommandPreprocessEvent":"[指令]{0} 执行了指令","PlayerDeathEvent":"[死亡]{0} 与山长眠!","AsyncPlayerChatEvent":"[聊天]{0} 说:{1}","PlayerQuitEvent":"[离开]{0} 离开了服务器!"},"message":{"MCReceivePrefix":"({0})[{1}]"}}}
1
+ {"minecraft-sync-msg":{"action":{"PlayerJoinEvent":"[{0}] {1} 加入了服务器!","PlayerCommandPreprocessEvent":"[指令]{0} 执行了指令","PlayerDeathEvent":"[{0}] {1} 与山长眠!","AsyncPlayerChatEvent":"[{0}] {1}: {2}","PlayerQuitEvent":"[{0}] {1} 离开了服务器!"},"message":{"MCReceivePrefix":"({0})[{1}]"}}}
@@ -1,9 +1,9 @@
1
1
  minecraft-sync-msg:
2
2
  action:
3
- PlayerJoinEvent: '[加入]{0} 加入了服务器!'
4
- PlayerCommandPreprocessEvent: '[指令]{0} 执行了指令'
5
- PlayerDeathEvent: '[死亡]{0} 与山长眠!'
6
- AsyncPlayerChatEvent: '[聊天]{0} 说:{1}'
7
- PlayerQuitEvent: '[离开]{0} 离开了服务器!'
3
+ PlayerJoinEvent: "[{0}] {1} 加入了服务器!"
4
+ PlayerCommandPreprocessEvent: "[指令]{0} 执行了指令"
5
+ PlayerDeathEvent: "[{0}] {1} 与山长眠!"
6
+ AsyncPlayerChatEvent: "[{0}] {1}: {2}"
7
+ PlayerQuitEvent: "[{0}] {1} 离开了服务器!"
8
8
  message:
9
- MCReceivePrefix: '({0})[{1}]'
9
+ MCReceivePrefix: "({0})[{1}]"
@@ -1,15 +1,18 @@
1
1
  import { IncomingMessage } from 'http';
2
- import { Context, Schema } from 'koishi';
2
+ import { Context, Logger, Schema } from 'koishi';
3
+ import { WebSocket, WebSocketServer } from 'ws';
4
+ import { GLQueQiaoAdapter } from '../gl/queqiao.adapter';
3
5
  import { WsConf } from './values';
4
6
  declare class McWss {
5
- private conf;
6
- private logger;
7
- private wss;
8
- private ctx;
9
- private connectedClients;
10
- constructor(ctx: Context, cfg: McWss.Config);
11
- private setupWebSocketHandlers;
12
- private setupMessageHandler;
7
+ adapter: GLQueQiaoAdapter;
8
+ conf: McWss.Config;
9
+ logger: Logger;
10
+ wss: WebSocketServer;
11
+ ctx: Context;
12
+ connectedClients: Set<WebSocket>;
13
+ constructor(ctx: Context, adapter: GLQueQiaoAdapter, cfg: McWss.Config);
14
+ setupWebSocketHandlers(): void;
15
+ setupMessageHandler(): void;
13
16
  verifyHeaders(headers: IncomingMessage['headers']): {
14
17
  valid: boolean;
15
18
  clientOrigin?: string;
@@ -9,7 +9,8 @@ const values_1 = require("./values");
9
9
  const zhCN = require('./locale/zh-CN.json');
10
10
  const enUS = require('./locale/en-US.json');
11
11
  class McWss {
12
- constructor(ctx, cfg) {
12
+ constructor(ctx, adapter, cfg) {
13
+ this.adapter = adapter;
13
14
  this.logger = new koishi_1.Logger('Minecraft-sync-msg-Wss');
14
15
  this.connectedClients = new Set();
15
16
  this.conf = cfg;
@@ -139,7 +140,9 @@ class McWss {
139
140
  setupMessageHandler() {
140
141
  let imgurl = '<unknown image url>';
141
142
  this.ctx.on('message', async (session) => {
142
- // this.ctx.logger.info(`收到聊天消息: ${session.content} 来自 ${session.platform}:${session.channelId}`);
143
+ // this.ctx.logger.info(
144
+ // `收到聊天消息: ${session.content} 来自 ${session.platform}:${session.channelId}`,
145
+ // );
143
146
  if (session.content.includes('<img') &&
144
147
  koishi_1.h.select(session.content, 'img')[0]?.type === 'img' &&
145
148
  koishi_1.h.select(session.content, 'img')[0]?.attrs?.src) {
@@ -160,6 +163,35 @@ class McWss {
160
163
  .replaceAll(/<at.*\/>/gi, `@[${koishi_1.h.select(session.content, 'at')[0]?.attrs?.name
161
164
  ? koishi_1.h.select(session.content, 'at')[0]?.attrs?.name
162
165
  : koishi_1.h.select(session.content, 'at')[0]?.attrs?.id}]`);
166
+ // console.log(this.adapter.servers);
167
+ // Object.entries(this.adapter.servers).forEach(
168
+ // async ([name, server]) => {
169
+ // console.log(
170
+ // name,
171
+ // this.conf.serverName,
172
+ // !isEqual(name, this.conf.serverName),
173
+ // );
174
+ // if (!isEqual(name, this.conf.serverName)) {
175
+ // console.log(
176
+ // `[${this.conf.serverName}] <${session.username}> ${clearSessionContentToMcMessage(session.content)}`,
177
+ // );
178
+ // const msgData: WsMessageData = {
179
+ // api: 'broadcast',
180
+ // data: {
181
+ // message: [
182
+ // {
183
+ // text: `[${this.conf.serverName}] <${session.username}> ${clearSessionContentToMcMessage(session.content)}`,
184
+ // color:
185
+ // server.extractAndRemoveColor(server.config.joinMsg)
186
+ // .color || 'white',
187
+ // },
188
+ // ],
189
+ // },
190
+ // };
191
+ // server.ws?.send(JSON.stringify(msgData));
192
+ // }
193
+ // },
194
+ // );
163
195
  if (this.connectedClients.size > 0) {
164
196
  const msgData = {
165
197
  api: 'broadcast',
@@ -94,8 +94,8 @@ exports.eventList = [
94
94
  // 事件映射
95
95
  function getSubscribedEvents(binaryInput) {
96
96
  const subscribedEvents = [];
97
- const eventValues = Object.values(mcEvent).filter(value => typeof value === 'number');
98
- const eventNames = Object.keys(mcEvent).filter(key => isNaN(Number(key)));
97
+ const eventValues = Object.values(mcEvent)?.filter(value => typeof value === 'number');
98
+ const eventNames = Object.keys(mcEvent)?.filter(key => isNaN(Number(key)));
99
99
  for (let i = 0; i < eventValues.length; i++) {
100
100
  if ((binaryInput & eventValues[i]) !== 0) {
101
101
  subscribedEvents.push(eventNames[i]);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.clearSessionContentToMcMessage = void 0;
4
- const koishi_1 = require("koishi");
5
4
  /**
6
5
  * 清洗数据防止QQ脏数据发送到游戏内
7
6
  */
@@ -22,8 +21,10 @@ const clearSessionContentToMcMessage = (content) => {
22
21
  .replaceAll(/<video.*\/>/gi, '<视频消息>')
23
22
  .replaceAll(/<audio.*\/>/gi, '<音频消息>')
24
23
  // .replaceAll(/<img.*\/>/gi, `[[CICode,url=${imgurl}]]`)
25
- .replaceAll(/<at.*\/>/gi, `@[${koishi_1.h.select(content, 'at')[0]?.attrs?.name
26
- ? koishi_1.h.select(content, 'at')[0]?.attrs?.name
27
- : koishi_1.h.select(content, 'at')[0]?.attrs?.id}]`));
24
+ .replaceAll(/<at.*\/>/gi, `@[${
25
+ // h.select(content, 'at')[0]?.attrs?.name
26
+ // ? h.select(content, 'at')[0]?.attrs?.name
27
+ // : h.select(content, 'at')[0]?.attrs?.id
28
+ '神秘人'}]`));
28
29
  };
29
30
  exports.clearSessionContentToMcMessage = clearSessionContentToMcMessage;
@@ -1 +1,8 @@
1
1
  export * from './game.mc';
2
+ /**
3
+ * 格式化时间差为易读格式
4
+ * @param milliseconds 时间差(毫秒)
5
+ * @returns 格式化后的时间字符串
6
+ */
7
+ export declare function formatDuration(milliseconds: number): string;
8
+ export declare function formatOnlineTime(seconds: number): string;
@@ -14,4 +14,62 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.formatDuration = formatDuration;
18
+ exports.formatOnlineTime = formatOnlineTime;
17
19
  __exportStar(require("./game.mc"), exports);
20
+ /**
21
+ * 格式化时间差为易读格式
22
+ * @param milliseconds 时间差(毫秒)
23
+ * @returns 格式化后的时间字符串
24
+ */
25
+ function formatDuration(milliseconds) {
26
+ if (milliseconds <= 0) {
27
+ return '0分钟';
28
+ }
29
+ const seconds = Math.floor(milliseconds / 1000);
30
+ const minutes = Math.floor(seconds / 60);
31
+ const hours = Math.floor(minutes / 60);
32
+ const days = Math.floor(hours / 24);
33
+ const months = Math.floor(days / 30);
34
+ const years = Math.floor(days / 365);
35
+ if (years > 0) {
36
+ const remainingMonths = Math.floor((days % 365) / 30);
37
+ return remainingMonths > 0
38
+ ? `${years}年${remainingMonths}个月`
39
+ : `${years}年`;
40
+ }
41
+ if (months > 0) {
42
+ const remainingDays = days % 30;
43
+ return remainingDays > 0
44
+ ? `${months}个月${remainingDays}天`
45
+ : `${months}月`;
46
+ }
47
+ if (days > 0) {
48
+ const remainingHours = hours % 24;
49
+ return remainingHours > 0 ? `${days}天${remainingHours}小时` : `${days}天`;
50
+ }
51
+ if (hours > 0) {
52
+ const remainingMinutes = minutes % 60;
53
+ return remainingMinutes > 0
54
+ ? `${hours}小时${remainingMinutes}分钟`
55
+ : `${hours}小时`;
56
+ }
57
+ if (minutes > 0) {
58
+ return `${minutes}分钟`;
59
+ }
60
+ return `${seconds}秒`;
61
+ }
62
+ function formatOnlineTime(seconds) {
63
+ const hours = Math.floor(seconds / 3600);
64
+ const minutes = Math.floor((seconds % 3600) / 60);
65
+ const remainingSeconds = seconds % 60;
66
+ if (hours > 0) {
67
+ return `${hours}小时${minutes}分钟${remainingSeconds}秒`;
68
+ }
69
+ else if (minutes > 0) {
70
+ return `${minutes}分钟${remainingSeconds}秒`;
71
+ }
72
+ else {
73
+ return `${remainingSeconds}秒`;
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-gl-bot",
3
3
  "description": "GleamSlime Koishi Rebot Plugins",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [
@@ -41,6 +41,7 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
+ "@types/ms": "^2.1.0",
44
45
  "lodash": "^4.17.21",
45
46
  "rcon-client": "^4.2.5",
46
47
  "socket.io-client": "^4.8.2",
File without changes
File without changes
File without changes
File without changes
@@ -1,11 +0,0 @@
1
- import { MCSManagerBot } from '../bot';
2
- /**
3
- * 服务器列表指令
4
- *
5
- * @example 服务器 列表
6
- */
7
- export declare class MCBotListCommand {
8
- private readonly bot;
9
- constructor(bot: MCSManagerBot);
10
- handle(status?: string): Promise<string>;
11
- }
@@ -1,26 +0,0 @@
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;
@@ -1,12 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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
- }