3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-27 21:22:38 +01:00
dbot/modules/udp/udp.js

32 lines
730 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) {
2016-05-07 18:29:18 +02:00
var servers = [];
2016-05-07 18:04:10 +02:00
_.each(dbot.config.modules.udp.servers, function(data) {
2013-03-06 14:55:35 +01:00
var server = dgram.createSocket("udp4");
2016-05-07 18:29:18 +02:00
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();
2016-05-07 18:04:10 +02:00
if (msginfo.address == data.address) {
dbot.say(data.server, data.channel, message);
2013-03-06 17:34:59 +01:00
}
2014-02-18 19:47:43 +01:00
}.bind(this));
2016-05-07 18:29:18 +02:00
});
this.onLoad = function() {
_.each(servers, function(server) {
server.bind(data.port);
});
}.bind(this);
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
};