koishi-plugin-test-sm-nextmap 0.0.3 → 0.0.4

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,9 +1,9 @@
1
1
  import { Context, Schema } from 'koishi';
2
- export declare const name = "map-notify-docker-debug";
2
+ export declare const name = "source-http-notify";
3
+ export declare const inject: string[];
3
4
  export interface Config {
4
- port: number;
5
- channelId: string;
6
- platform: string;
5
+ targetChannelId: 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
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
6
  var __export = (target, all) => {
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -32,40 +22,36 @@ var src_exports = {};
32
22
  __export(src_exports, {
33
23
  Config: () => Config,
34
24
  apply: () => apply,
25
+ inject: () => inject,
35
26
  name: () => name
36
27
  });
37
28
  module.exports = __toCommonJS(src_exports);
38
29
  var import_koishi = require("koishi");
39
- var import_dgram = __toESM(require("dgram"));
40
- var name = "map-notify-docker-debug";
30
+ var name = "source-http-notify";
31
+ var inject = ["server"];
41
32
  var Config = import_koishi.Schema.object({
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("平台名称")
33
+ targetPlatform: import_koishi.Schema.string().default("onebot").description("发送消息的平台"),
34
+ targetChannelId: import_koishi.Schema.string().required().description("接收通知的群号或频道 ID")
45
35
  });
46
36
  function apply(ctx, config) {
47
- let server;
48
- ctx.on("ready", () => {
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);
55
- if (bot) {
56
- bot.sendMessage(config.channelId, `🎮 信号捕获: ${rawData}`);
57
- }
58
- }
59
- });
60
- server.on("error", (err) => {
61
- ctx.logger.error(`UDP Server 错误: ${err.stack}`);
62
- });
63
- server.bind(config.port, "0.0.0.0", () => {
64
- ctx.logger.info(`Koishi UDP 监听已就绪,端口: ${config.port}`);
65
- });
66
- });
67
- ctx.on("dispose", () => {
68
- if (server) server.close();
37
+ ctx.server.get("/mapchange", async (report) => {
38
+ const { map, type } = report.query;
39
+ if (!map) {
40
+ report.status = 400;
41
+ return "Missing map name";
42
+ }
43
+ ctx.logger.info(`收到服务器通知: [${type}] 地图: ${map}`);
44
+ const message = type === "Test" ? `🎮 [测试] 服务器连接成功!当前地图: ${map}` : `🎮 [换图] 服务器即将更换地图,下一张图是: ${map}`;
45
+ const bot = ctx.bots.find((b) => b.platform === config.targetPlatform);
46
+ if (bot) {
47
+ bot.sendMessage(config.targetChannelId, message).catch((err) => {
48
+ ctx.logger.error("消息推送失败:", err);
49
+ });
50
+ } else {
51
+ ctx.logger.warn(`未找到平台为 ${config.targetPlatform} 的可用 Bot`);
52
+ }
53
+ report.status = 200;
54
+ report.body = "OK";
69
55
  });
70
56
  }
71
57
  __name(apply, "apply");
@@ -73,5 +59,6 @@ __name(apply, "apply");
73
59
  0 && (module.exports = {
74
60
  Config,
75
61
  apply,
62
+ inject,
76
63
  name
77
64
  });
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.3",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [