Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created February 10, 2012 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abackstrom/1787731 to your computer and use it in GitHub Desktop.
Save abackstrom/1787731 to your computer and use it in GitHub Desktop.
#!/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