Merge pull request #303 from zuzak/rc

Add UDP packet functionality
This commit is contained in:
Luke Slater 2013-05-17 09:30:53 -07:00
commit 8f2cc5bd4d
3 changed files with 40 additions and 0 deletions

12
modules/udp/README.md Normal file
View File

@ -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.

6
modules/udp/config.json Normal file
View File

@ -0,0 +1,6 @@
{
"port":14628,
"address": "127.0.0.1",
"server": "freenode",
"channel": "#oaosidl"
}

22
modules/udp/udp.js Normal file
View File

@ -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);
};