@rithien/discord_bridge 0.3.0

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.
@@ -0,0 +1,120 @@
1
+ /*
2
+ * ATTENTION: An "eval-source-map" devtool has been used.
3
+ * This devtool is neither made for production nor for readable output files.
4
+ * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
5
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6
+ * or disable the default devtool with "devtool: false".
7
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8
+ */
9
+ /******/ (() => { // webpackBootstrap
10
+ /******/ var __webpack_modules__ = ({
11
+
12
+ /***/ 718
13
+ /*!***********************!*\
14
+ !*** ./web/index.jsx ***!
15
+ \***********************/
16
+ () {
17
+
18
+ eval("{//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZVJvb3QiOiIiLCJmaWxlIjoiNzE4LmpzIn0=\n//# sourceURL=webpack-internal:///718\n\n}");
19
+
20
+ /***/ }
21
+
22
+ /******/ });
23
+ /************************************************************************/
24
+ /******/ // The module cache
25
+ /******/ var __webpack_module_cache__ = {};
26
+ /******/
27
+ /******/ // The require function
28
+ /******/ function __webpack_require__(moduleId) {
29
+ /******/ // Check if module is in cache
30
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
31
+ /******/ if (cachedModule !== undefined) {
32
+ /******/ return cachedModule.exports;
33
+ /******/ }
34
+ /******/ // Create a new module (and put it into the cache)
35
+ /******/ var module = __webpack_module_cache__[moduleId] = {
36
+ /******/ // no module.id needed
37
+ /******/ // no module.loaded needed
38
+ /******/ exports: {}
39
+ /******/ };
40
+ /******/
41
+ /******/ // Execute the module function
42
+ /******/ if (!(moduleId in __webpack_modules__)) {
43
+ /******/ delete __webpack_module_cache__[moduleId];
44
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
45
+ /******/ e.code = 'MODULE_NOT_FOUND';
46
+ /******/ throw e;
47
+ /******/ }
48
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
49
+ /******/
50
+ /******/ // Return the exports of the module
51
+ /******/ return module.exports;
52
+ /******/ }
53
+ /******/
54
+ /******/ // expose the modules object (__webpack_modules__)
55
+ /******/ __webpack_require__.m = __webpack_modules__;
56
+ /******/
57
+ /******/ // expose the module cache
58
+ /******/ __webpack_require__.c = __webpack_module_cache__;
59
+ /******/
60
+ /************************************************************************/
61
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
62
+ /******/ (() => {
63
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
64
+ /******/ })();
65
+ /******/
66
+ /******/ /* webpack/runtime/sharing */
67
+ /******/ (() => {
68
+ /******/ __webpack_require__.S = {};
69
+ /******/ var initPromises = {};
70
+ /******/ var initTokens = {};
71
+ /******/ __webpack_require__.I = (name, initScope) => {
72
+ /******/ if(!initScope) initScope = [];
73
+ /******/ // handling circular init calls
74
+ /******/ var initToken = initTokens[name];
75
+ /******/ if(!initToken) initToken = initTokens[name] = {};
76
+ /******/ if(initScope.indexOf(initToken) >= 0) return;
77
+ /******/ initScope.push(initToken);
78
+ /******/ // only runs once
79
+ /******/ if(initPromises[name]) return initPromises[name];
80
+ /******/ // creates a new share scope if needed
81
+ /******/ if(!__webpack_require__.o(__webpack_require__.S, name)) __webpack_require__.S[name] = {};
82
+ /******/ // runs all init snippets from all modules reachable
83
+ /******/ var scope = __webpack_require__.S[name];
84
+ /******/ var warn = (msg) => {
85
+ /******/ if (typeof console !== "undefined" && console.warn) console.warn(msg);
86
+ /******/ };
87
+ /******/ var uniqueName = "@rithien/discord_bridge";
88
+ /******/ var register = (name, version, factory, eager) => {
89
+ /******/ var versions = scope[name] = scope[name] || {};
90
+ /******/ var activeVersion = versions[version];
91
+ /******/ if(!activeVersion || (!activeVersion.loaded && (!eager != !activeVersion.eager ? eager : uniqueName > activeVersion.from))) versions[version] = { get: factory, from: uniqueName, eager: !!eager };
92
+ /******/ };
93
+ /******/ var initExternal = (id) => {
94
+ /******/ var handleError = (err) => (warn("Initialization of sharing external failed: " + err));
95
+ /******/ try {
96
+ /******/ var module = __webpack_require__(id);
97
+ /******/ if(!module) return;
98
+ /******/ var initFn = (module) => (module && module.init && module.init(__webpack_require__.S[name], initScope))
99
+ /******/ if(module.then) return promises.push(module.then(initFn, handleError));
100
+ /******/ var initResult = initFn(module);
101
+ /******/ if(initResult && initResult.then) return promises.push(initResult['catch'](handleError));
102
+ /******/ } catch(err) { handleError(err); }
103
+ /******/ }
104
+ /******/ var promises = [];
105
+ /******/ switch(name) {
106
+ /******/ }
107
+ /******/ if(!promises.length) return initPromises[name] = 1;
108
+ /******/ return initPromises[name] = Promise.all(promises).then(() => (initPromises[name] = 1));
109
+ /******/ };
110
+ /******/ })();
111
+ /******/
112
+ /************************************************************************/
113
+ /******/
114
+ /******/ // module cache are used so entry inlining is disabled
115
+ /******/ // startup
116
+ /******/ // Load entry module and return exports
117
+ /******/ var __webpack_exports__ = __webpack_require__(718);
118
+ /******/
119
+ /******/ })()
120
+ ;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*
3
+ * ATTENTION: An "eval-source-map" devtool has been used.
4
+ * This devtool is neither made for production nor for readable output files.
5
+ * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
6
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
7
+ * or disable the default devtool with "devtool: false".
8
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
9
+ */
10
+ (self["webpackChunk_rithien_discord_bridge"] = self["webpackChunk_rithien_discord_bridge"] || []).push([["package_json"],{
11
+
12
+ /***/ 330
13
+ /*!**********************!*\
14
+ !*** ./package.json ***!
15
+ \**********************/
16
+ (module) {
17
+
18
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rithien/discord_bridge","version":"0.3.0","description":"Clusterio plugin bridging chat between instances and Discord, with per-instance channel routing","main":"info.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","prepare":"webpack-cli --env production"},"keywords":["clusterio","factorio","discord"],"author":"rithien <jacek@zaluzje.bialystok.pl>","license":"MIT","peerDependencies":{"@clusterio/lib":"^2.0.0-alpha.14"},"devDependencies":{"@clusterio/lib":"^2.0.0-alpha.14","@clusterio/web_ui":"^2.0.0-alpha.14","webpack":"^5.88.2","webpack-cli":"^5.1.4","webpack-merge":"^5.9.0"},"dependencies":{"discord.js":"^14.14.1"},"publishConfig":{"access":"public"}}');
19
+
20
+ /***/ }
21
+
22
+ }]);
package/info.js ADDED
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ const lib = require("@clusterio/lib");
3
+
4
+ class InstanceActionEvent {
5
+ static type = "event";
6
+ static src = "instance";
7
+ static dst = "controller";
8
+ static plugin = "discord_bridge";
9
+
10
+ constructor(instanceName, action, content) {
11
+ this.instanceName = instanceName;
12
+ this.action = action;
13
+ this.content = content;
14
+ }
15
+
16
+ static jsonSchema = {
17
+ type: "object",
18
+ required: ["instanceName", "action", "content"],
19
+ properties: {
20
+ "instanceName": { type: "string" },
21
+ "action": { type: "string" },
22
+ "content": { type: "string" },
23
+ },
24
+ };
25
+
26
+ static fromJSON(json) {
27
+ return new this(json.instanceName, json.action, json.content);
28
+ }
29
+ }
30
+
31
+ class DiscordChatEvent {
32
+ static type = "event";
33
+ static src = "controller";
34
+ static dst = "instance";
35
+ static plugin = "discord_bridge";
36
+
37
+ constructor(content) {
38
+ this.content = content;
39
+ }
40
+
41
+ static jsonSchema = {
42
+ type: "object",
43
+ required: ["content"],
44
+ properties: {
45
+ "content": { type: "string" },
46
+ },
47
+ };
48
+
49
+ static fromJSON(json) {
50
+ return new this(json.content);
51
+ }
52
+ }
53
+
54
+ const plugin = {
55
+ name: "discord_bridge",
56
+ title: "Discord Bridge",
57
+ description: "Bridges chat between instances and Discord.",
58
+ instanceEntrypoint: "instance",
59
+ instanceConfigFields: {
60
+ "discord_bridge.channel_id": {
61
+ title: "Channel ID",
62
+ description:
63
+ "Discord channel ID this instance bridges chat to. Overrides the controller-level " +
64
+ "discord_bridge.channel_id. Leave empty to fall back to the controller-level channel.",
65
+ type: "string",
66
+ optional: true,
67
+ },
68
+ },
69
+ controllerEntrypoint: "controller",
70
+ controllerConfigFields: {
71
+ "discord_bridge.bot_token": {
72
+ title: "Bot Token",
73
+ description: "Bot token to log into Discord with.",
74
+ type: "string",
75
+ optional: true,
76
+ },
77
+ "discord_bridge.channel_id": {
78
+ title: "Channel ID",
79
+ description:
80
+ "Default Discord channel ID. Used for instances that do not have their own " +
81
+ "discord_bridge.channel_id set, and as the destination for host connect/disconnect notifications.",
82
+ type: "string",
83
+ optional: true,
84
+ },
85
+ "discord_bridge.discord_template": {
86
+ title: "Discord template",
87
+ description:
88
+ "Template to use for sending chat messages from Discord in game. In the template the string " +
89
+ "__display_name__ is replaced with the display name of the user sending the message, " +
90
+ "__username__ is replaced with the username and __content__ with the message content.",
91
+ type: "string",
92
+ initialValue: "[Discord] __display_name__: __content__",
93
+ },
94
+ "discord_bridge.bridge_player_shouts": {
95
+ title: "Bridge Player Shouts",
96
+ description: "Bridge shouts made with /shout to the Discord channel.",
97
+ type: "boolean",
98
+ initialValue: true,
99
+ },
100
+ "discord_bridge.bridge_player_chat": {
101
+ title: "Bridge Player Chat",
102
+ description: "Bridge player chat to the Discord channel.",
103
+ type: "boolean",
104
+ initialValue: true,
105
+ },
106
+ "discord_bridge.bridge_player_commands": {
107
+ title: "Bridge Player Commands",
108
+ description: "Bridge /command lua commands players execute to the Discord channel.",
109
+ type: "boolean",
110
+ initialValue: false,
111
+ },
112
+ "discord_bridge.bridge_player_joins": {
113
+ title: "Bridge Player Joins",
114
+ description: "Bridge join and leave notifications to the Discord channel.",
115
+ type: "boolean",
116
+ initialValue: true,
117
+ },
118
+ "discord_bridge.bridge_player_kicks_and_bans": {
119
+ title: "Bridge Player Kicks and Bans",
120
+ description: "Bridge kick and ban messages to the Discord channel.",
121
+ type: "boolean",
122
+ initialValue: true,
123
+ },
124
+ "discord_bridge.bridge_player_promotions": {
125
+ title: "Bridge Player Promotions",
126
+ description: "Bridge admin promotion messages to the Discord channel.",
127
+ type: "boolean",
128
+ initialValue: false,
129
+ },
130
+ "discord_bridge.player_templates": {
131
+ title: "Player templates",
132
+ description:
133
+ "Template to use for sending bridged player action messages from Factorio. In the template the " +
134
+ "string __instance_name__ is replaced with the name of the instance the message originated from " +
135
+ "and __content__ is replaced with the content of the message. The available actions that can be " +
136
+ "bridged are COMMAND SHOUT CHAT JOIN LEAVE KICK BAN UNBANNED PROMOTE DEMOTE.",
137
+ type: "object",
138
+ initialValue: {
139
+ "COMMAND": "[__instance_name__] __content__",
140
+ "SHOUT": "[__instance_name__] __content__",
141
+ "CHAT": "[__instance_name__] __content__",
142
+ "JOIN": "[__instance_name__] __content__",
143
+ "LEAVE": "[__instance_name__] __content__",
144
+ "KICK": "[__instance_name__] __content__",
145
+ "BAN": "[__instance_name__] __content__",
146
+ "UNBANNED": "[__instance_name__] __content__",
147
+ "PROMOTE": "[__instance_name__] __content__",
148
+ "DEMOTE": "[__instance_name__] __content__",
149
+ },
150
+ },
151
+ "discord_bridge.notify_instance_status": {
152
+ title: "Notify Instance Status",
153
+ description: "Notify of instance status changes to the Discord channel.",
154
+ type: "boolean",
155
+ initialValue: true,
156
+ },
157
+ "discord_bridge.instance_status_templates": {
158
+ title: "Instance Status Templates",
159
+ description:
160
+ "Template to use for sending notifications about instance status changes. In the template the " +
161
+ "string __instance_name__ and __host_name__ are replaced with the instance and host the change " +
162
+ "occured on. Templates specify previous:current status and the possible instance statuses are " +
163
+ "undefined unknown stopped starting running stopping creating_save exporting_data deleted",
164
+ type: "object",
165
+ initialValue: {
166
+ "starting:running": "[__instance_name__] started",
167
+ "starting:stopped": "[__instance_name__] failed to start",
168
+ "running:stopped": "[__instance_name__] abruptly stopped",
169
+ "stopping:stopped": "[__instance_name__] stopped",
170
+ "undefined:unassigned": "[__instance_name__] was created",
171
+ "deleted": "[__instance_name__] was deleted",
172
+ },
173
+ },
174
+ "discord_bridge.notify_host_connections": {
175
+ title: "Notify Host Connections",
176
+ description: "Notify of host connecting and disconnecting to the Discord channel.",
177
+ type: "boolean",
178
+ initialValue: true,
179
+ },
180
+ "discord_bridge.host_templates": {
181
+ title: "Host templates",
182
+ description:
183
+ "Template to use for sending notifications about host connection events. In the template the " +
184
+ "string __host_name__ is replaced with the name of the host the connection event occured from. " +
185
+ "The possible events that can happen are connect drop resume close.",
186
+ type: "object",
187
+ initialValue: {
188
+ "connect": "[__host_name__] connected",
189
+ "drop": "",
190
+ "resume": "",
191
+ "close": "[__host_name__] disconnected",
192
+ },
193
+ },
194
+ },
195
+
196
+ messages: [
197
+ InstanceActionEvent,
198
+ DiscordChatEvent,
199
+ ],
200
+ };
201
+
202
+ module.exports = {
203
+ plugin,
204
+ InstanceActionEvent,
205
+ DiscordChatEvent,
206
+ };
package/instance.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ const lib = require("@clusterio/lib");
3
+ const { BaseInstancePlugin } = require("@clusterio/host");
4
+
5
+ const { InstanceActionEvent, DiscordChatEvent } = require("./info.js");
6
+
7
+
8
+ /**
9
+ * Removes gps and train tags from messags
10
+ */
11
+ function removeTags(content) {
12
+ return content.replace(/(\[gps=-?\d+,-?\d+\]|\[train=\d+\])/g, "");
13
+ }
14
+
15
+ class InstancePlugin extends BaseInstancePlugin {
16
+ async init() {
17
+ this.messageQueue = [];
18
+ this.instance.handle(DiscordChatEvent, this.handleDiscordChatEvent.bind(this));
19
+ }
20
+
21
+ onControllerConnectionEvent(event) {
22
+ if (event === "connect") {
23
+ for (let [action, content] of this.messageQueue) {
24
+ this.sendChat(action, content);
25
+ }
26
+ this.messageQueue = [];
27
+ }
28
+ }
29
+
30
+ async handleDiscordChatEvent(event) {
31
+ let text = lib.escapeString(event.content);
32
+ await this.instance.server.sendRcon(`/sc game.print('${text}')`, true);
33
+ }
34
+
35
+ sendChat(action, content) {
36
+ this.instance.sendTo("controller",
37
+ new InstanceActionEvent(this.instance.name, action, content)
38
+ );
39
+ }
40
+
41
+ async onOutput(output) {
42
+ if (output.type !== "action") {
43
+ return;
44
+ }
45
+
46
+ if (this.host.connector.connected) {
47
+ this.sendChat(output.action, output.message);
48
+ } else {
49
+ this.messageQueue.push([output.action, output.message]);
50
+ }
51
+ }
52
+ }
53
+
54
+ module.exports = {
55
+ InstancePlugin,
56
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@rithien/discord_bridge",
3
+ "version": "0.3.0",
4
+ "description": "Clusterio plugin bridging chat between instances and Discord, with per-instance channel routing",
5
+ "main": "info.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "prepare": "webpack-cli --env production"
9
+ },
10
+ "keywords": [
11
+ "clusterio",
12
+ "factorio",
13
+ "discord"
14
+ ],
15
+ "author": "rithien <jacek@zaluzje.bialystok.pl>",
16
+ "license": "MIT",
17
+ "peerDependencies": {
18
+ "@clusterio/lib": "^2.0.0-alpha.14"
19
+ },
20
+ "devDependencies": {
21
+ "@clusterio/lib": "^2.0.0-alpha.14",
22
+ "@clusterio/web_ui": "^2.0.0-alpha.14",
23
+ "webpack": "^5.88.2",
24
+ "webpack-cli": "^5.1.4",
25
+ "webpack-merge": "^5.9.0"
26
+ },
27
+ "dependencies": {
28
+ "discord.js": "^14.14.1"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }
package/web/index.jsx ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ const path = require("path");
3
+ const webpack = require("webpack");
4
+ const { merge } = require("webpack-merge");
5
+
6
+ const common = require("@clusterio/web_ui/webpack.common");
7
+
8
+ module.exports = (env = {}) => merge(common(env), {
9
+ context: __dirname,
10
+ entry: "./web/index.jsx",
11
+ output: {
12
+ path: path.resolve(__dirname, "dist", "web"),
13
+ },
14
+ plugins: [
15
+ new webpack.container.ModuleFederationPlugin({
16
+ name: "discord_bridge",
17
+ library: { type: "var", name: "plugin_discord_bridge" },
18
+ exposes: {
19
+ "./": "./info.js",
20
+ "./package.json": "./package.json",
21
+ },
22
+ shared: {
23
+ "@clusterio/lib": { import: false },
24
+ "@clusterio/web_ui": { import: false },
25
+ },
26
+ }),
27
+ ],
28
+ });