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;
|
||||
|
17
run.js
17
run.js
@ -6,11 +6,18 @@ 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 */
|
||||
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 = {};
|
||||
}
|
||||
@ -20,9 +27,6 @@ var DBot = function(timers) {
|
||||
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 = {};
|
||||
}
|
||||
@ -35,7 +39,6 @@ var DBot = function(timers) {
|
||||
if(!this.db.hasOwnProperty("locks")) {
|
||||
this.db.locks = [];
|
||||
}
|
||||
}
|
||||
|
||||
// Populate bot properties with config data
|
||||
this.name = this.config.name || 'dbox';
|
||||
|
Loading…
Reference in New Issue
Block a user