koishi-plugin-cocoyyy-console 1.2.2 → 1.2.3-alpha.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/lib/index.js CHANGED
@@ -3973,6 +3973,39 @@ function registerJmCommands(ctx, jm_config) {
3973
3973
  }
3974
3974
  __name(registerJmCommands, "registerJmCommands");
3975
3975
 
3976
+ // src/services/health_service.ts
3977
+ var import_axios5 = __toESM(require("axios"));
3978
+ var HEALTH_TARGETS = [
3979
+ { name: "baidu", url: "https://www.baidu.com" },
3980
+ { name: "qq", url: "https://www.qq.com" },
3981
+ { name: "bing", url: "https://www.bing.com" }
3982
+ ];
3983
+ var TIMEOUT_MS = 5e3;
3984
+ async function checkUrl(target) {
3985
+ const start = Date.now();
3986
+ try {
3987
+ await import_axios5.default.head(target.url, {
3988
+ timeout: TIMEOUT_MS,
3989
+ validateStatus: /* @__PURE__ */ __name(() => true, "validateStatus")
3990
+ });
3991
+ return { name: target.name, url: target.url, ok: true, ms: Date.now() - start };
3992
+ } catch (e) {
3993
+ return { name: target.name, url: target.url, ok: false, ms: Date.now() - start, err: e?.code ?? e?.message ?? "未知错误" };
3994
+ }
3995
+ }
3996
+ __name(checkUrl, "checkUrl");
3997
+ function registerHealthCommands(ctx) {
3998
+ ctx.command("health", "检测当前网络连通性").action(async () => {
3999
+ const results = await Promise.all(HEALTH_TARGETS.map(checkUrl));
4000
+ const okCount = results.filter((r) => r.ok).length;
4001
+ return `网络检测结果 (${okCount}/${results.length} 可达):
4002
+ ` + results.map(
4003
+ (r) => r.ok ? `${r.name} (${r.url}) - ${r.ms}ms` : `${r.name} (${r.url}) - ${r.err}`
4004
+ ).join("\n");
4005
+ });
4006
+ }
4007
+ __name(registerHealthCommands, "registerHealthCommands");
4008
+
3976
4009
  // src/index.ts
3977
4010
  var name = "cocoyyy-console";
3978
4011
  var inject = { optional: ["puppeteer"] };
@@ -4040,6 +4073,7 @@ async function apply(ctx, config) {
4040
4073
  const jmCtx = getCtxForFunction(ctx, 10);
4041
4074
  if (config.function_config.jm_flag && jmCtx)
4042
4075
  registerJmCommands(jmCtx, config?.jm_config ?? {});
4076
+ registerHealthCommands(ctx);
4043
4077
  if (dev_mode)
4044
4078
  registerTestCommands(ctx, config);
4045
4079
  }
@@ -0,0 +1,2 @@
1
+ import { Context } from 'koishi';
2
+ export declare function registerHealthCommands(ctx: Context): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cocoyyy-console",
3
3
  "description": "自用koishi插件,功能包含复读,记录黑历史,*人等",
4
- "version": "1.2.2",
4
+ "version": "1.2.3-alpha.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "contributors": [