koishi-plugin-test-sm-nextmap 0.0.1 → 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 +2 -2
- package/lib/index.js +17 -18
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
|
-
export declare const name = "
|
|
2
|
+
export declare const name = "map-notify-docker-debug";
|
|
3
3
|
export interface Config {
|
|
4
4
|
port: number;
|
|
5
|
+
channelId: string;
|
|
5
6
|
platform: string;
|
|
6
|
-
targetPlatform: string;
|
|
7
7
|
}
|
|
8
8
|
export declare const Config: Schema<Config>;
|
|
9
9
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -37,36 +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 = "
|
|
40
|
+
var name = "map-notify-docker-debug";
|
|
41
41
|
var Config = import_koishi.Schema.object({
|
|
42
|
-
port: import_koishi.Schema.number().default(
|
|
43
|
-
|
|
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
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const bot = ctx.bots.find((b) => b.platform === config.targetPlatform);
|
|
49
|
+
server = import_dgram.default.createSocket("udp4");
|
|
50
|
+
server.on("message", (msg, rinfo) => {
|
|
51
|
+
const rawData = msg.toString().trim();
|
|
52
|
+
ctx.logger.info(`[UDP接收成功] 来自 ${rinfo.address}:${rinfo.port} 内容: "${rawData}"`);
|
|
53
|
+
if (rawData.includes("NextMap:") || rawData.includes("Test:")) {
|
|
54
|
+
const bot = ctx.bots.find((b) => b.platform === config.platform);
|
|
56
55
|
if (bot) {
|
|
57
|
-
bot.sendMessage(config.
|
|
56
|
+
bot.sendMessage(config.channelId, `🎮 信号捕获: ${rawData}`);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
});
|
|
61
|
-
|
|
62
|
-
ctx.logger.error(`UDP
|
|
60
|
+
server.on("error", (err) => {
|
|
61
|
+
ctx.logger.error(`UDP Server 错误: ${err.stack}`);
|
|
63
62
|
});
|
|
64
|
-
|
|
65
|
-
ctx.logger.info(
|
|
63
|
+
server.bind(config.port, "0.0.0.0", () => {
|
|
64
|
+
ctx.logger.info(`Koishi UDP 监听已就绪,端口: ${config.port}`);
|
|
66
65
|
});
|
|
67
66
|
});
|
|
68
67
|
ctx.on("dispose", () => {
|
|
69
|
-
if (
|
|
68
|
+
if (server) server.close();
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
__name(apply, "apply");
|