koishi-plugin-minecraft-search 1.2.2 → 1.3.1

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 +34 -41
  2. package/package.json +12 -6
  3. package/readme.md +11 -12
package/lib/index.js CHANGED
@@ -26,6 +26,7 @@ __export(src_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(src_exports);
28
28
  var import_koishi = require("koishi");
29
+ var import_mc_server_util = require("mc-server-util");
29
30
  var name = "minecraft-search";
30
31
  var Config = import_koishi.Schema.intersect([
31
32
  import_koishi.Schema.object({
@@ -94,37 +95,16 @@ function apply(ctx, config) {
94
95
  try {
95
96
  const defaultPort = server.serverType === "bedrock" ? 19132 : 25565;
96
97
  const { host, port } = parseServerAddress(server.host, defaultPort);
97
- const apiUrl = `https://motd.minebbs.com/api/status`;
98
- const params = new URLSearchParams();
99
- params.append("ip", host);
100
- params.append("port", port.toString());
101
- params.append("stype", server.serverType === "bedrock" ? "be" : "je");
102
- const response = await ctx.http.get(`${apiUrl}?${params.toString()}`);
103
- const result = {
104
- online: response.status === "online",
105
- host: response.host.split(":")[0],
106
- // 只使用主机名,不包含端口
107
- port: parseInt(response.host.split(":")[1]) || port,
108
- version: {
109
- name: response.version,
110
- name_clean: response.version,
111
- protocol: response.protocol
112
- },
113
- players: {
114
- online: response.players.online,
115
- max: response.players.max,
116
- list: response.players.sample ? [{ name_clean: response.players.sample }] : []
117
- },
118
- motd: {
119
- clean: response.pureMotd,
120
- raw: response.motd.text
121
- },
122
- icon: response.icon,
123
- retrieved_at: (/* @__PURE__ */ new Date()).toISOString(),
124
- // 保留原有结构中的其他字段
125
- software: void 0,
126
- ip_address: host
127
- };
98
+ const timeout = (server.timeout || 5) * 1e3;
99
+ let result;
100
+ if (server.serverType === "bedrock") {
101
+ throw new Error("Bedrock服务器暂不支持");
102
+ } else {
103
+ result = await (0, import_mc_server_util.getMinecraftServerStatus)(host, port, {
104
+ timeout,
105
+ debug: false
106
+ });
107
+ }
128
108
  return {
129
109
  success: true,
130
110
  data: result,
@@ -144,7 +124,7 @@ function apply(ctx, config) {
144
124
  return `🔴 ${server.name} - 离线`;
145
125
  }
146
126
  const players = result.players ? `${result.players.online}/${result.players.max}` : "N/A";
147
- const version = result.version ? result.version.name_clean || result.version.name : "N/A";
127
+ const version = result.version ? result.version.name : "N/A";
148
128
  return `🟢 ${server.name} - 在线 | 玩家: ${players} | 版本: ${version}`;
149
129
  }
150
130
  __name(formatShortStatus, "formatShortStatus");
@@ -153,33 +133,46 @@ function apply(ctx, config) {
153
133
  return `🔴 服务器 ${server.name} (${server.host}) 当前离线`;
154
134
  }
155
135
  let motdText = "暂无描述";
156
- if (result.motd && result.motd.clean) {
157
- motdText = result.motd.clean.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
136
+ if (result.description) {
137
+ let descriptionStr = result.description;
138
+ if (typeof descriptionStr !== "string") {
139
+ if (typeof descriptionStr === "object" && descriptionStr !== null) {
140
+ if (descriptionStr.text) {
141
+ descriptionStr = descriptionStr.text;
142
+ } else {
143
+ descriptionStr = JSON.stringify(descriptionStr);
144
+ }
145
+ } else {
146
+ descriptionStr = String(descriptionStr);
147
+ }
148
+ }
149
+ descriptionStr = descriptionStr.replace(/§[0-9a-fk-or]/gi, "");
150
+ motdText = descriptionStr.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
158
151
  }
152
+ const defaultPort = server.serverType === "bedrock" ? 19132 : 25565;
153
+ const { host, port } = parseServerAddress(server.host, defaultPort);
159
154
  let message = `🟢 ${server.name} 状态信息
160
155
  `;
161
- message += `📡 地址: ${result.host}:${result.port}
156
+ message += `📡 地址: ${host}:${port}
162
157
  `;
163
158
  message += `🎮 类型: ${server.serverType || "Java"}
164
159
  `;
165
160
  if (result.version) {
166
- message += `📦 版本: ${result.version.name_clean || result.version.name}
161
+ message += `📦 版本: ${result.version.name}
167
162
  `;
168
163
  }
169
164
  if (result.players) {
170
165
  message += `👥 人数: ${result.players.online}/${result.players.max}
171
166
  `;
172
- if (result.players.list && result.players.list.length > 0) {
173
- const allPlayers = result.players.list.map((p) => p.name_clean).join(", ");
167
+ if (result.players.sample && result.players.sample.length > 0) {
168
+ const allPlayers = result.players.sample.map((p) => p.name).join(", ");
174
169
  message += `👤 在线玩家: ${allPlayers}
175
170
  `;
176
171
  }
177
172
  }
178
173
  message += `📋 MOTD: ${motdText}
179
174
  `;
180
- if (result.software) {
181
- }
182
- message += `⏰ 查询时间: ${new Date(result.retrieved_at).toLocaleString("zh-CN")}`;
175
+ message += `⏰ 查询时间: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`;
183
176
  return message;
184
177
  }
185
178
  __name(formatDetailedStatus, "formatDetailedStatus");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-search",
3
3
  "description": "使用API查询基础的mc服务器信息",
4
- "version": "1.2.2",
4
+ "version": "1.3.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -12,14 +12,20 @@
12
12
  "keywords": [
13
13
  "chatbot",
14
14
  "koishi",
15
- "plugin"
15
+ "plugin",
16
+ "minecraft",
17
+ "server",
18
+ "status"
16
19
  ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/yourusername/koishi-plugin-minecraft-search.git"
23
+ },
24
+ "homepage": "https://github.com/yourusername/koishi-plugin-minecraft-search",
17
25
  "peerDependencies": {
18
26
  "koishi": "^4.18.7"
19
27
  },
20
- "homepage": "https://github.com/forgetmelodyXL/minecraft-search",
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/forgetmelodyXL/minecraft-search.git"
28
+ "dependencies": {
29
+ "mc-server-util": "^1.0.0"
24
30
  }
25
31
  }
package/readme.md CHANGED
@@ -7,10 +7,11 @@
7
7
  ## 功能特性
8
8
 
9
9
  ### 🎮 服务器状态查询
10
- - 支持 Java 版和基岩版服务器
10
+ - 支持 Java 版服务器
11
11
  - 支持查询全部服务器状态(简短信息)
12
12
  - 支持查询指定服务器状态(详细信息)
13
- - 可配置查询超时时间和 Query 查询选项
13
+ - 可配置查询超时时间
14
+ - 自动移除 Minecraft 颜色代码,显示纯文本 MOTD
14
15
 
15
16
  ### ⚡ 服务器电源控制
16
17
  - 支持通过麦块联机 API 启动服务器
@@ -80,9 +81,7 @@ minekuaiSettings: {
80
81
 
81
82
  ### 服务器类型 (serverType)
82
83
  - `java`:Java 版服务器(默认)
83
- - `bedrock`:基岩版服务器
84
-
85
-
84
+ - `bedrock`:基岩版服务器(暂不支持)
86
85
 
87
86
  ### 超时时间 (timeout)
88
87
  - 默认值:5.0 秒
@@ -98,7 +97,7 @@ minekuaiSettings: {
98
97
 
99
98
  ## 依赖说明
100
99
 
101
- - 使用 https://motd.minebbs.com/api/status API 进行服务器状态查询
100
+ - 使用 https://www.npmjs.com/package/mc-server-util 库进行服务器状态查询
102
101
  - 支持麦块联机平台的 API 集成
103
102
  - 基于 Koishi 框架开发
104
103
 
@@ -119,12 +118,12 @@ minekuaiSettings: {
119
118
 
120
119
  ## 更新日志
121
120
 
122
- ### v1.2.0
123
- - 新增强制重启服务器功能
124
- - 修正包名为 koishi-plugin-minecraft-search
125
- - 更新服务器状态查询使用 minebbs.com API
126
- - 优化服务器状态查询输出格式,添加服务器ID显示
127
- - 改进服务器状态汇总信息,显示在线服务器数量
121
+ ### v1.3.0
122
+ - 替换服务器状态查询库为 mc-server-util
123
+ - 移除对基岩版服务器的支持(暂不支持)
124
+ - 移除 Query 查询选项
125
+ - 添加自动移除 Minecraft 颜色代码功能
126
+ - 优化错误处理和类型检查
128
127
 
129
128
  ### v1.1.1
130
129
  - 初始版本发布