mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 11:42:36 +01:00
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.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;
|
||||
|
57
run.js
57
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
|
||||
|
Loading…
Reference in New Issue
Block a user