Skip to content

Instantly share code, notes, and snippets.

@aaronj1335
Created May 13, 2014 02:11
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 aaronj1335/097d69f9e2d09703bc4f to your computer and use it in GitHub Desktop.
Save aaronj1335/097d69f9e2d09703bc4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env node --harmony
function setup() {
var net = require('net');
var fs = require('fs');
var irc = require('irc-js');
var Notifier = require('node-notifier');
var notifier = new Notifier();
var ca = fs.readFileSync(process.env.HOME + '/.ssh/znc.pem').toString();
var bot = irc.connect({
nick: 'aaronj1335',
server: {
address: 'dev1.waterfall.com',
port: 1335,
ssl: {
ca: ca
}
},
user: {
username: 'aaronj1335',
password: 'uwish'
}
});
bot.match('*', function(msg) {
console.log(msg.type, msg.params);
});
bot.match('PRIVMSG', function(msg) {
var chan = msg.params[0];
var text = msg.params[1] && msg.params[1].slice(1);
if (chan === '#waterfall') {
notifier.notify({message: text});
}
});
process.on('uncaughtException', function(err) {
console.dir(err);
});
bot.socket.on('error', function(err) {
console.dir(err);
});
}
if (require.main === module) {
// ya so i dunno why but if i just call `setup` i get
// DEPTH_ZERO_SELF_SIGNED_CERT error events emitted on `bot.socket`
// setup();
// BUT if i run it in its own context, that doesn't happen. and if i change
// the contents of the pem file, it doesn't work either way, so i don't think
// it's the pem file.
var vm = require('vm');
var fn = setup.toString().replace(/^[^{]+\{/, '').replace(/\}\s*$/, '');
vm.runInContext(fn, vm.createContext({
require: require,
process: process,
console: console
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment