From 248ca9b790cd197b569efa8aa8ca6a5355ff9039 Mon Sep 17 00:00:00 2001 From: Psychedelic Squid Date: Tue, 6 Mar 2012 23:54:52 +0000 Subject: [PATCH] Create and/or fix a missing/incomplete DB on running. --- run.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/run.js b/run.js index fc29667..73d51b2 100644 --- a/run.js +++ b/run.js @@ -6,7 +6,33 @@ require('./snippets'); var DBot = function(timers) { // Load external files this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); - this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); + try { + this.db = JSON.parse(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.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 this.name = this.config.name || 'dbox';