Created
February 10, 2012 08:07
-
-
Save abackstrom/1787731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
Send UDP packets to the daemon listening on port 8888, | |
and they will be echoed to the configured IRC channel: | |
echo "my hovercraft is full of eels" | nc -w1 -u 127.0.0.1 8888 | |
create a config.js file in the same directory as this | |
file, with the following structure: | |
var config = {}; | |
config.host = 'irc.freenode.net'; | |
config.port = 6667; | |
config.channel = '#foo'; | |
config.nick = 'foobot'; | |
module.exports = config; | |
*/ | |
// node-irc: https://github.com/martynsmith/node-irc | |
// $ npm install irc | |
var irc = require('irc'); | |
var dgram = require('dgram'); | |
var config = require('./config'); | |
var bot = new irc.Client( | |
config.host, | |
config.nick, | |
{ | |
debug: true, | |
port: config.port, | |
channels: [ config.channel ], | |
} | |
); | |
bot.addListener('message', function (from, message) { | |
console.log('<%s> %s', from, message); | |
}); | |
var server = dgram.createSocket("udp4"); | |
server.on("message", function (msg, rinfo) { | |
bot.say(config.channel, "[dbg " + rinfo.address + ":" + rinfo.port + "] " + msg); | |
}); | |
server.on("listening", function () { | |
var address = server.address(); | |
console.log("server listening " + address.address + ":" + address.port); | |
}); | |
server.bind(8888); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment