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

25 lines
659 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);
2014-02-18 19:47:43 +01:00
if (msginfo.address == this.config.address) {
dbot.say(this.config.server, this.config.channel, message);
2013-03-06 17:34:59 +01:00
}
2014-02-18 19:47:43 +01:00
}.bind(this));
2014-09-13 21:23:00 +02:00
this.onLoad = function() {
server.bind(this.config.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
};