-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
79 lines (65 loc) · 1.69 KB
/
main.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
'use strict';
(function bootstrap(){
var conf = require('nconf')
.argv()
.env()
.file({file: getConfigFile()})
.defaults({
'karmaCooldown': 60
,'botName': '```zoidbox'
,'testingChannel': '#zoidbox'
});
var bot = initIRC( conf );
//initialize
bot.setMaxListeners(20);
bot.use( require('./lib/core') );
bot.use( require('./lib/ops') );
bot.loadPlugins();
//=====================================================
function getConfigFile(){
var override = './lib/config.user.json'
,def = './lib/config.json';
return require('fs').existsSync(override) ? override : def;
}
function initIRC( conf ){
var irc = require( 'irc' );
var b = new irc.Client(
conf.get('server')
, conf.get('botName')
, {
channels: conf.get('channels')
,floodProtection: true
}
);
b.conf = conf;
b.botName = conf.get('botName'); //this changes based on nick
b.botID = conf.get('botName');
b.testingChannel = conf.get('testingChannel');
b.channels = conf.get('channels');
b.use = function use( plugin ){
plugin( bot );
};
b.loadPlugins = function loadPlugins(){
var plugins = [];
var walk = require('walk');
var walker = walk.walk('./plugins', { followLinks: false });
walker.on('file', function(root, stat, next){
if ( stat.name.slice(-3) === '.js' ){
console.log('loading plugin %s/%s', root, stat.name);
try {
bot.use( require( root + '/' + stat.name ) );
plugins.push( root + '/' + stat.name );
}catch (err){
console.error( err );
console.log('----------------------');
}
}
next();
});
walker.on('end', function(){
console.log('plugins loaded: %s', plugins);
});
};
return b;
}
})();