-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
41 lines (32 loc) · 1.02 KB
/
index.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
var Loader, loader, exitHandler;
if (process.env.NO_LOADER) {
require("./bot.js");
} else {
Loader = require('./loader')
loader = new Loader('./bot.js')
loader.initBot();
loader.setTimeout(180 * 1000)
loader.on('exit', function () {
process.exit();
})
process.stdin.resume();//so the program will not close instantly
process.nextTick(function() {
exitHandler = function exitHandler(options, err) {
if (options.cleanup) console.log('[Loader] cleaning up...');
if (err) {
console.log(err.stack);
}
if (options.exit) {
loader.destroy();
};
}
//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
//catches signal
process.on('SIGTERM', exitHandler.bind(null, {exit:true}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
});
}