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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Context, Schema } from 'koishi';
2
- export declare const name = "map-notify-debug";
2
+ export declare const name = "map-notify-docker-debug";
3
3
  export interface Config {
4
4
  port: number;
5
5
  channelId: string;
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(8888).description("UDP 监听端口"),
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 udpServer;
47
+ let server;
48
48
  ctx.on("ready", () => {
49
- udpServer = import_dgram.default.createSocket("udp4");
50
- udpServer.on("message", (msg, rinfo) => {
49
+ server = import_dgram.default.createSocket("udp4");
50
+ server.on("message", (msg, rinfo) => {
51
51
  const rawData = msg.toString().trim();
52
- ctx.logger.info(`[DEBUG] 收到来自 ${rinfo.address}:${rinfo.port} 的原始数据: "${rawData}"`);
53
- if (rawData.startsWith("NextMap:") || rawData.startsWith("Test:")) {
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, announcement).then(() => ctx.logger.info("消息已成功发送至机器人平台")).catch((e) => ctx.logger.error(`机器人发送失败: ${e.message}`));
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
- udpServer.on("error", (err) => {
67
- ctx.logger.error(`UDP 服务运行出错: ${err.stack}`);
60
+ server.on("error", (err) => {
61
+ ctx.logger.error(`UDP Server 错误: ${err.stack}`);
68
62
  });
69
- udpServer.bind(config.port, () => {
70
- const address = udpServer.address();
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 (udpServer) {
76
- udpServer.close();
77
- ctx.logger.info("UDP 服务已关闭");
78
- }
68
+ if (server) server.close();
79
69
  });
80
70
  }
81
71
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-test-sm-nextmap",
3
3
  "description": "",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [