forked from DeviaVir/zenbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zenbot.js
48 lines (38 loc) · 1.08 KB
/
zenbot.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
var semver = require('semver')
var path = require('path')
var program = require('commander')
program._name = 'zenbot'
var versions = process.versions
if (semver.gt('8.3.0', versions.node)) {
console.log('You are running a node.js version older than 8.3.x, please upgrade via https://nodejs.org/en/')
process.exit(1)
}
var fs = require('fs')
, boot = require('./boot')
boot(function (err, zenbot) {
if (err) {
throw err
}
program.version(zenbot.version)
var command_directory = './commands'
fs.readdir(command_directory, function(err, files){
if (err) {
throw err
}
var commands = files.map((file)=>{
return path.join(command_directory, file)
}).filter((file)=>{
return fs.statSync(file).isFile()
})
commands.forEach((file)=>{
require(path.resolve(__dirname, file.replace('.js','')))(program, zenbot.conf)
})
program
.command('*', 'Display help', { noHelp: true })
.action((cmd)=>{
console.log('Invalid command: ' + cmd)
program.help()
})
program.parse(process.argv)
})
})