koishi-plugin-minecraft-search 2.0.0 → 2.0.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 +16 -14
  2. package/package.json +1 -1
  3. package/readme.md +16 -4
package/lib/index.js CHANGED
@@ -152,6 +152,7 @@ function apply(ctx, config) {
152
152
  errorMessage = errorMessage.replace(/getaddrinfo EAI_AGAIN/i, "网络波动,请稍后尝试");
153
153
  errorMessage = errorMessage.replace(/\s+(\d+\.\d+\.\d+\.\d+):\d+/, "");
154
154
  errorMessage = errorMessage.replace(/\s+[\w.-]+$/, "");
155
+ errorMessage = errorMessage.replace(/\s+[a-zA-Z0-9][a-zA-Z0-9.-]*:[0-9]+/, "");
155
156
  return {
156
157
  success: false,
157
158
  error: errorMessage,
@@ -177,11 +178,7 @@ function apply(ctx, config) {
177
178
  function formatDetailedStatus(result, server, showIp) {
178
179
  const displayName = getServerName(server);
179
180
  if (!result.online) {
180
- if (showIp) {
181
- return `🔴 ${displayName} (${server.host}) 当前离线`;
182
- } else {
183
- return `🔴 ${displayName} 当前离线`;
184
- }
181
+ return `🔴 ${displayName} 当前离线`;
185
182
  }
186
183
  let motdText = "暂无描述";
187
184
  if (result.description) {
@@ -283,11 +280,11 @@ function apply(ctx, config) {
283
280
  };
284
281
  const result = await queryServerStatus(tempServer);
285
282
  if (!result.success) {
286
- return `🔴 服务器 ${parsedHost}:${parsedPort} - 离线 | 原因:${result.error}`;
283
+ return `🔴 服务器 - 离线 | 原因:${result.error}`;
287
284
  }
288
285
  return formatDetailedStatus(result.data, tempServer, config.showIpInDetail);
289
286
  });
290
- ctx.guild().command("mc/绑定 <host:string>", "绑定Minecraft服务器").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 5 }).action(async ({ session, options }, host) => {
287
+ ctx.guild().command("mc/绑定 <host:string>", "绑定Minecraft服务器").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 5 }).option("instance", "-i <instance:string>", { fallback: "" }).action(async ({ session, options }, host) => {
291
288
  if (!host) {
292
289
  return "请提供服务器地址,例如:绑定+IP地址(不带端口时默认为25565)";
293
290
  }
@@ -301,7 +298,7 @@ function apply(ctx, config) {
301
298
  port: parsedPort
302
299
  });
303
300
  if (existingServers.length > 0) {
304
- return `该服务器 (${parsedHost}:${parsedPort}) 已在本群绑定,服务器ID为: ${existingServers[0].id}`;
301
+ return `该服务器已在本群绑定,服务器ID为: ${existingServers[0].id}`;
305
302
  }
306
303
  const createData = {
307
304
  userId,
@@ -310,7 +307,7 @@ function apply(ctx, config) {
310
307
  port: parsedPort,
311
308
  serverType: "java",
312
309
  timeout: options.timeout,
313
- minekuaiInstanceId: ""
310
+ minekuaiInstanceId: options.instance
314
311
  };
315
312
  if (options.name) {
316
313
  createData.name = options.name;
@@ -320,8 +317,7 @@ function apply(ctx, config) {
320
317
  const newServer = servers[servers.length - 1];
321
318
  return `✅ 服务器绑定成功!
322
319
  服务器ID: ${newServer.id}
323
- 名称: ${newServer.name || "Minecraft 服务器"}
324
- 地址: ${parsedHost}:${parsedPort}`;
320
+ 名称: ${newServer.name || "Minecraft 服务器"}`;
325
321
  });
326
322
  ctx.guild().command("mc/绑定密钥 <apiKey:string>", "绑定麦块API密钥").action(async ({ session }, apiKey) => {
327
323
  if (!apiKey) {
@@ -354,7 +350,7 @@ function apply(ctx, config) {
354
350
  await ctx.database.remove("minecraft_server", { id });
355
351
  return `✅ 服务器 ${server.name} 已解绑`;
356
352
  });
357
- ctx.guild().command("mc/修改 <id:number>", "修改Minecraft服务器信息").option("name", "-n <name:string>", { fallback: "" }).option("timeout", "-t <timeout:number>", { fallback: 0 }).action(async ({ session, options }, id) => {
353
+ 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) => {
358
354
  if (!id) {
359
355
  return "请提供服务器ID,例如:修改 1";
360
356
  }
@@ -371,13 +367,17 @@ function apply(ctx, config) {
371
367
  if (options.timeout > 0) {
372
368
  updates.timeout = options.timeout;
373
369
  }
370
+ if (options.instance) {
371
+ updates.minekuaiInstanceId = options.instance;
372
+ }
374
373
  if (Object.keys(updates).length === 0) {
375
- return "请提供要修改的参数,使用 -n 指定新名称,-t 指定新超时时间";
374
+ return "请提供要修改的参数,使用 -n 指定新名称,-t 指定新超时时间,-i 指定新麦块实例ID";
376
375
  }
377
376
  await ctx.database.set("minecraft_server", { id }, updates);
378
377
  const parts = [];
379
378
  if (updates.name) parts.push(`名称: ${updates.name}`);
380
379
  if (updates.timeout) parts.push(`超时: ${updates.timeout}秒`);
380
+ if (updates.minekuaiInstanceId) parts.push(`麦块实例ID: ${updates.minekuaiInstanceId}`);
381
381
  return `✅ 服务器信息已更新!
382
382
  ${parts.join("\n")}`;
383
383
  });
@@ -498,8 +498,10 @@ ${parts.join("\n")}`;
498
498
  servers.forEach((server) => {
499
499
  message += `[ID:${server.id}] ${server.name}
500
500
  `;
501
- message += ` 地址: ${server.host}:${server.port}
501
+ if (config.showIpInDetail) {
502
+ message += ` 地址: ${server.host}:${server.port}
502
503
  `;
504
+ }
503
505
  message += ` 类型: ${server.serverType} | 超时: ${server.timeout}秒
504
506
  `;
505
507
  if (server.minekuaiInstanceId) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-minecraft-search",
3
3
  "description": "使用API查询基础的mc服务器信息",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -61,9 +61,9 @@ npm install koishi-plugin-minecraft-search
61
61
 
62
62
  ### 服务器管理
63
63
  ```
64
- mc/绑定 <host> [-n <name>] [-t <timeout>] # 绑定服务器,支持指定名称和超时时间
64
+ mc/绑定 <host> [-n <name>] [-t <timeout>] [-i <instance>] # 绑定服务器,支持指定名称、超时时间和麦块实例ID
65
65
  mc/解绑 <id> # 解绑服务器
66
- mc/修改 <id> [-n <name>] [-t <timeout>] # 修改服务器信息
66
+ mc/修改 <id> [-n <name>] [-t <timeout>] [-i <instance>] # 修改服务器信息,支持修改名称、超时时间和麦块实例ID
67
67
  mc/服务器列表 # 查看已绑定的服务器列表
68
68
  mc/设置实例 <id> <instanceId> # 设置服务器的麦块实例ID
69
69
  mc/绑定API密钥 <apiKey> # 绑定麦块API密钥
@@ -73,6 +73,7 @@ mc/绑定API密钥 <apiKey> # 绑定麦块API密钥
73
73
  ```
74
74
  mc/查服 # 查询全部服务器状态(简短信息)
75
75
  mc/查服 1 # 查询ID为1的服务器的详细信息
76
+ mc/查服 <ip> # 直接输入IP地址查询服务器状态
76
77
  ```
77
78
 
78
79
  **输出示例:**
@@ -115,14 +116,16 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
115
116
  ## 指令说明
116
117
 
117
118
  ### 绑定服务器
118
- - **命令**:`mc/绑定 <host> [-n <name>] [-t <timeout>]`
119
+ - **命令**:`mc/绑定 <host> [-n <name>] [-t <timeout>] [-i <instance>]`
119
120
  - **参数**:
120
121
  - `<host>`:服务器地址,支持带端口格式(如:`play.example.com:25565`)
121
122
  - `-n <name>`:服务器名称(可选,默认使用地址作为名称)
122
123
  - `-t <timeout>`:查询超时时间(可选,默认5秒)
124
+ - `-i <instance>`:麦块实例ID(可选,用于电源控制)
123
125
  - **示例**:
124
126
  - `mc/绑定 s3.ungc.com.cn` - 绑定默认端口的服务器
125
127
  - `mc/绑定 s3.ungc.com.cn:37095 -n 测试服 -t 10` - 绑定指定端口、名称和超时的服务器
128
+ - `mc/绑定 s3.ungc.com.cn -i abc123` - 绑定服务器并设置麦块实例ID
126
129
 
127
130
  ### 绑定API密钥
128
131
  - **命令**:`mc/绑定API密钥 <apiKey>`
@@ -132,7 +135,7 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
132
135
 
133
136
  ### 服务器管理指令
134
137
  - **`mc/解绑 <id>`**:解绑指定ID的服务器
135
- - **`mc/修改 <id> [-n <name>] [-t <timeout>]`**:修改服务器名称或超时时间
138
+ - **`mc/修改 <id> [-n <name>] [-t <timeout>] [-i <instance>]`**:修改服务器名称、超时时间或麦块实例ID
136
139
  - **`mc/设置实例 <id> <instanceId>`**:为服务器设置麦块实例ID,用于电源控制
137
140
  - **`mc/服务器列表`**:查看当前群组已绑定的所有服务器
138
141
 
@@ -151,6 +154,8 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
151
154
  - 🛡️ **错误处理**:完善的错误处理和用户提示
152
155
  - 🗄️ **数据库存储**:使用数据库存储服务器配置,支持多群组管理
153
156
  - 🔒 **权限控制**:每个群组只能管理自己绑定的服务器
157
+ - 🌐 **直接IP查询**:支持直接输入IP地址查询服务器状态
158
+ - 🔧 **实例ID管理**:支持在绑定和修改服务器时直接设置麦块实例ID
154
159
 
155
160
  ## 依赖说明
156
161
 
@@ -179,6 +184,13 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
179
184
  <details>
180
185
  <summary>点我查看更新日志详情</summary>
181
186
 
187
+ ### v2.0.1
188
+ - 新增绑定服务器时支持 -i 选项直接设置麦块实例ID
189
+ - 新增修改服务器时支持 -i 选项修改麦块实例ID
190
+ - 新增支持直接输入IP地址查询服务器状态
191
+ - 优化服务器绑定逻辑,避免重复绑定
192
+ - 完善错误提示信息
193
+
182
194
  ### v2.0.0
183
195
  - 全新数据库存储架构,支持多群组管理
184
196
  - 新增服务器绑定、解绑、修改等管理指令