koishi-plugin-minecraft-search 2.0.13 → 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 +25 -12
  2. package/package.json +1 -1
  3. package/readme.md +7 -0
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
  }
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.13",
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 启动服务器
@@ -188,6 +189,12 @@ 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
+
191
198
  ### v2.0.13
192
199
  - 优化 `mc/修改服务器` 指令,新增 `-a` 选项支持合并输入服务器地址和端口
193
200
  - 支持类似 `127.0.0.1:25565` 的格式,代码自动分离IP和端口