Module specific config. Allows specify dbKeys to ensure default objects there for use.

This commit is contained in:
Luke Slater 2012-12-12 18:07:08 +00:00
parent 65414f6975
commit c64e66da17
6 changed files with 27 additions and 30 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
# Ignore the user config files # Ignore the user config files
config.json ./config.json
# Ignore the user database # Ignore the user database
db.json db.json

View File

@ -0,0 +1,3 @@
{
"dbKeys": [ "bans", "locks" ]
}

3
modules/kick/config.json Normal file
View File

@ -0,0 +1,3 @@
{
"dbKeys": [ "kicks", "kickers" ]
}

View File

@ -0,0 +1,3 @@
{
"dbKeys": [ "quoteArrs" ]
}

4
modules/web/config.json Normal file
View File

@ -0,0 +1,4 @@
{
"webHost": "localhost",
"webPort": 8080
}

42
run.js
View File

@ -23,35 +23,6 @@ var DBot = function(timers) {
this.db = {}; this.db = {};
} }
// 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 = [];
}
if(!this.db.hasOwnProperty("ignores")) {
this.db.ignores = {};
}
if(!this.db.hasOwnProperty('polls')) {
this.db.polls = {};
}
// Load Strings file // Load Strings file
try { try {
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
@ -236,6 +207,19 @@ DBot.prototype.reloadModules = function() {
// Invalid or no string info // Invalid or no string info
} }
// Load the module config data
try {
var config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8'))
this.config[name] = config;
for(var i=0;i<config.dbKeys;i++) {
if(!this.db.hasOwnProperty(config.dbKeys[i])) {
this.db[config.dbKeys[i]] = {};
}
}
} catch(err) {
// Invalid or no config data
}
this.modules.push(module); this.modules.push(module);
} catch(err) { } catch(err) {
console.log(this.t('module_load_error', {'moduleName': name})); console.log(this.t('module_load_error', {'moduleName': name}));