koishi-plugin-minecraft-search 2.0.7 → 2.0.9
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 +43 -8
- package/package.json +1 -1
- package/readme.md +18 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -67,7 +67,8 @@ function apply(ctx, config) {
|
|
|
67
67
|
port: "integer",
|
|
68
68
|
serverType: "string",
|
|
69
69
|
timeout: "float",
|
|
70
|
-
minekuaiInstanceId: "string"
|
|
70
|
+
minekuaiInstanceId: "string",
|
|
71
|
+
active: "boolean"
|
|
71
72
|
}, {
|
|
72
73
|
autoInc: true,
|
|
73
74
|
primary: "id"
|
|
@@ -246,10 +247,11 @@ function apply(ctx, config) {
|
|
|
246
247
|
ctx.guild().command("mc/查服 [target:text]", "查询Minecraft服务器状态").action(async ({ session }, target) => {
|
|
247
248
|
const servers = await ctx.database.get("minecraft_server", {});
|
|
248
249
|
if (target === void 0) {
|
|
249
|
-
|
|
250
|
-
|
|
250
|
+
const activeServers = servers.filter((server) => server.active !== false);
|
|
251
|
+
if (activeServers.length === 0) {
|
|
252
|
+
return "❌ 本群未绑定任何服务器,请先使用 绑定服务器 指令";
|
|
251
253
|
}
|
|
252
|
-
const queries =
|
|
254
|
+
const queries = activeServers.map((server) => queryServerStatus(server));
|
|
253
255
|
const results = await Promise.all(queries);
|
|
254
256
|
const onlineCount = results.filter((r) => r.success && r.data && r.data.online).length;
|
|
255
257
|
let message = `📊 服务器状态汇总 (当前在线${onlineCount}/${results.length}台)
|
|
@@ -267,7 +269,7 @@ function apply(ctx, config) {
|
|
|
267
269
|
}
|
|
268
270
|
});
|
|
269
271
|
message += `
|
|
270
|
-
💡 输入"查服+服务器ID"即可查询详细状态,例如:查服 ${
|
|
272
|
+
💡 输入"查服+服务器ID"即可查询详细状态,例如:查服 ${activeServers[0]?.id || 1}`;
|
|
271
273
|
message += `
|
|
272
274
|
💡 也可以直接输入IP地址查询`;
|
|
273
275
|
return message;
|
|
@@ -276,6 +278,9 @@ function apply(ctx, config) {
|
|
|
276
278
|
if (!isNaN(id)) {
|
|
277
279
|
const server = servers.find((s) => s.id === id);
|
|
278
280
|
if (server) {
|
|
281
|
+
if (server.active === false) {
|
|
282
|
+
return `❌ 服务器 ${server.name} (ID: ${id}) 处于不活跃状态,无法查询`;
|
|
283
|
+
}
|
|
279
284
|
const result2 = await queryServerStatus(server);
|
|
280
285
|
if (!result2.success) {
|
|
281
286
|
return `🔴 ${getServerName(server)} - 离线 | 原因:${result2.error}`;
|
|
@@ -294,7 +299,8 @@ function apply(ctx, config) {
|
|
|
294
299
|
host: parsedHost,
|
|
295
300
|
port: parsedPort,
|
|
296
301
|
serverType: "java",
|
|
297
|
-
timeout: 5
|
|
302
|
+
timeout: 5,
|
|
303
|
+
active: true
|
|
298
304
|
};
|
|
299
305
|
const result = await queryServerStatus(tempServer);
|
|
300
306
|
if (!result.success) {
|
|
@@ -329,7 +335,8 @@ function apply(ctx, config) {
|
|
|
329
335
|
port: parsedPort,
|
|
330
336
|
serverType: "java",
|
|
331
337
|
timeout: options.timeout,
|
|
332
|
-
minekuaiInstanceId: options.instance
|
|
338
|
+
minekuaiInstanceId: options.instance,
|
|
339
|
+
active: true
|
|
333
340
|
};
|
|
334
341
|
if (options.name) {
|
|
335
342
|
createData.name = options.name;
|
|
@@ -542,7 +549,8 @@ ${parts.join("\n")}`;
|
|
|
542
549
|
|
|
543
550
|
`;
|
|
544
551
|
servers.forEach((server) => {
|
|
545
|
-
|
|
552
|
+
const activeStatus = server.active === false ? "� 不活跃" : "� 活跃";
|
|
553
|
+
message += `[ID:${server.id}] ${server.name} | ${activeStatus}
|
|
546
554
|
`;
|
|
547
555
|
if (config.showIpInDetail) {
|
|
548
556
|
message += ` 地址: ${server.host}:${server.port}
|
|
@@ -575,6 +583,33 @@ ${parts.join("\n")}`;
|
|
|
575
583
|
await ctx.database.set("minecraft_server", { id }, { minekuaiInstanceId: instanceId });
|
|
576
584
|
return `✅ ${server.name} 的麦块实例ID已设置为: ${instanceId}`;
|
|
577
585
|
});
|
|
586
|
+
ctx.guild().command("mc/服务器状态 <id:number> [status:text]", "查询或设置服务器活跃状态").action(async ({ session }, id, status) => {
|
|
587
|
+
const permissionError = await checkPermission(session, config);
|
|
588
|
+
if (permissionError) {
|
|
589
|
+
return permissionError;
|
|
590
|
+
}
|
|
591
|
+
if (!id) {
|
|
592
|
+
return "请提供服务器ID,例如:服务器状态 1";
|
|
593
|
+
}
|
|
594
|
+
const groupId = session.guildId;
|
|
595
|
+
const servers = await ctx.database.get("minecraft_server", { groupId });
|
|
596
|
+
const server = servers.find((s) => s.id === id);
|
|
597
|
+
if (!server) {
|
|
598
|
+
return `❌ 未找到ID为 ${id} 的服务器`;
|
|
599
|
+
}
|
|
600
|
+
if (!status) {
|
|
601
|
+
const activeStatus = server.active === false ? "� 不活跃" : "� 活跃";
|
|
602
|
+
return `📋 ${server.name} (ID: ${id}) 状态:${activeStatus}`;
|
|
603
|
+
} else if (status === "启用") {
|
|
604
|
+
await ctx.database.set("minecraft_server", { id }, { active: true });
|
|
605
|
+
return `✅ ${server.name} (ID: ${id}) 已设置为活跃状态`;
|
|
606
|
+
} else if (status === "停用") {
|
|
607
|
+
await ctx.database.set("minecraft_server", { id }, { active: false });
|
|
608
|
+
return `✅ ${server.name} (ID: ${id}) 已设置为不活跃状态`;
|
|
609
|
+
} else {
|
|
610
|
+
return "请使用正确的状态值:启用 或 停用";
|
|
611
|
+
}
|
|
612
|
+
});
|
|
578
613
|
}
|
|
579
614
|
__name(apply, "apply");
|
|
580
615
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -68,7 +68,8 @@ mc/解绑服务器 <id> # 解绑服务器
|
|
|
68
68
|
mc/修改服务器 <id> [-n <name>] [-t <timeout>] [-i <instance>] # 修改服务器信息,支持修改名称、超时时间和麦块实例ID
|
|
69
69
|
mc/服务器列表 # 查看已绑定的服务器列表
|
|
70
70
|
mc/设置实例 <id> <instanceId> # 设置服务器的麦块实例ID
|
|
71
|
-
mc
|
|
71
|
+
mc/绑定API密钥 <apiKey> # 绑定麦块API密钥
|
|
72
|
+
mc/服务器状态 <id> [状态] # 查询或设置服务器活跃状态(状态:启用/停用)
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
### 查询服务器状态
|
|
@@ -130,16 +131,17 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
|
|
|
130
131
|
- `mc/绑定服务器 s3.ungc.com.cn -i abc123` - 绑定服务器并设置麦块实例ID
|
|
131
132
|
|
|
132
133
|
### 绑定API密钥
|
|
133
|
-
- **命令**:`mc
|
|
134
|
+
- **命令**:`mc/绑定API密钥 <apiKey>`
|
|
134
135
|
- **参数**:
|
|
135
136
|
- `<apiKey>`:麦块联机平台的API密钥
|
|
136
137
|
- **说明**:每个群组只需绑定一次,后续会自动使用该密钥
|
|
137
138
|
|
|
138
139
|
### 服务器管理指令
|
|
139
140
|
- **`mc/解绑服务器 <id>`**:解绑指定ID的服务器
|
|
140
|
-
- **`mc/修改服务器 <id> [-n <name>] [-t <timeout>] [-i <instance
|
|
141
|
+
- **`mc/修改服务器 <id> [-n <name>] [-t <timeout>] [-i <instance>]`**:修改服务器名称、超时时间或麦块实例ID
|
|
141
142
|
- **`mc/设置实例 <id> <instanceId>`**:为服务器设置麦块实例ID,用于电源控制
|
|
142
143
|
- **`mc/服务器列表`**:查看当前群组已绑定的所有服务器
|
|
144
|
+
- **`mc/服务器状态 <id> [状态]`**:查询或设置服务器活跃状态(状态:启用/停用)
|
|
143
145
|
|
|
144
146
|
### 服务器控制指令
|
|
145
147
|
- **`mc/开服 <id>`**:启动指定服务器
|
|
@@ -186,6 +188,19 @@ mc/资源 1 # 查看ID为1的麦块服务器资源使用情况
|
|
|
186
188
|
<details>
|
|
187
189
|
<summary>点我查看更新日志详情</summary>
|
|
188
190
|
|
|
191
|
+
### v2.0.9
|
|
192
|
+
- 修复指令名称不一致问题,统一使用"绑定API密钥"指令名称
|
|
193
|
+
|
|
194
|
+
### v2.0.8
|
|
195
|
+
- 新增服务器活跃状态管理功能
|
|
196
|
+
- 在 minecraft_server 数据库中添加 active 字段(boolean 类型)
|
|
197
|
+
- 绑定服务器后默认设置为活跃状态
|
|
198
|
+
- 新增 `mc/服务器状态` 指令,支持查询和设置服务器活跃状态
|
|
199
|
+
- 修改 `mc/查服` 指令,过滤掉不活跃的服务器
|
|
200
|
+
- 修改 `mc/服务器列表` 指令,显示服务器活跃状态
|
|
201
|
+
- 当查询不活跃的服务器时,显示提示信息
|
|
202
|
+
- 兼容旧数据:已存在的服务器 active 字段为 null 时,视为活跃状态
|
|
203
|
+
|
|
189
204
|
### v2.0.7
|
|
190
205
|
- 优化指令命名,将"绑定"改为"绑定服务器","解绑"改为"解绑服务器","修改"改为"修改服务器"
|
|
191
206
|
|