koishi-plugin-cat-raising 1.3.9 → 1.3.10
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 +33 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_koishi = require("koishi");
|
|
39
39
|
var crypto = __toESM(require("crypto"));
|
|
40
|
+
var net = __toESM(require("net"));
|
|
40
41
|
var import_url = require("url");
|
|
41
42
|
var name = "cat-raising";
|
|
42
43
|
var Config = import_koishi.Schema.intersect([
|
|
@@ -319,6 +320,18 @@ function apply(ctx, config) {
|
|
|
319
320
|
const pendingDanmakuTimersByMessage = /* @__PURE__ */ new Map();
|
|
320
321
|
const pendingDanmakuTimersByRoom = /* @__PURE__ */ new Map();
|
|
321
322
|
const pendingDanmakuRoomMap = /* @__PURE__ */ new Map();
|
|
323
|
+
ctx.command("cat", "🐱喵喵喵");
|
|
324
|
+
ctx.command("cat.status", "查看插件状态").action(async () => {
|
|
325
|
+
let latencyMsg = "";
|
|
326
|
+
try {
|
|
327
|
+
const ms = await tcpPing("api.live.bilibili.com", 80);
|
|
328
|
+
latencyMsg = `B站API延迟: ${ms}ms`;
|
|
329
|
+
} catch (e) {
|
|
330
|
+
latencyMsg = `B站API延迟: 失败 (${e.message || "Unknown"})`;
|
|
331
|
+
}
|
|
332
|
+
return `🐱喵喵喵
|
|
333
|
+
${latencyMsg}`;
|
|
334
|
+
});
|
|
322
335
|
ctx.on("message", async (session) => {
|
|
323
336
|
const groupConfig = config.monitorGroups.find((g) => g.groupId === session.channelId);
|
|
324
337
|
if (!groupConfig) return;
|
|
@@ -481,6 +494,26 @@ function sleep(ms) {
|
|
|
481
494
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
482
495
|
}
|
|
483
496
|
__name(sleep, "sleep");
|
|
497
|
+
function tcpPing(host, port = 80, timeout = 2e3) {
|
|
498
|
+
return new Promise((resolve, reject) => {
|
|
499
|
+
const start = Date.now();
|
|
500
|
+
const socket = new net.Socket();
|
|
501
|
+
socket.setTimeout(timeout, () => {
|
|
502
|
+
socket.destroy();
|
|
503
|
+
reject(new Error("Timeout"));
|
|
504
|
+
});
|
|
505
|
+
socket.connect(port, host, () => {
|
|
506
|
+
const ms = Date.now() - start;
|
|
507
|
+
socket.destroy();
|
|
508
|
+
resolve(ms);
|
|
509
|
+
});
|
|
510
|
+
socket.on("error", (err) => {
|
|
511
|
+
socket.destroy();
|
|
512
|
+
reject(err);
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
__name(tcpPing, "tcpPing");
|
|
484
517
|
// Annotate the CommonJS export names for ESM import in node:
|
|
485
518
|
0 && (module.exports = {
|
|
486
519
|
Config,
|