UNPKG

discord-dj

Version:

Discord DJ Bot. Let you play music in your server. Inspired by PlugDJ

85 lines (72 loc) 2.5 kB
var Utils = require('../lib/Logic/Utils.js'); var DiscordDJ = require('../lib/index.js'); var Special = require('./Special.js'); var Discordie = require('discordie'); var fs = require('fs'); if(Discordie == null) { console.log('DiscordDJ is not installed correctly.'); console.log('Please, install it using "setup-bot.bat" or "setup-bot.sh"'); console.log('http://guichaguri.github.io/DiscordDJ/'); process.exit(0); } var config; try { config = JSON.parse(fs.readFileSync('config.json', 'utf8')); } catch(e) { config = null; } var configModified = false; var connected = false; var bot = new Discordie(); var manager = null; function getConfigObject(cfg, def) { if(typeof cfg != 'object') cfg = {}; var obj = {}; for(var key in def) { if(def.hasOwnProperty(key)) { if(def[key] != null && typeof def[key] == 'object') { obj[key] = getConfigObject(cfg[key], def[key]); } else { if(typeof cfg[key] == 'undefined') { obj[key] = def[key]; configChanged = true; } else { obj[key] = cfg[key]; } } } } return obj; } function install(shouldLogin, callback) { require('./Installer.js')(bot, config, shouldLogin, callback); configModified = true; } function connect() { var credentials = {}, hasCredentials = false; if(Utils.exists(config['token'])) { credentials['token'] = config['token']; hasCredentials = true; } if(Utils.exists(config['email']) && Utils.exists(config['password'])) { credentials['email'] = config['email']; credentials['password'] = config['password']; hasCredentials = true; } if(!hasCredentials) return install(true, finishInstallation); bot.Dispatcher.removeListener(Discordie.Events.GATEWAY_READY, handleConnection); bot.Dispatcher.removeListener(Discordie.Events.DISCONNECTED, handleDisconnection); bot.Dispatcher.once(Discordie.Events.GATEWAY_READY, handleConnection); bot.Dispatcher.once(Discordie.Events.DISCONNECTED, handleDisconnection); console.log('Trying to connect...'); bot.connect(credentials); } var obj = getConfigObject(config, { 'bla': 'hey', 'bla2': { 'bla3': 'hoho', 'bla4': null } }); console.log(obj); console.log(config);