diff --git a/modules/quotes.js b/modules/quotes.js index cedd678..f08b3e1 100644 --- a/modules/quotes.js +++ b/modules/quotes.js @@ -247,6 +247,9 @@ var quotes = function(dbot) { dbot.db.bans['*'].include(data.user)) { dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.'); } else { + if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) { + dbot.db.quoteArrs['realityonce'] = []; + } dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.'); addStack.push('realityonce'); rmAllowed = true; diff --git a/run.js b/run.js index be242b4..f9b5927 100644 --- a/run.js +++ b/run.js @@ -6,35 +6,38 @@ require('./snippets'); var DBot = function(timers) { // Load external files this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); + this.db = null; + var rawDB; try { - this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); + var rawDB = fs.readFileSync('db.json', 'utf-8'); } catch (e) { - this.db = {}; - } finally { /* fill any missing parts of the db; if this is a new DB, that's all of them */ - if(!this.db.hasOwnProperty("bans")) { - this.db.bans = {}; - } - if(!this.db.bans.hasOwnProperty("*")) { - this.db.bans["*"] = []; - } - if(!this.db.hasOwnProperty("quoteArrs")) { - this.db.quoteArrs = {}; - } - if(!this.db.quoteArrs.hasOwnProperty("realityonce")) { - this.db.quoteArrs.realityonce = []; - } - if(!this.db.hasOwnProperty("kicks")) { - this.db.kicks = {}; - } - if(!this.db.hasOwnProperty("kickers")) { - this.db.kickers = {}; - } - if(!this.db.hasOwnProperty("modehate")) { - this.db.modehate = []; - } - if(!this.db.hasOwnProperty("locks")) { - this.db.locks = []; - } + this.db = {}; /* if no db file, make empty one */ + } + if(!this.db) { /* if it wasn't empty */ + this.db = JSON.parse(rawDB); + } + + /* repair any deficiencies in the DB; if this is a new DB, that's everything */ + if(!this.db.hasOwnProperty("bans")) { + this.db.bans = {}; + } + if(!this.db.bans.hasOwnProperty("*")) { + this.db.bans["*"] = []; + } + if(!this.db.hasOwnProperty("quoteArrs")) { + this.db.quoteArrs = {}; + } + if(!this.db.hasOwnProperty("kicks")) { + this.db.kicks = {}; + } + if(!this.db.hasOwnProperty("kickers")) { + this.db.kickers = {}; + } + if(!this.db.hasOwnProperty("modehate")) { + this.db.modehate = []; + } + if(!this.db.hasOwnProperty("locks")) { + this.db.locks = []; } // Populate bot properties with config data