@@ -8,12 +8,17 @@ let handlers = require('./lib/handlers');
88const NODE_ENV = process . env . NODE_ENV || 'development' ;
99let config = loadEnv ( ) ;
1010
11+ // @TODO suport all configurations
1112const client = new irc . Client (
1213 config . server ,
1314 config . botNick ,
14- { channels : config . channels }
15+ {
16+ channels : config . channels ,
17+ password : config . password || null
18+ }
1519) ;
1620
21+ // Load env variables based on filename (duh~!?)
1722function loadEnv ( ) {
1823 try {
1924 return JSON . parse ( fs . readFileSync ( `./config/${ NODE_ENV } .json` ) ) ;
@@ -23,6 +28,7 @@ function loadEnv() {
2328 }
2429}
2530
31+ // Clean and (re)bind all listeners to irc client
2632function bindListeners ( ) {
2733 console . log ( 'Listeners Binded' ) ;
2834 Object . keys ( handlers ) . forEach ( key => {
@@ -31,11 +37,13 @@ function bindListeners() {
3137 } ) ;
3238} ;
3339
40+ // Creating a watcher to monitore files
3441watch . createMonitor ( './lib' , ( monitor ) => {
3542 bindListeners ( ) ;
3643 monitor . on ( 'changed' , ( ) => reloadModuleCache ( ) ) ;
3744} ) ;
3845
46+ // Sorcery to clean and reload require cache
3947function reloadModuleCache ( ) {
4048 fs . readdir ( './lib' , ( err , files ) => {
4149 files . forEach ( deleteFileCache ) ;
0 commit comments