koishi-plugin-minecraft-search 1.2.0 → 1.2.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.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +28 -29
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -34,6 +34,7 @@ var Config = import_koishi.Schema.intersect([
|
|
|
34
34
|
name: import_koishi.Schema.string().required().description("服务器名称"),
|
|
35
35
|
host: import_koishi.Schema.string().required().description("服务器地址"),
|
|
36
36
|
serverType: import_koishi.Schema.union(["java", "bedrock"]).default("java").description("服务器类型"),
|
|
37
|
+
timeout: import_koishi.Schema.number().default(5).description("查询超时时间(秒)"),
|
|
37
38
|
minekuaiInstanceId: import_koishi.Schema.string().description("麦块实例ID (可选)")
|
|
38
39
|
})).description("服务器列表").role("table").required()
|
|
39
40
|
}).description("服务器配置"),
|
|
@@ -93,38 +94,36 @@ function apply(ctx, config) {
|
|
|
93
94
|
try {
|
|
94
95
|
const defaultPort = server.serverType === "bedrock" ? 19132 : 25565;
|
|
95
96
|
const { host, port } = parseServerAddress(server.host, defaultPort);
|
|
96
|
-
const apiUrl = `https://
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (versionMatch) {
|
|
103
|
-
versionInfo = {
|
|
104
|
-
name: versionMatch[0],
|
|
105
|
-
name_clean: versionMatch[0]
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
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()}`);
|
|
109
103
|
const result = {
|
|
110
|
-
online: response.status === "
|
|
111
|
-
host,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
max: response.players_max,
|
|
116
|
-
list: response.players
|
|
117
|
-
} : null,
|
|
118
|
-
version: response.version ? {
|
|
104
|
+
online: response.status === "online",
|
|
105
|
+
host: response.host.split(":")[0],
|
|
106
|
+
// 只使用主机名,不包含端口
|
|
107
|
+
port: parseInt(response.host.split(":")[1]) || port,
|
|
108
|
+
version: {
|
|
119
109
|
name: response.version,
|
|
120
|
-
name_clean: response.version
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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,
|
|
124
120
|
raw: response.motd.text
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
retrieved_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
121
|
+
},
|
|
122
|
+
icon: response.icon,
|
|
123
|
+
retrieved_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
124
|
+
// 保留原有结构中的其他字段
|
|
125
|
+
software: void 0,
|
|
126
|
+
ip_address: host
|
|
128
127
|
};
|
|
129
128
|
return {
|
|
130
129
|
success: true,
|