Created
October 23, 2015 15:05
-
-
Save owenconti/d7691938ff0611cf2bd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load all files in the commands directory into an array | |
var commandDirs = ['./commands', './modules/customCommands']; | |
function loadFirstCommandDir() { | |
if ( commandDirs.length > 0 ) { | |
var dir = commandDirs[ 0 ]; | |
loadCommandsFromDir( dirname ); | |
} else { | |
// When we are out of dirs to load, start the bot | |
startBot(); | |
} | |
} | |
function loadCommandsFromDir( dirname ) { | |
fs.readdir( dirname , function( err, files ) { | |
if ( err ) { | |
Log.log( 'ERROR: ' + err ); | |
} | |
files.forEach( function(fileName) { | |
if ( fileName.indexOf( '.js' ) >= 0 ) { | |
commandFiles.push( require( dirname + '/' + fileName ) ); | |
} | |
} ); | |
// Remove the dirname from the commandDirs | |
commandDirs.shift(); | |
loadFirstCommandDir(); | |
}); | |
} | |
loadFirstCommandDir(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment