-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
135 lines (112 loc) · 2.99 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/******************************
--[ Justicar WoD Bot ]--
Made for Sanguinus.org
_.mmmmmmmmm._
dMMMY'~~~~~`YMMMb
dMMMY' `YMMMb
dMMMY' `YMMMb
CMMM( )MMMD
YMMMb. .dMMMY
YMMMb. .dMMMY
`YMMMboo...oodMMMY'
. `"#MMMMMMM#"' .
Mb `MMM' dM
MMMM. .dMMMb. .dMMM
MMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMM
MMMM' `YMMMY' `YMMM
MM' )MMM( `MM
' .MMMMM. `
dMMMMMb
dMMMMMMMb
"""""""
by Matt Webb
********************************/
/**
* @fileOverview Justicar IRC Bot, an IRC bot with a web interface meant for managing large IRC World of Darkness games.
* @author <a href="[email protected]">Matthew Webb</a>
* @version 0.1
*/
// This sets environment variable based on .env file, must be done first
require('dotenv').config();
console.log(process.env.NODE_ENV);
//
// Includes
//
// General modules
const chalk = require('chalk'),
q = require('q')
;
//
// Edgy cool start up graphic. Cuz we rock it like its 1994 around here.
//
let introASCII = require('fs').readFileSync('art/ankh.txt', 'utf8');
console.log(chalk.red(introASCII));
if(process.env.NODE_ENV === 'development') {
console.log(chalk.yellow.bold("=== WARNING: Development Mode ==="));
} else {
console.log(chalk.green("Production Mode"));
}
// Database modules
const mongoose = require('mongoose')
;
//
// Load configs
let config = require("./config/config").getConfig();
// ***
//
// Database
//
// ***
mongoose.Promise = q.Promise;
// Set to debug mode if in dev mode (handled by .env file)
if(process.env.NODE_ENV === 'development') {
mongoose.set("debug", true);
}
let dbConnectionPromise = mongoose.connect(config.db.uri, { useMongoClient: true }).then(
function(db) {
console.log(chalk.green("\nConnected to database @", config.db.uri));
return true;
},
function(err) {
console.error(chalk.red("\nDatabase connection error:", err));
process.exit();
}
);
require("./database/models.js");
// IRC modules
const irc = require('irc'),
JusticarIRC = require('./irc/JusticarIRC')
;
// ***
//
// Configure IRC bot client
//
// ***
if (config.irc && config.irc.server && config.irc.nick) {
JusticarIRC.bot.client = new irc.Client(config.irc.server, config.irc.nick, Object.assign({}, config.irc.settings, {autoConnect:false}));
} else {
console.error(chalk.red("!!!Invalid IRC configuration!!!"));
process.exit();
}
let server = require('./server/server.js');
dbConnectionPromise.then(
function() {
let usePort = config.www.port || 3000;
server.listen(usePort, function() {
console.log(chalk.green.bold("\nWeb server ready on port", usePort));
});
JusticarIRC.bot.connect();
},
function(err) {
console.error(err);
console.log('%s MongoDB connection error. Exiting.');
process.exit();
}
).catch(
function(err) {
console.error(err);
console.log('Error starting server. Exiting.');
process.exit();
}
);