-
Notifications
You must be signed in to change notification settings - Fork 7
/
boot.js
55 lines (52 loc) · 1.51 KB
/
boot.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
var glob = require('glob')
, path = require('path')
module.exports = function (cb) {
var zenbot = require('./')()
try {
var c = require('./conf')
}
catch (e) {
c = {}
}
var defaults = require('./conf-sample')
Object.keys(defaults).forEach(function (k) {
if (typeof c[k] === 'undefined') {
c[k] = defaults[k]
}
})
zenbot.set('@zenbot:conf', c)
function withMongo () {
glob('extensions/*', {cwd: __dirname, absolute: true}, function (err, results) {
if (err) return cb(err)
results.forEach(function (result) {
if (path.basename(result) === 'README.md') {
return
}
var ext = require(path.join(result, '_codemap'))
zenbot.use(ext)
})
cb(null, zenbot)
})
}
var u = 'mongodb://' + c.mongo.host + ':' + c.mongo.port + '/' + c.mongo.db
require('mongodb').MongoClient.connect(u, function (err, db) {
if (err) {
zenbot.set('zenbot:db.mongo', null)
console.error('warning: mongodb not accessible. some features (such as backfilling/simulation) may be disabled.')
return withMongo()
}
zenbot.set('zenbot:db.mongo', db)
if (c.mongo.username) {
db.authenticate(c.mongo.username, c.mongo.password, function (err, result) {
if (err) {
zenbot.set('zenbot:db.mongo', null)
console.error('warning: mongodb auth failed. some features (such as backfilling/simulation) may be disabled.')
}
withMongo()
})
}
else {
withMongo()
}
})
}