koishi-plugin-minecraft-search 2.0.12 → 2.0.14

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 (3) hide show
  1. package/lib/index.js +33 -14
  2. package/package.json +1 -1
  3. package/readme.md +33 -5
package/lib/index.js CHANGED
@@ -199,20 +199,33 @@ function apply(ctx, config) {
199
199
  if (!result.online) {
200
200
  return `🔴 ${displayName} 当前离线`;
201
201
  }
202
- let motdText = "暂无描述";
203
- if (result.description) {
204
- let descriptionStr = result.description;
205
- if (typeof descriptionStr !== "string") {
206
- if (typeof descriptionStr === "object" && descriptionStr !== null) {
207
- if (descriptionStr.text) {
208
- descriptionStr = descriptionStr.text;
209
- } else {
210
- descriptionStr = JSON.stringify(descriptionStr);
211
- }
212
- } else {
213
- descriptionStr = String(descriptionStr);
202
+ function parseChatComponent(component) {
203
+ if (!component) return "";
204
+ if (typeof component === "string") return component;
205
+ if (typeof component !== "object") return String(component);
206
+ let text = "";
207
+ if (component.text) {
208
+ text += component.text;
209
+ }
210
+ if (component.translate) {
211
+ text += component.translate;
212
+ }
213
+ if (Array.isArray(component.extra)) {
214
+ for (const extra of component.extra) {
215
+ text += parseChatComponent(extra);
214
216
  }
215
217
  }
218
+ if (Array.isArray(component.with)) {
219
+ for (const w of component.with) {
220
+ text += parseChatComponent(w);
221
+ }
222
+ }
223
+ return text;
224
+ }
225
+ __name(parseChatComponent, "parseChatComponent");
226
+ let motdText = "暂无描述";
227
+ if (result.description) {
228
+ let descriptionStr = parseChatComponent(result.description);
216
229
  descriptionStr = descriptionStr.replace(/§[0-9a-fk-or]/gi, "");
217
230
  motdText = descriptionStr.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
218
231
  }
@@ -387,7 +400,7 @@ function apply(ctx, config) {
387
400
  await ctx.database.remove("minecraft_server", { id });
388
401
  return `✅ 服务器已解绑`;
389
402
  });
390
- ctx.guild().command("mc/修改服务器 <id:number>", "修改Minecraft服务器信息").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 0 }).option("instance", "-i <instance:string>", { fallback: "" }).action(async ({ session, options }, id) => {
403
+ ctx.guild().command("mc/修改服务器 <id:number>", "修改Minecraft服务器信息").option("name", "-n <name:string>", { fallback: "" }).option("address", "-a <address:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 0 }).option("instance", "-i <instance:string>", { fallback: "" }).action(async ({ session, options }, id) => {
391
404
  const permissionError = await checkPermission(session, config);
392
405
  if (permissionError) {
393
406
  return permissionError;
@@ -405,6 +418,11 @@ function apply(ctx, config) {
405
418
  if (options.name) {
406
419
  updates.name = options.name;
407
420
  }
421
+ if (options.address) {
422
+ const { host, port } = parseServerAddress(options.address, 25565);
423
+ updates.host = host;
424
+ updates.port = port;
425
+ }
408
426
  if (options.timeout > 0) {
409
427
  updates.timeout = options.timeout;
410
428
  }
@@ -412,11 +430,12 @@ function apply(ctx, config) {
412
430
  updates.minekuaiInstanceId = options.instance;
413
431
  }
414
432
  if (Object.keys(updates).length === 0) {
415
- return "请提供要修改的参数,使用 -n 指定新名称,-t 指定新超时时间,-i 指定新麦块实例ID";
433
+ return "请提供要修改的参数,使用 -n 指定新名称,-a 指定新地址(格式: IP:端口,不带端口时默认为25565),-t 指定新超时时间,-i 指定新麦块实例ID";
416
434
  }
417
435
  await ctx.database.set("minecraft_server", { id }, updates);
418
436
  const parts = [];
419
437
  if (updates.name) parts.push(`名称: ${updates.name}`);
438
+ if (updates.host) parts.push(`地址: ${updates.host}:${updates.port}`);
420
439
  if (updates.timeout) parts.push(`超时: ${updates.timeout}秒`);
421
440
  if (updates.minekuaiInstanceId) parts.push(`麦块实例ID: ${updates.minekuaiInstanceId}`);
422
441
  return `✅ 服务器信息已更新!
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-search",
3
3
  "description": "用于查询Minecraft服务器状态。如果服务器来自于麦块联机,那么可以查询指定服务器的详细资源使用情况,甚至还能对指定服务器进行电源开启或重启操作",
4
- "version": "2.0.12",
4
+ "version": "2.0.14",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -12,6 +12,7 @@
12
12
  - 支持查询指定服务器状态(详细信息)
13
13
  - 可配置查询超时时间
14
14
  - 自动移除 Minecraft 颜色代码,显示纯文本 MOTD
15
+ - 支持解析聊天组件格式 MOTD(包括 translate、extra、with 等字段)
15
16
 
16
17
  ### ⚡ 服务器电源控制
17
18
  - 支持通过麦块联机 API 启动服务器
@@ -65,7 +66,7 @@ npm install koishi-plugin-minecraft-search
65
66
  ```
66
67
  mc/绑定服务器 <host> [-n <name>] [-t <timeout>] [-i <instance>] # 绑定服务器,支持指定名称、超时时间和麦块实例ID
67
68
  mc/解绑服务器 <id> # 解绑服务器
68
- mc/修改服务器 <id> [-n <name>] [-t <timeout>] [-i <instance>] # 修改服务器信息,支持修改名称、超时时间和麦块实例ID
69
+ mc/修改服务器 <id> [-n <name>] [-a <address>] [-t <timeout>] [-i <instance>] # 修改服务器信息,支持修改名称、地址、超时时间和麦块实例ID
69
70
  mc/服务器列表 # 查看已绑定的服务器列表
70
71
  mc/设置实例 <id> <instanceId> # 设置服务器的麦块实例ID
71
72
  mc/绑定API密钥 <apiKey> # 绑定麦块API密钥
@@ -126,9 +127,9 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
126
127
  - `-t <timeout>`:查询超时时间(可选,默认5秒)
127
128
  - `-i <instance>`:麦块实例ID(可选,用于电源控制)
128
129
  - **示例**:
129
- - `mc/绑定服务器 s3.ungc.com.cn` - 绑定默认端口的服务器
130
- - `mc/绑定服务器 s3.ungc.com.cn:37095 -n 测试服 -t 10` - 绑定指定端口、名称和超时的服务器
131
- - `mc/绑定服务器 s3.ungc.com.cn -i abc123` - 绑定服务器并设置麦块实例ID
130
+ - `mc/绑定服务器 127.0.0.1` - 绑定默认端口的服务器
131
+ - `mc/绑定服务器 127.0.0.1:25565 -n 测试服 -t 10` - 绑定指定端口、名称和超时的服务器
132
+ - `mc/绑定服务器 127.0.0.1 -i abc123` - 绑定服务器并设置麦块实例ID
132
133
 
133
134
  ### 绑定API密钥
134
135
  - **命令**:`mc/绑定API密钥 <apiKey>`
@@ -138,7 +139,7 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
138
139
 
139
140
  ### 服务器管理指令
140
141
  - **`mc/解绑服务器 <id>`**:解绑指定ID的服务器
141
- - **`mc/修改服务器 <id> [-n <name>] [-t <timeout>] [-i <instance>]`**:修改服务器名称、超时时间或麦块实例ID
142
+ - **`mc/修改服务器 <id> [-n <name>] [-a <address>] [-t <timeout>] [-i <instance>]`**:修改服务器名称、地址、超时时间或麦块实例ID,其中 `-a` 选项支持合并输入IP和端口(如 `127.0.0.1:25565`),不带端口时默认使用25565端口
142
143
  - **`mc/设置实例 <id> <instanceId>`**:为服务器设置麦块实例ID,用于电源控制
143
144
  - **`mc/服务器列表`**:查看当前群组已绑定的所有服务器
144
145
  - **`mc/服务器状态 <id> [状态]`**:查询或设置服务器活跃状态(状态:启用/停用)
@@ -188,6 +189,33 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
188
189
  <details>
189
190
  <summary>点我查看更新日志详情</summary>
190
191
 
192
+ ### v2.0.14
193
+ - 优化 MOTD 解析,支持 Minecraft 聊天组件格式
194
+ - 新增对 `translate` 字段的支持,兼容 1.12.2 等旧版本服务器
195
+ - 支持解析 `extra` 和 `with` 数组字段
196
+ - 修复旧版本服务器 MOTD 显示原始 JSON 的问题
197
+
198
+ ### v2.0.13
199
+ - 优化 `mc/修改服务器` 指令,新增 `-a` 选项支持合并输入服务器地址和端口
200
+ - 支持类似 `127.0.0.1:25565` 的格式,代码自动分离IP和端口
201
+ - 不带端口时默认使用25565端口
202
+
203
+ ### v2.0.12
204
+ - 修复指令名称不一致问题,统一使用"绑定API密钥"指令名称
205
+
206
+ ### v2.0.11
207
+ - 新增服务器活跃状态管理功能
208
+ - 在 minecraft_server 数据库中添加 active 字段(boolean 类型)
209
+ - 绑定服务器后默认设置为活跃状态
210
+ - 新增 `mc/服务器状态` 指令,支持查询和设置服务器活跃状态
211
+ - 修改 `mc/查服` 指令,过滤掉不活跃的服务器
212
+ - 修改 `mc/服务器列表` 指令,显示服务器活跃状态
213
+ - 当查询不活跃的服务器时,显示提示信息
214
+ - 兼容旧数据:已存在的服务器 active 字段为 null 时,视为活跃状态
215
+
216
+ ### v2.0.10
217
+ - 优化指令命名,将"绑定"改为"绑定服务器","解绑"改为"解绑服务器","修改"改为"修改服务器"
218
+
191
219
  ### v2.0.9
192
220
  - 修复指令名称不一致问题,统一使用"绑定API密钥"指令名称
193
221