koishi-plugin-test-sm-nextmap 0.0.2 → 0.0.3
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 -1
- package/lib/index.js +15 -25
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -37,45 +37,35 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_koishi = require("koishi");
|
|
39
39
|
var import_dgram = __toESM(require("dgram"));
|
|
40
|
-
var name = "map-notify-debug";
|
|
40
|
+
var name = "map-notify-docker-debug";
|
|
41
41
|
var Config = import_koishi.Schema.object({
|
|
42
|
-
port: import_koishi.Schema.number().default(
|
|
43
|
-
channelId: import_koishi.Schema.string().required().description("
|
|
44
|
-
platform: import_koishi.Schema.string().default("onebot").description("
|
|
42
|
+
port: import_koishi.Schema.number().default(29417).description("UDP 监听端口"),
|
|
43
|
+
channelId: import_koishi.Schema.string().required().description("通知群号"),
|
|
44
|
+
platform: import_koishi.Schema.string().default("onebot").description("平台名称")
|
|
45
45
|
});
|
|
46
46
|
function apply(ctx, config) {
|
|
47
|
-
let
|
|
47
|
+
let server;
|
|
48
48
|
ctx.on("ready", () => {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
server = import_dgram.default.createSocket("udp4");
|
|
50
|
+
server.on("message", (msg, rinfo) => {
|
|
51
51
|
const rawData = msg.toString().trim();
|
|
52
|
-
ctx.logger.info(`[
|
|
53
|
-
if (rawData.
|
|
54
|
-
const content = rawData.split(":")[1];
|
|
55
|
-
const announcement = `📢 收到服务器信号:${content}`;
|
|
52
|
+
ctx.logger.info(`[UDP接收成功] 来自 ${rinfo.address}:${rinfo.port} 内容: "${rawData}"`);
|
|
53
|
+
if (rawData.includes("NextMap:") || rawData.includes("Test:")) {
|
|
56
54
|
const bot = ctx.bots.find((b) => b.platform === config.platform);
|
|
57
55
|
if (bot) {
|
|
58
|
-
bot.sendMessage(config.channelId,
|
|
59
|
-
} else {
|
|
60
|
-
ctx.logger.warn(`未找到平台为 ${config.platform} 的可用机器人`);
|
|
56
|
+
bot.sendMessage(config.channelId, `🎮 信号捕获: ${rawData}`);
|
|
61
57
|
}
|
|
62
|
-
} else {
|
|
63
|
-
ctx.logger.warn(`收到了无法识别的数据格式: ${rawData}`);
|
|
64
58
|
}
|
|
65
59
|
});
|
|
66
|
-
|
|
67
|
-
ctx.logger.error(`UDP
|
|
60
|
+
server.on("error", (err) => {
|
|
61
|
+
ctx.logger.error(`UDP Server 错误: ${err.stack}`);
|
|
68
62
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
ctx.logger.info(`[SUCCESS] 调试模式已开启,正在监听 UDP ${address.address}:${address.port}`);
|
|
63
|
+
server.bind(config.port, "0.0.0.0", () => {
|
|
64
|
+
ctx.logger.info(`Koishi UDP 监听已就绪,端口: ${config.port}`);
|
|
72
65
|
});
|
|
73
66
|
});
|
|
74
67
|
ctx.on("dispose", () => {
|
|
75
|
-
if (
|
|
76
|
-
udpServer.close();
|
|
77
|
-
ctx.logger.info("UDP 服务已关闭");
|
|
78
|
-
}
|
|
68
|
+
if (server) server.close();
|
|
79
69
|
});
|
|
80
70
|
}
|
|
81
71
|
__name(apply, "apply");
|