forked from GitHub/dbot
Fail on invalid-syntax DBs, instead of replacing them. Also, shunt creation of 'realityonce' array to the realityonce listener, so it's not created before being needed.
This commit is contained in:
parent
730b65761e
commit
92767dbfb1
@ -247,6 +247,9 @@ var quotes = function(dbot) {
|
|||||||
dbot.db.bans['*'].include(data.user)) {
|
dbot.db.bans['*'].include(data.user)) {
|
||||||
dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.');
|
dbot.say(data.channel, data.user + ' is banned from using this command. Commence incineration.');
|
||||||
} else {
|
} else {
|
||||||
|
if(!dbot.db.quoteArrs.hasOwnProperty('realityonce')) {
|
||||||
|
dbot.db.quoteArrs['realityonce'] = [];
|
||||||
|
}
|
||||||
dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.');
|
dbot.db.quoteArrs['realityonce'].push('reality ' + once[1] + '.');
|
||||||
addStack.push('realityonce');
|
addStack.push('realityonce');
|
||||||
rmAllowed = true;
|
rmAllowed = true;
|
||||||
|
17
run.js
17
run.js
@ -6,11 +6,18 @@ require('./snippets');
|
|||||||
var DBot = function(timers) {
|
var DBot = function(timers) {
|
||||||
// Load external files
|
// Load external files
|
||||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||||
|
this.db = null;
|
||||||
|
var rawDB;
|
||||||
try {
|
try {
|
||||||
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
var rawDB = fs.readFileSync('db.json', 'utf-8');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.db = {};
|
this.db = {}; /* if no db file, make empty one */
|
||||||
} finally { /* fill any missing parts of the db; if this is a new DB, that's all of them */
|
}
|
||||||
|
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")) {
|
if(!this.db.hasOwnProperty("bans")) {
|
||||||
this.db.bans = {};
|
this.db.bans = {};
|
||||||
}
|
}
|
||||||
@ -20,9 +27,6 @@ var DBot = function(timers) {
|
|||||||
if(!this.db.hasOwnProperty("quoteArrs")) {
|
if(!this.db.hasOwnProperty("quoteArrs")) {
|
||||||
this.db.quoteArrs = {};
|
this.db.quoteArrs = {};
|
||||||
}
|
}
|
||||||
if(!this.db.quoteArrs.hasOwnProperty("realityonce")) {
|
|
||||||
this.db.quoteArrs.realityonce = [];
|
|
||||||
}
|
|
||||||
if(!this.db.hasOwnProperty("kicks")) {
|
if(!this.db.hasOwnProperty("kicks")) {
|
||||||
this.db.kicks = {};
|
this.db.kicks = {};
|
||||||
}
|
}
|
||||||
@ -35,7 +39,6 @@ var DBot = function(timers) {
|
|||||||
if(!this.db.hasOwnProperty("locks")) {
|
if(!this.db.hasOwnProperty("locks")) {
|
||||||
this.db.locks = [];
|
this.db.locks = [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Populate bot properties with config data
|
// Populate bot properties with config data
|
||||||
this.name = this.config.name || 'dbox';
|
this.name = this.config.name || 'dbox';
|
||||||
|
Loading…
Reference in New Issue
Block a user