koishi-plugin-minecraft-search 2.0.0 → 2.0.2
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.js +29 -27
- package/package.json +1 -1
- 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
|
-
|
|
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 `🔴 服务器
|
|
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
|
|
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) {
|
|
@@ -352,9 +348,9 @@ function apply(ctx, config) {
|
|
|
352
348
|
return `❌ 未找到ID为 ${id} 的服务器`;
|
|
353
349
|
}
|
|
354
350
|
await ctx.database.remove("minecraft_server", { id });
|
|
355
|
-
return `✅
|
|
351
|
+
return `✅ 服务器已解绑`;
|
|
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
|
});
|
|
@@ -387,12 +387,12 @@ ${parts.join("\n")}`;
|
|
|
387
387
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
388
388
|
const server = servers.find((s) => s.id === id);
|
|
389
389
|
if (!server) return `❌ 未找到ID为 ${id} 的服务器,请确保操作的是本群绑定的服务器`;
|
|
390
|
-
if (!server.minekuaiInstanceId) return
|
|
390
|
+
if (!server.minekuaiInstanceId) return `${server.name} 未配置麦块实例ID`;
|
|
391
391
|
try {
|
|
392
392
|
await minekuaiApiRequest(server.minekuaiInstanceId, "start", groupId, 3);
|
|
393
|
-
return `✅
|
|
393
|
+
return `✅ 已发送启动指令到 ${server.name} (ID: ${id})`;
|
|
394
394
|
} catch (error) {
|
|
395
|
-
return `❌
|
|
395
|
+
return `❌ 启动服务器失败: ${error.message}`;
|
|
396
396
|
}
|
|
397
397
|
});
|
|
398
398
|
ctx.guild().command("mc/重启 <id:number>", "重启麦块服务器").action(async ({ session }, id) => {
|
|
@@ -401,12 +401,12 @@ ${parts.join("\n")}`;
|
|
|
401
401
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
402
402
|
const server = servers.find((s) => s.id === id);
|
|
403
403
|
if (!server) return `❌ 未找到ID为 ${id} 的服务器,请确保操作的是本群绑定的服务器`;
|
|
404
|
-
if (!server.minekuaiInstanceId) return
|
|
404
|
+
if (!server.minekuaiInstanceId) return `${server.name} 未配置麦块实例ID`;
|
|
405
405
|
try {
|
|
406
406
|
await minekuaiApiRequest(server.minekuaiInstanceId, "restart", groupId, 3);
|
|
407
|
-
return `✅
|
|
407
|
+
return `✅ ${server.name} 重启指令已发送完成,请稍后检查服务器状态`;
|
|
408
408
|
} catch (error) {
|
|
409
|
-
return `❌
|
|
409
|
+
return `❌ 重启服务器失败: ${error.message}`;
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
412
|
ctx.guild().command("mc/强制重启 <id:number>", "强制重启麦块服务器").action(async ({ session }, id) => {
|
|
@@ -415,16 +415,16 @@ ${parts.join("\n")}`;
|
|
|
415
415
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
416
416
|
const server = servers.find((s) => s.id === id);
|
|
417
417
|
if (!server) return `❌ 未找到ID为 ${id} 的服务器,请确保操作的是本群绑定的服务器`;
|
|
418
|
-
if (!server.minekuaiInstanceId) return
|
|
418
|
+
if (!server.minekuaiInstanceId) return `${server.name} 未配置麦块实例ID`;
|
|
419
419
|
try {
|
|
420
420
|
await minekuaiApiRequest(server.minekuaiInstanceId, "stop", groupId, 3);
|
|
421
421
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
422
422
|
await minekuaiApiRequest(server.minekuaiInstanceId, "kill", groupId, 3);
|
|
423
423
|
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
424
424
|
await minekuaiApiRequest(server.minekuaiInstanceId, "start", groupId, 3);
|
|
425
|
-
return `✅
|
|
425
|
+
return `✅ ${server.name} 强制重启指令已发送完成,请稍后检查服务器状态`;
|
|
426
426
|
} catch (error) {
|
|
427
|
-
return `❌
|
|
427
|
+
return `❌ 强制重启服务器失败: ${error.message}`;
|
|
428
428
|
}
|
|
429
429
|
});
|
|
430
430
|
ctx.guild().command("mc/资源 <id:number>", "查看麦块服务器资源使用情况").action(async ({ session }, id) => {
|
|
@@ -433,7 +433,7 @@ ${parts.join("\n")}`;
|
|
|
433
433
|
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
434
434
|
const server = servers.find((s) => s.id === id);
|
|
435
435
|
if (!server) return `❌ 未找到ID为 ${id} 的服务器,请确保操作的是本群绑定的服务器`;
|
|
436
|
-
if (!server.minekuaiInstanceId) return
|
|
436
|
+
if (!server.minekuaiInstanceId) return `${server.name} 未配置麦块实例ID`;
|
|
437
437
|
try {
|
|
438
438
|
const apiKeys = await ctx.database.get("minecraft_api_key", { groupId });
|
|
439
439
|
if (!apiKeys || apiKeys.length === 0) {
|
|
@@ -483,7 +483,7 @@ ${parts.join("\n")}`;
|
|
|
483
483
|
message += `⏰ 查询时间: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`;
|
|
484
484
|
return message;
|
|
485
485
|
} catch (error) {
|
|
486
|
-
return `❌
|
|
486
|
+
return `❌ 查询服务器资源使用情况失败: ${error.message}`;
|
|
487
487
|
}
|
|
488
488
|
});
|
|
489
489
|
ctx.guild().command("mc/服务器列表", "查看已绑定的服务器列表").action(async ({ session }) => {
|
|
@@ -498,8 +498,10 @@ ${parts.join("\n")}`;
|
|
|
498
498
|
servers.forEach((server) => {
|
|
499
499
|
message += `[ID:${server.id}] ${server.name}
|
|
500
500
|
`;
|
|
501
|
-
|
|
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) {
|
|
@@ -521,7 +523,7 @@ ${parts.join("\n")}`;
|
|
|
521
523
|
return `❌ 未找到ID为 ${id} 的服务器`;
|
|
522
524
|
}
|
|
523
525
|
await ctx.database.set("minecraft_server", { id }, { minekuaiInstanceId: instanceId });
|
|
524
|
-
return `✅
|
|
526
|
+
return `✅ ${server.name} 的麦块实例ID已设置为: ${instanceId}`;
|
|
525
527
|
});
|
|
526
528
|
}
|
|
527
529
|
__name(apply, "apply");
|
package/package.json
CHANGED
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
|
- 新增服务器绑定、解绑、修改等管理指令
|