diff --git a/modules/udp/README.md b/modules/udp/README.md new file mode 100644 index 0000000..1c2b284 --- /dev/null +++ b/modules/udp/README.md @@ -0,0 +1,12 @@ +# UDP +Prints UDP packets; designed for a [MediaWiki installation](https://www.mediawiki.org/wiki/Manual:$wgRC2UDPAddress). + +# Configuration +## server +The server name, as configured in the main ``config.json``, that depressionbot will announce packets on. +## channel +The channel name, that depressionbot will announce packets on. +## port +The port depressionbot will listen for UDP packets on. +## address +The address depressionbot will allow UDP packets from. UDP packets sent from a different address will be ignored. diff --git a/modules/udp/config.json b/modules/udp/config.json new file mode 100644 index 0000000..4619fcd --- /dev/null +++ b/modules/udp/config.json @@ -0,0 +1,6 @@ +{ + "port":14628, + "address": "127.0.0.1", + "server": "freenode", + "channel": "#oaosidl" +} diff --git a/modules/udp/udp.js b/modules/udp/udp.js new file mode 100644 index 0000000..b7d9b76 --- /dev/null +++ b/modules/udp/udp.js @@ -0,0 +1,22 @@ +/** + * Module Name: UDP + * Description: Relays UDP packets, intended for + * a feed of RecentChanges on a MediaWiki install. + */ +var dgram = require('dgram'); + +var udp = function(dbot) { + var server = dgram.createSocket("udp4"); + server.on("message", function(msg, msginfo) { + var message = msg.toString(); + console.log(message); + if (msginfo.address == dbot.config.udp.address) { + dbot.say(dbot.config.udp.server, dbot.config.udp.channel, message); + } + }); + server.bind(dbot.config.udp.port); +}; + +exports.fetch = function(dbot) { + return new udp(dbot); +};