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.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;
|
||||||
|
57
run.js
57
run.js
@ -6,35 +6,38 @@ 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.hasOwnProperty("bans")) {
|
if(!this.db) { /* if it wasn't empty */
|
||||||
this.db.bans = {};
|
this.db = JSON.parse(rawDB);
|
||||||
}
|
}
|
||||||
if(!this.db.bans.hasOwnProperty("*")) {
|
|
||||||
this.db.bans["*"] = [];
|
/* repair any deficiencies in the DB; if this is a new DB, that's everything */
|
||||||
}
|
if(!this.db.hasOwnProperty("bans")) {
|
||||||
if(!this.db.hasOwnProperty("quoteArrs")) {
|
this.db.bans = {};
|
||||||
this.db.quoteArrs = {};
|
}
|
||||||
}
|
if(!this.db.bans.hasOwnProperty("*")) {
|
||||||
if(!this.db.quoteArrs.hasOwnProperty("realityonce")) {
|
this.db.bans["*"] = [];
|
||||||
this.db.quoteArrs.realityonce = [];
|
}
|
||||||
}
|
if(!this.db.hasOwnProperty("quoteArrs")) {
|
||||||
if(!this.db.hasOwnProperty("kicks")) {
|
this.db.quoteArrs = {};
|
||||||
this.db.kicks = {};
|
}
|
||||||
}
|
if(!this.db.hasOwnProperty("kicks")) {
|
||||||
if(!this.db.hasOwnProperty("kickers")) {
|
this.db.kicks = {};
|
||||||
this.db.kickers = {};
|
}
|
||||||
}
|
if(!this.db.hasOwnProperty("kickers")) {
|
||||||
if(!this.db.hasOwnProperty("modehate")) {
|
this.db.kickers = {};
|
||||||
this.db.modehate = [];
|
}
|
||||||
}
|
if(!this.db.hasOwnProperty("modehate")) {
|
||||||
if(!this.db.hasOwnProperty("locks")) {
|
this.db.modehate = [];
|
||||||
this.db.locks = [];
|
}
|
||||||
}
|
if(!this.db.hasOwnProperty("locks")) {
|
||||||
|
this.db.locks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate bot properties with config data
|
// Populate bot properties with config data
|
||||||
|
Loading…
Reference in New Issue
Block a user