var cmdopt = require('cmdopt') , os = require('os') , repl = require('repl') , _ = require('underscore'); var parser = new cmdopt.Parser(); parser.option("-h, --help", "show help"); parser.option("-c, --channel=CHANNEL", "IRC channel to join"); parser.option("-n, --nick=NICK", "Nickname of the bot"); parser.option("--connect=[yes,no]", "Should the bot connect to IRC").action(function(opts, val) { opts.connect = val === "yes" }); parser.option("--feed=FEED", "A feed to watch").action(function(opts, val) { if (!opts.feeds) opts.feeds = []; opts.feeds.push(val); }); var args = process.argv.slice(2); var defaults = { channel: "#hoonk", feeds: [ // "http://search.twitter.com/search.atom?q=arktekk", // "http://search.twitter.com/search.atom?q=from:AgileBorat" // "http://search.twitter.com/search.atom?q=from:KongenDin" // "http://search.twitter.com/search.atom?q=from:NestenSivJensen" "http://search.twitter.com/search.atom?q=awesome", "http://search.twitter.com/search.atom?q=eurovision", ], nick: os.hostname(), host: "gibson.freenode.net", port: 6667, connect: true }; var bots = [{ name: 'arktekk', js: './lib/arktekk-bot.js' }]; try { var config = parser.parse(args); config = _.defaults(config, defaults); if (config.help) { console.log(parser.help()); console.log("Config:"); console.log(config); return; } _.each(bots, function(bot) { var instance = require(bot.js) instance.start(config); bot.instance = instance; }); var r = repl.start('irc> '); r.context.bots = bots; r.context.config = JSON.parse(JSON.stringify(config)); // TODO: Make the config per-plugin. r.context.setConfig = function(c) { // TODO: store configuration console.log("Setting config"); // console.log(c); _.each(bots, function(bot) { bot.instance.emit("configUpdated", config); }); config = c; r.context.config = JSON.parse(JSON.stringify(c)); return "Config updated"; } } catch (ex) { if (ex instanceof cmdopt.ParseError) { process.stderr.write(ex.message + "\n"); process.exit(1); } throw ex; }