forked from weijingwang/Trustable-Adult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (47 loc) · 1.29 KB
/
app.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
require('dotenv').config();
const { login, discord, sequelize } = require('./client');
const discordEvents = require('./discord');
const ticker = require('./ticker');
const jobs = require('./jobs');
const servers = require('./servers');
const models = require('./bags/models'); // Registers Models before initialising.
console.log('Starting...');
sequelize.authenticate().then(() => {
return sequelize.sync();
}).then(() => {
return servers.fetch();
}).then(() => {
return ticker.fetch();
}).then(() => {
return login();
}).then(() => {
return discordEvents.register();
}).then(() => {
console.log('Ready!');
// Register any on-going Jobs.
jobs.register();
// Updates all the Prices initially.
ticker.update();
}).catch(e => {
console.error(e);
exit();
});
// Tell the process not to exit straight away.
process.stdin.resume();
let killed = false;
const exit = () => {
if (killed) {
return;
}
jobs.kill();
killed = true;
discord.destroy().then(() => {
process.exit();
});
};
// Register the Listeners for different exit events.
process.on('exit', () => exit());
process.on('SIGINT', () => exit());
process.on('SIGUSR1', () => exit());
process.on('SIGUSR2', () => exit());
process.on('uncaughtException', () => exit());