forked from tradle/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.js
executable file
·69 lines (57 loc) · 1.43 KB
/
cmd.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
#!/usr/bin/env node
try {
const SegfaultHandler = require('segfault-handler')
SegfaultHandler.registerHandler("crash.log")
} catch (err) {}
// load .env
require('dotenv').config()
const argv = require('minimist')(process.argv.slice(2), {
alias: {
c: 'conf',
},
default: {
conf: './conf/silly.json'
}
})
const debug = require('debug')('tradle:bot:scaffold')
const {
co,
normalizeConf,
forceLog
} = require('./lib/utils')
const conf = normalizeConf(require(argv.conf))
conf.autostart = false
const app = require('./lib/app')(conf)
const init = co(function* init () {
// log(`
// Awaiting webhook POSTs at: ${conf.webhookURL}
// Expecting provider API at: ${conf.providerURL}
// Databases will be stored in: ${conf.dir}
// `)
try {
yield app.health()
log('feeling FANtastic')
} catch (err) {
log(`Error: PROVIDER COULD NOT BE REACHED at ${conf.providerURL}\n`, err.message)
}
const { bot } = app
if (conf.strategies) {
conf.strategies.forEach(path => {
log('Using strategy from ' + path)
bot.strategies.use(require(path))
})
}
if (String(conf.repl) !== 'false') {
const pepperIcon = '\uD83C\uDF36 '
const prompt = typeof conf.repl === 'string' ? conf.repl : pepperIcon
require('./lib/repl')({ prompt, app })
}
bot.start()
})
init().catch(err => {
log('Exiting due to error', err)
process.exit(1)
})
function log (...args) {
forceLog(debug, ...args)
}