3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 12:12:35 +01:00
dbot/modules/udp/udp.js

23 lines
611 B
JavaScript
Raw Normal View History

2013-03-06 14:55:35 +01:00
/**
2013-03-06 18:48:48 +01:00
* Module Name: UDP
2013-03-06 15:17:24 +01:00
* Description: Relays UDP packets, intended for
* a feed of RecentChanges on a MediaWiki install.
2013-03-06 14:55:35 +01:00
*/
var dgram = require('dgram');
2013-03-06 18:48:48 +01:00
var udp = function(dbot) {
2013-03-06 14:55:35 +01:00
var server = dgram.createSocket("udp4");
2013-03-06 17:34:59 +01:00
server.on("message", function(msg, msginfo) {
2013-03-06 15:17:24 +01:00
var message = msg.toString();
2013-03-06 15:18:43 +01:00
console.log(message);
2013-03-06 18:48:48 +01:00
if (msginfo.address == dbot.config.udp.address) {
dbot.say(dbot.config.udp.server, dbot.config.udp.channel, message);
2013-03-06 17:34:59 +01:00
}
2013-03-06 14:55:35 +01:00
});
2013-03-06 18:48:48 +01:00
server.bind(dbot.config.udp.port);
2013-03-06 14:55:35 +01:00
};
exports.fetch = function(dbot) {
2013-03-06 18:48:48 +01:00
return new udp(dbot);
2013-03-06 14:55:35 +01:00
};