koishi-plugin-minecraft-search 1.3.4 → 1.3.6
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 +58 -1
- package/package.json +1 -1
- package/readme.md +33 -0
package/lib/index.js
CHANGED
|
@@ -131,7 +131,9 @@ function apply(ctx, config) {
|
|
|
131
131
|
errorMessage = errorMessage.replace(/connect ECONNREFUSED/i, "服务器已关闭");
|
|
132
132
|
errorMessage = errorMessage.replace(/connect ETIMEDOUT/i, "服务器连接超时");
|
|
133
133
|
errorMessage = errorMessage.replace(/connect ENOTFOUND/i, "DNS服务器配置错误");
|
|
134
|
-
errorMessage = errorMessage.replace(
|
|
134
|
+
errorMessage = errorMessage.replace(/getaddrinfo EAI_AGAIN/i, "DNS服务器配置错误");
|
|
135
|
+
errorMessage = errorMessage.replace(/\s+(\d+\.\d+\.\d+\.\d+):\d+/, "");
|
|
136
|
+
errorMessage = errorMessage.replace(/\s+[\w.-]+$/, "");
|
|
135
137
|
return {
|
|
136
138
|
success: false,
|
|
137
139
|
error: errorMessage,
|
|
@@ -273,6 +275,61 @@ function apply(ctx, config) {
|
|
|
273
275
|
return `❌ 强制重启服务器 ${server.name} 失败: ${error.message}`;
|
|
274
276
|
}
|
|
275
277
|
});
|
|
278
|
+
ctx.command("mc/资源 <id:number>", "查看麦块服务器资源使用情况").action(async ({ session }, id) => {
|
|
279
|
+
if (!id) return "请提供服务器ID,例如:资源 1";
|
|
280
|
+
const server = config.servers.find((s) => s.id === id);
|
|
281
|
+
if (!server) return `未找到ID为 ${id} 的服务器`;
|
|
282
|
+
if (!server.minekuaiInstanceId) return `服务器 ${server.name} 未配置麦块实例ID`;
|
|
283
|
+
try {
|
|
284
|
+
const { apiUrl, apiKey } = config.minekuaiSettings;
|
|
285
|
+
if (!apiKey) throw new Error("麦块API密钥未配置");
|
|
286
|
+
if (!apiUrl) throw new Error("麦块API地址未配置");
|
|
287
|
+
const baseUrl = apiUrl.replace(/\/+$/, "");
|
|
288
|
+
const url = `${baseUrl}/servers/${server.minekuaiInstanceId}/resources`;
|
|
289
|
+
const headers = {
|
|
290
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
291
|
+
"Content-Type": "application/json",
|
|
292
|
+
"Accept": "application/json"
|
|
293
|
+
};
|
|
294
|
+
const response = await ctx.http.get(url, { headers });
|
|
295
|
+
ctx.logger.info(`麦块API资源查询成功: 实例 ${server.minekuaiInstanceId}`);
|
|
296
|
+
const attributes = response.attributes;
|
|
297
|
+
const resources = attributes.resources;
|
|
298
|
+
const currentState = attributes.current_state;
|
|
299
|
+
const isSuspended = attributes.is_suspended;
|
|
300
|
+
const memoryUsed = resources.memory_bytes / 1024 / 1024 / 1024;
|
|
301
|
+
const cpuUsage = resources.cpu_absolute;
|
|
302
|
+
const diskUsed = resources.disk_bytes / 1024 / 1024 / 1024;
|
|
303
|
+
const uptime = resources.uptime;
|
|
304
|
+
const uptimeDays = Math.floor(uptime / 86400);
|
|
305
|
+
const uptimeHours = Math.floor(uptime % 86400 / 3600);
|
|
306
|
+
const uptimeMinutes = Math.floor(uptime % 3600 / 60);
|
|
307
|
+
const uptimeSeconds = uptime % 60;
|
|
308
|
+
const formattedUptime = `${uptimeDays}天 ${uptimeHours}小时 ${uptimeMinutes}分钟 ${uptimeSeconds}秒`;
|
|
309
|
+
let message = `📊 ${server.name} 资源使用情况
|
|
310
|
+
`;
|
|
311
|
+
message += `� 状态: ${currentState === "running" ? "运行中" : currentState}
|
|
312
|
+
`;
|
|
313
|
+
message += `🔄 暂停: ${isSuspended ? "是" : "否"}
|
|
314
|
+
`;
|
|
315
|
+
message += `🖥️ CPU: ${cpuUsage.toFixed(2)}%
|
|
316
|
+
`;
|
|
317
|
+
message += `💾 内存: ${memoryUsed.toFixed(2)}GB
|
|
318
|
+
`;
|
|
319
|
+
message += `💿 磁盘: ${diskUsed.toFixed(2)}GB
|
|
320
|
+
`;
|
|
321
|
+
message += `📡 网络接收: ${(resources.network_rx_bytes / 1024 / 1024).toFixed(2)}MB
|
|
322
|
+
`;
|
|
323
|
+
message += `📡 网络发送: ${(resources.network_tx_bytes / 1024 / 1024).toFixed(2)}MB
|
|
324
|
+
`;
|
|
325
|
+
message += `⏱️ 运行时间: ${formattedUptime}
|
|
326
|
+
`;
|
|
327
|
+
message += `⏰ 查询时间: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`;
|
|
328
|
+
return message;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
return `❌ 查询服务器 ${server.name} 资源使用情况失败: ${error.message}`;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
276
333
|
}
|
|
277
334
|
__name(apply, "apply");
|
|
278
335
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
- 支持通过麦块联机 API 重启服务器
|
|
19
19
|
- 自动重试机制,提高操作成功率
|
|
20
20
|
|
|
21
|
+
### 📊 服务器资源查询
|
|
22
|
+
- 支持通过麦块联机 API 查询服务器资源使用情况
|
|
23
|
+
- 显示 CPU、内存、磁盘使用情况
|
|
24
|
+
- 显示网络接收和发送数据量
|
|
25
|
+
- 显示服务器运行时间
|
|
26
|
+
- 显示服务器状态和暂停状态
|
|
27
|
+
|
|
21
28
|
## 安装
|
|
22
29
|
|
|
23
30
|
1. 安装插件:
|
|
@@ -77,6 +84,25 @@ minekuaiSettings: {
|
|
|
77
84
|
强制重启 1 # 强制重启ID为1的麦块服务器
|
|
78
85
|
```
|
|
79
86
|
|
|
87
|
+
### 服务器资源查询
|
|
88
|
+
```
|
|
89
|
+
资源 1 # 查看ID为1的麦块服务器资源使用情况
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**输出示例:**
|
|
93
|
+
```
|
|
94
|
+
📊 服务器名称 资源使用情况
|
|
95
|
+
📋 状态: 运行中
|
|
96
|
+
🔄 暂停: 否
|
|
97
|
+
🖥️ CPU: 33.08%
|
|
98
|
+
💾 内存: 10.71GB
|
|
99
|
+
💿 磁盘: 18.50GB
|
|
100
|
+
📡 网络接收: 384.50MB
|
|
101
|
+
📡 网络发送: 2679.00MB
|
|
102
|
+
⏱️ 运行时间: 425天 12小时 39分钟 5秒
|
|
103
|
+
⏰ 查询时间: 2026-03-13 12:00:00
|
|
104
|
+
```
|
|
105
|
+
|
|
80
106
|
## 配置选项说明
|
|
81
107
|
|
|
82
108
|
### 服务器类型 (serverType)
|
|
@@ -120,6 +146,13 @@ minekuaiSettings: {
|
|
|
120
146
|
<details>
|
|
121
147
|
<summary>点我查看更新日志详情</summary>
|
|
122
148
|
|
|
149
|
+
### v1.3.6
|
|
150
|
+
- 新增服务器资源使用情况查询功能
|
|
151
|
+
- 支持查看 CPU、内存、磁盘使用情况
|
|
152
|
+
- 支持查看网络接收和发送数据量
|
|
153
|
+
- 支持查看服务器运行时间
|
|
154
|
+
- 支持查看服务器状态和暂停状态
|
|
155
|
+
|
|
123
156
|
### v1.3.4
|
|
124
157
|
- 优化错误信息显示,将英文错误信息翻译成中文
|
|
125
158
|
- 统一服务器状态显示格式,离线服务器显示具体错误原因
|