koishi-plugin-test-sm-nextmap 0.0.1
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 +9 -0
- package/lib/index.js +78 -0
- package/package.json +20 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "test-sm-nextmap";
|
|
3
|
+
export interface Config {
|
|
4
|
+
port: number;
|
|
5
|
+
platform: string;
|
|
6
|
+
targetPlatform: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const Config: Schema<Config>;
|
|
9
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Config: () => Config,
|
|
34
|
+
apply: () => apply,
|
|
35
|
+
name: () => name
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_koishi = require("koishi");
|
|
39
|
+
var import_dgram = __toESM(require("dgram"));
|
|
40
|
+
var name = "test-sm-nextmap";
|
|
41
|
+
var Config = import_koishi.Schema.object({
|
|
42
|
+
port: import_koishi.Schema.number().default(8888).description("UDP 监听端口"),
|
|
43
|
+
targetPlatform: import_koishi.Schema.string().required().description("通知发送的目标群/频道号"),
|
|
44
|
+
platform: import_koishi.Schema.string().default("onebot").description("机器人平台")
|
|
45
|
+
});
|
|
46
|
+
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 data = msg.toString().trim();
|
|
52
|
+
if (data.startsWith("NextMap:")) {
|
|
53
|
+
const nextMapName = data.split(":")[1];
|
|
54
|
+
const announcement = `🔄 当前地图结束,即将切换至:${nextMapName}`;
|
|
55
|
+
const bot = ctx.bots.find((b) => b.platform === config.targetPlatform);
|
|
56
|
+
if (bot) {
|
|
57
|
+
bot.sendMessage(config.targetPlatform, announcement);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
udpServer.on("error", (err) => {
|
|
62
|
+
ctx.logger.error(`UDP 服务运行出错: ${err.message}`);
|
|
63
|
+
});
|
|
64
|
+
udpServer.bind(config.port, () => {
|
|
65
|
+
ctx.logger.info(`地图监控已就绪,端口: ${config.port}`);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
ctx.on("dispose", () => {
|
|
69
|
+
if (udpServer) udpServer.close();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
__name(apply, "apply");
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
Config,
|
|
76
|
+
apply,
|
|
77
|
+
name
|
|
78
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-test-sm-nextmap",
|
|
3
|
+
"description": "",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"chatbot",
|
|
14
|
+
"koishi",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"koishi": "^4.18.9"
|
|
19
|
+
}
|
|
20
|
+
}
|