koishi-plugin-test-sm-nextmap 0.0.2 → 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-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,50 +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-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(8888).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 udpServer;
48
- ctx.on("ready", () => {
49
- udpServer = import_dgram.default.createSocket("udp4");
50
- udpServer.on("message", (msg, rinfo) => {
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}`;
56
- const bot = ctx.bots.find((b) => b.platform === config.platform);
57
- 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} 的可用机器人`);
61
- }
62
- } else {
63
- ctx.logger.warn(`收到了无法识别的数据格式: ${rawData}`);
64
- }
65
- });
66
- udpServer.on("error", (err) => {
67
- ctx.logger.error(`UDP 服务运行出错: ${err.stack}`);
68
- });
69
- udpServer.bind(config.port, () => {
70
- const address = udpServer.address();
71
- ctx.logger.info(`[SUCCESS] 调试模式已开启,正在监听 UDP ${address.address}:${address.port}`);
72
- });
73
- });
74
- ctx.on("dispose", () => {
75
- if (udpServer) {
76
- udpServer.close();
77
- ctx.logger.info("UDP 服务已关闭");
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`);
78
52
  }
53
+ report.status = 200;
54
+ report.body = "OK";
79
55
  });
80
56
  }
81
57
  __name(apply, "apply");
@@ -83,5 +59,6 @@ __name(apply, "apply");
83
59
  0 && (module.exports = {
84
60
  Config,
85
61
  apply,
62
+ inject,
86
63
  name
87
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.2",
4
+ "version": "0.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [