-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.js
69 lines (58 loc) · 1.81 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var sys = require('sys'),
fs = require('fs'),
App = require('fatbot/app').App,
command_handler = require('fatbot/command_handler'),
utils = require('fatbot/utils'),
logging = require('fatbot/logging'),
log = logging.log;
log.options.level = logging.levels.info;
var console_handler = new logging.ConsoleHandler(log, logging.console_color_formatter());
var args = {};
command_handler.args_from_string(args, process.argv.slice(2));
function show_help() {
sys.puts('fatbot [opts] your_config.json');
sys.puts(' --verbose');
sys.puts(' show debug messages');
sys.puts(' --quiet');
sys.puts(' dont output logging to stdout');
sys.puts(' --logfile=FILE')
sys.puts(' output logging to FILE');
};
if( args.help ) {
show_help();
process.exit(0);
}
if( !args.args ) {
log.error('you must pass a config file!\n');
show_help();
process.exit(1)
}
// config the intervaler logger now to set a nicer level
log.Logger({name: 'intervaler', level: logging.levels.info});
if( args.verbose ) {
log.options.level = logging.levels.debug;
}
if( args.quiet ) {
console_handler.remove();
}
if( args.logfile && typeof args.logfile == 'string') {
// send logging messages to a log file
var file_handler = new logging.FileHandler(log, args.logfile)
}
process.addListener('error', function(err) {
log.exception(err, 'UNCAUGHT ERROR');
});
try {
var data = fs.readFileSync(args.args);
options = JSON.parse(data.toString());
} catch(e) {
log.error('failed opening config: '+e);
log.info('your config file probably isnt valid json - try http://www.jsonlint.com');
process.exit(1);
}
var app = new App(options);
log.info('created app ok');
log.info('loading plugins...');
app.load_plugins();
log.info('all systems are go!');
app.start();