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 CHANGED
@@ -5,6 +5,7 @@ export interface ServerConfig {
5
5
  name: string;
6
6
  host: string;
7
7
  minekuaiInstanceId?: string;
8
+ timeout?: number;
8
9
  serverType?: 'java' | 'bedrock';
9
10
  }
10
11
  export interface Config {
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://api.imlazy.ink/mcapi/?name=${encodeURIComponent(server.name)}&host=${encodeURIComponent(`${host}:${port}`)}&type=json&getmotd=%0a%0a&getbg=1.jpg`;
97
- const response = await ctx.http.get(apiUrl);
98
- let versionInfo = null;
99
- if (response.motd && response.motd.text) {
100
- const cleanMotd = response.motd.text.replace(/§[0-9a-fk-or]/gi, "");
101
- const versionMatch = cleanMotd.match(/(v?\d+\.\d+\.?\d*)/);
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
- port,
113
- players: response.players_online !== null ? {
114
- online: response.players_online,
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
- } : versionInfo,
122
- motd: response.motd ? {
123
- clean: response.motd.text.replace(/§[0-9a-fk-or]/gi, ""),
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
- } : null,
126
- software: response.software,
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,
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.0",
4
+ "version": "1.2.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [