mioku-plugin-help 2.1.1 → 2.2.0
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/package.json +13 -1
- package/status/data-collector.ts +1 -16
- package/status/html-generator.ts +0 -18
- package/status/types.ts +5 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mioku-plugin-help",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "帮助插件,使用截图服务生成美观的帮助图片,并提供 #状态 指令",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,18 @@
|
|
|
17
17
|
"screenshot",
|
|
18
18
|
"config",
|
|
19
19
|
"ai"
|
|
20
|
+
],
|
|
21
|
+
"accessHooks": [
|
|
22
|
+
{
|
|
23
|
+
"id": "帮助菜单",
|
|
24
|
+
"match": "/(?:[#/]\\s*(?:帮助|菜单|help)|^(?:帮助|菜单|help)(?:\\s|$))/",
|
|
25
|
+
"description": "匹配 #help / 帮助 / 菜单 等帮助指令"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "状态",
|
|
29
|
+
"match": "/(?:[#/]\\s*(?:状态|zt|status)|^(?:状态|zt|status)(?:\\s|$))/",
|
|
30
|
+
"description": "匹配 #状态 / 状态 / zt / status 等系统状态指令"
|
|
31
|
+
}
|
|
20
32
|
]
|
|
21
33
|
},
|
|
22
34
|
"peerDependencies": {
|
package/status/data-collector.ts
CHANGED
|
@@ -225,7 +225,6 @@ async function collectBotStatuses(
|
|
|
225
225
|
|
|
226
226
|
// 并行拿 OneBot API 的 status / group / friend / version
|
|
227
227
|
let online = true;
|
|
228
|
-
let onlineDurationMs = 0;
|
|
229
228
|
let groupCount = 0;
|
|
230
229
|
let friendCount = 0;
|
|
231
230
|
let appVersion = "unknown";
|
|
@@ -248,20 +247,7 @@ async function collectBotStatuses(
|
|
|
248
247
|
).catch(() => null),
|
|
249
248
|
]);
|
|
250
249
|
if (statusResult.status === "fulfilled" && statusResult.value) {
|
|
251
|
-
|
|
252
|
-
// napcat-sdk 的 api() 已经把 OneBot v11 响应的 data 字段解包出来,
|
|
253
|
-
const startTs = safeNumber(status?.stat?.start_time);
|
|
254
|
-
if (startTs > 0) {
|
|
255
|
-
// OneBot 约定:start_time 是 unix 秒;> 1e12 视为毫秒
|
|
256
|
-
const startMs = startTs > 1e12 ? startTs : startTs * 1000;
|
|
257
|
-
onlineDurationMs = Math.max(0, Date.now() - startMs);
|
|
258
|
-
}
|
|
259
|
-
if (typeof status?.online === "boolean") {
|
|
260
|
-
online = status.online;
|
|
261
|
-
} else if (typeof status?.good === "boolean") {
|
|
262
|
-
// go-cqhttp / LLOneBot 用 good 表示总体健康
|
|
263
|
-
online = status.good;
|
|
264
|
-
}
|
|
250
|
+
online = statusResult.value.online;
|
|
265
251
|
}
|
|
266
252
|
if (versionResult.status === "fulfilled" && versionResult.value) {
|
|
267
253
|
const v = versionResult.value;
|
|
@@ -297,7 +283,6 @@ async function collectBotStatuses(
|
|
|
297
283
|
online,
|
|
298
284
|
groupCount,
|
|
299
285
|
friendCount,
|
|
300
|
-
onlineDurationMs,
|
|
301
286
|
send: counts.send,
|
|
302
287
|
receive: counts.receive,
|
|
303
288
|
});
|
package/status/html-generator.ts
CHANGED
|
@@ -71,23 +71,6 @@ function fmtBps(bps: number): string {
|
|
|
71
71
|
return `${fmtBytes(bps)}/s`;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function fmtUptime(ms: number): string {
|
|
75
|
-
if (!Number.isFinite(ms) || ms <= 0) {
|
|
76
|
-
return "—";
|
|
77
|
-
}
|
|
78
|
-
const sec = Math.floor(ms / 1000);
|
|
79
|
-
const days = Math.floor(sec / 86400);
|
|
80
|
-
const hours = Math.floor((sec % 86400) / 3600);
|
|
81
|
-
const minutes = Math.floor((sec % 3600) / 60);
|
|
82
|
-
if (days > 0) {
|
|
83
|
-
return `${days}天${String(hours).padStart(2, "0")}时${String(minutes).padStart(2, "0")}分`;
|
|
84
|
-
}
|
|
85
|
-
if (hours > 0) {
|
|
86
|
-
return `${hours}时${String(minutes).padStart(2, "0")}分`;
|
|
87
|
-
}
|
|
88
|
-
return `${minutes}分`;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
74
|
function progressBar(percent: number, color: string): string {
|
|
92
75
|
const clamped = Math.max(0, Math.min(100, percent));
|
|
93
76
|
return `<div class="status-bar"><div class="status-bar__fill" style="width:${clamped}%;background:${color};"></div></div>`;
|
|
@@ -162,7 +145,6 @@ function renderHero(
|
|
|
162
145
|
{ text: statusText, kind: bot.online ? "ok" : "danger" },
|
|
163
146
|
{ text: `好友 ${fmtNumber(bot.friendCount)}`, kind: "data" },
|
|
164
147
|
{ text: `群聊 ${fmtNumber(bot.groupCount)}`, kind: "data" },
|
|
165
|
-
{ text: `运行时长 ${fmtUptime(bot.onlineDurationMs)}`, kind: "data" },
|
|
166
148
|
{ text: `收 ${fmtNumber(bot.receive)}`, kind: "data" },
|
|
167
149
|
{ text: `发 ${fmtNumber(bot.send)}`, kind: "data" },
|
|
168
150
|
{ text: frameworkText, kind: "data" },
|
package/status/types.ts
CHANGED
|
@@ -19,8 +19,6 @@ export interface BotAccountStatus {
|
|
|
19
19
|
online: boolean;
|
|
20
20
|
groupCount: number;
|
|
21
21
|
friendCount: number;
|
|
22
|
-
/** Computed from `bot.api("get_status").stat.start_time`. 0 if unavailable. */
|
|
23
|
-
onlineDurationMs: number;
|
|
24
22
|
send: number;
|
|
25
23
|
receive: number;
|
|
26
24
|
}
|
|
@@ -37,18 +35,13 @@ export interface OneBotVersionInfoData {
|
|
|
37
35
|
|
|
38
36
|
/**
|
|
39
37
|
* OneBot v11 `get_status` payload (already unwrapped by napcat-sdk).
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - LLOneBot: same shape
|
|
38
|
+
* Per napcat 官方文档: `{ online, good, stat }` —— `stat` 是空对象,
|
|
39
|
+
* 不包含 `start_time` 或任何统计字段。本接口只声明文档承诺的字段。
|
|
43
40
|
*/
|
|
44
41
|
export interface OneBotStatusData {
|
|
45
|
-
online
|
|
46
|
-
good
|
|
47
|
-
stat
|
|
48
|
-
start_time?: number;
|
|
49
|
-
[key: string]: unknown;
|
|
50
|
-
};
|
|
51
|
-
[key: string]: unknown;
|
|
42
|
+
online: boolean;
|
|
43
|
+
good: boolean;
|
|
44
|
+
stat: Record<string, never>;
|
|
52
45
|
}
|
|
53
46
|
|
|
54
47
|
/** Subset of mioku's `AIService.getUsageSummary` payload that we actually render. */
|