diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | main.js | 28 |
2 files changed, 25 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2ce437 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*.un~ +*.swp +node_modules/ @@ -4,15 +4,31 @@ var cmdopt = require('cmdopt') , _ = 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("--checkinsUrl", "URL to use when looking for checkins"); -var config = { - channel: '#bitraf2', +var args = process.argv.slice(2); +var defaults = { checkinsUrl: 'http://hermes.bitraf.no/~trygvis/checkins.php', nick: os.hostname() }; -var bot = require('./lib/client.js')(config); +try { + var config = parser.parse(args); + config = _.defaults(config, defaults); + console.log("config", config); + if (config.help) console.log(parser.help()); -var r = repl.start('irc> '); -r.context.bot = bot; -r.context.config = config; + var bot = require('./lib/client.js')(config); + var r = repl.start('irc> '); + r.context.bot = bot; + r.context.config = config; +} catch (ex) { + if (ex instanceof cmdopt.ParseError) { + process.stderr.write(ex.message + "\n"); + process.exit(1); + } + throw ex; +} |