mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
Module config now loaded from config.json , rleloaded upon reloading and various module changes to make it work right [#474] [#489]
This commit is contained in:
parent
2471e4bca3
commit
4a7fcd57b3
@ -38,7 +38,7 @@ var admin = function(dbot) {
|
||||
};
|
||||
|
||||
this.onLoad = function() {
|
||||
var configMap = dbot.config;
|
||||
/*var configMap = dbot.config;
|
||||
this.db.scan('config', function(config) {
|
||||
if(config) {
|
||||
var currentPath = configMap,
|
||||
@ -53,7 +53,7 @@ var admin = function(dbot) {
|
||||
|
||||
currentPath[key[i]] = value;
|
||||
}
|
||||
}, function(err) { });
|
||||
}, function(err) { });*/
|
||||
}.bind(this);
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,6 @@ var request = require('request');
|
||||
_ = require('underscore')._;
|
||||
|
||||
var dent = function(dbot) {
|
||||
this.dbot = dbot;
|
||||
this.StatusRegex = {
|
||||
identica: /\bhttps?:\/\/identi\.ca\/notice\/(\d+)\b/ig,
|
||||
twitter: /\bhttps?:\/\/twitter\.com\/\w+\/status\/(\d+)\b/ig
|
||||
@ -15,8 +14,8 @@ var dent = function(dbot) {
|
||||
|
||||
this.api = {
|
||||
'post': function(content) {
|
||||
var username = dbot.config.dent.username,
|
||||
password = dbot.config.dent.password,
|
||||
var username = this.config.username,
|
||||
password = this.config.password,
|
||||
info,
|
||||
auth = "Basic " +
|
||||
new Buffer(username + ":" + password).toString("base64");
|
||||
@ -57,7 +56,7 @@ var dent = function(dbot) {
|
||||
this.commands['~dent'].regex = [/^~dent (.+)$/, 2];
|
||||
|
||||
this.onLoad = function() {
|
||||
if(dbot.config.dent.dentQuotes === true && _.has(dbot.modules, 'quotes')) {
|
||||
if(this.config.dentQuotes === true && _.has(dbot.modules, 'quotes')) {
|
||||
dbot.api.event.addHook('~qadd', function(key, text) {
|
||||
if(text.indexOf('~~') == -1) {
|
||||
this.api.post(key + ': ' + text);
|
||||
|
@ -30,7 +30,7 @@ var pages = function(dbot) {
|
||||
|
||||
/* TODO: merge back into github module */
|
||||
var milestones;
|
||||
request({"url":"https://api.github.com/repos/" + dbot.config.github.defaultrepo + "/milestones?state=open","headers":{"User-Agent":"reality/depressionbot (project module)"}}, function(error, response, body){
|
||||
request({"url":"https://api.github.com/repos/" + dbot.config.modules.github.defaultrepo + "/milestones?state=open","headers":{"User-Agent":"reality/depressionbot (project module)"}}, function(error, response, body){
|
||||
milestones = JSON.parse(body);
|
||||
});
|
||||
|
||||
@ -53,7 +53,7 @@ var pages = function(dbot) {
|
||||
"botname": dbot.config.name
|
||||
}),
|
||||
"curr839": dbot.config.language,
|
||||
"repo": dbot.config.github.defaultrepo,
|
||||
"repo": dbot.config.modules.github.defaultrepo,
|
||||
"branch": dbot.t("branch",{
|
||||
"branch": branch
|
||||
}),
|
||||
|
@ -14,30 +14,30 @@ var project = function(dbot) {
|
||||
var list = [];
|
||||
if(_.has(dbot.modules,'dent')){
|
||||
list.push(dbot.t("dent-account", {
|
||||
"username": dbot.config.dent.username
|
||||
"username": dbot.config.modules.dent.username
|
||||
}));
|
||||
if(_.has(dbot.config.dent.dentQuotes)) {
|
||||
if(_.has(dbot.config.modules.dent.dentQuotes)) {
|
||||
list.push(dbot.t("dent-push"));
|
||||
}
|
||||
}
|
||||
if(_.has(dbot.modules,'link')){
|
||||
if(dbot.config.link.autoTitle){
|
||||
if(dbot.config.modules.link.autoTitle){
|
||||
list.push(dbot.t("link-autotitle"));
|
||||
}
|
||||
}
|
||||
if(_.has(dbot.modules,'quotes')){
|
||||
list.push(dbot.t("quote-rmlimit", {
|
||||
"limit": dbot.config.quotes.rmLimit
|
||||
"limit": dbot.config.modules.quotes.rmLimit
|
||||
}));
|
||||
}
|
||||
if(_.has(dbot.modules,'report')){
|
||||
if(dbot.config.report.notifyVoice){
|
||||
if(dbot.config.modules.report.notifyVoice){
|
||||
list.push(dbot.t("report-notifyvoice"));
|
||||
}
|
||||
}
|
||||
if(_.has(dbot.modules,'web')){
|
||||
list.push(dbot.t("web-port", {
|
||||
"port": dbot.config.web.webPort
|
||||
"port": dbot.config.modules.web.webPort
|
||||
}));
|
||||
}
|
||||
return list;
|
||||
|
@ -3,13 +3,14 @@ var express = require('express'),
|
||||
fs = require('fs');
|
||||
|
||||
var webInterface = function(dbot) {
|
||||
this.config = dbot.config.modules.web;
|
||||
this.pub = 'public';
|
||||
this.app = express();
|
||||
|
||||
this.app.use(express.static(this.pub));
|
||||
this.app.set('view engine', 'jade');
|
||||
|
||||
var server = this.app.listen(dbot.config.web.webPort);
|
||||
var server = this.app.listen(this.config.webPort);
|
||||
|
||||
this.reloadPages = function() {
|
||||
var pages = dbot.pages;
|
||||
|
80
run.js
80
run.js
@ -19,37 +19,10 @@ var DBot = function() {
|
||||
this.db = {};
|
||||
}
|
||||
|
||||
if(!_.has(this.db, 'config')) {
|
||||
this.db.config = {};
|
||||
}
|
||||
|
||||
/*** Load the fancy DB ***/
|
||||
this.ddb = new DatabaseDriver();
|
||||
|
||||
/*** Load the Config ***/
|
||||
|
||||
if(!fs.existsSync('config.json')) {
|
||||
console.log('Error: config.json file does not exist. Stopping');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
this.config = _.clone(this.db.config);
|
||||
try {
|
||||
_.defaults(this.config, JSON.parse(fs.readFileSync('config.json', 'utf-8')));
|
||||
} catch(err) {
|
||||
console.log('Config file is invalid. Stopping: ' + err);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
try {
|
||||
var defaultConfig = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8'));
|
||||
} catch(err) {
|
||||
console.log('Error loading sample config. Bugger off this should not even be edited. Stopping.');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Load missing config directives from sample file
|
||||
_.defaults(this.config, defaultConfig);
|
||||
this.reloadConfig();
|
||||
|
||||
/*** Load main strings ***/
|
||||
|
||||
@ -83,6 +56,33 @@ var DBot = function() {
|
||||
this.instance.connectAll();
|
||||
};
|
||||
|
||||
DBot.prototype.reloadConfig = function() {
|
||||
this.config = {};
|
||||
|
||||
if(!fs.existsSync('config.json')) {
|
||||
console.log('Error: config.json file does not exist. Stopping');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
try {
|
||||
this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8'));
|
||||
} catch(err) {
|
||||
console.log('Config file is invalid. Stopping: ' + err);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
try {
|
||||
var defaultConfig = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8'));
|
||||
} catch(err) {
|
||||
console.log('Error loading sample config. Bugger off this should not even be edited. Stopping.');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// Load missing config directives from sample file
|
||||
if(!_.has(this.config, 'modules')) this.config.modules = {};
|
||||
_.defaults(this.config, defaultConfig);
|
||||
};
|
||||
|
||||
// Say something in a channel
|
||||
DBot.prototype.say = function(server, channel, message) {
|
||||
this.instance.say(server, channel, message);
|
||||
@ -138,6 +138,7 @@ DBot.prototype.reloadModules = function() {
|
||||
this.api = {};
|
||||
this.stringMap = {};
|
||||
this.usage = {};
|
||||
this.reloadConfig();
|
||||
|
||||
try {
|
||||
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||
@ -173,25 +174,17 @@ DBot.prototype.reloadModules = function() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load the module config data
|
||||
config = {};
|
||||
|
||||
if(_.has(this.db.config, name)) {
|
||||
config = _.clone(this.db.config[name]);
|
||||
}
|
||||
|
||||
try {
|
||||
var defaultConfig = fs.readFileSync(moduleDir + 'config.json', 'utf-8');
|
||||
if(!_.has(this.config.modules, name)) this.config.modules[name] = {};
|
||||
if(fs.existsSync(moduleDir + 'config.json')) {
|
||||
try {
|
||||
defaultConfig = JSON.parse(defaultConfig);
|
||||
} catch(err) { // syntax error
|
||||
var defaultConfig = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8'));
|
||||
} catch(err) { // Syntax error
|
||||
this.status[name] = 'Error parsing config: ' + err + ' ' + err.stack.split('\n')[2].trim();
|
||||
continue;
|
||||
}
|
||||
config = _.defaults(config, defaultConfig);
|
||||
} catch(err) {
|
||||
// Invalid or no config data
|
||||
this.config.modules[name] = _.defaults(this.config.modules[name], defaultConfig);
|
||||
}
|
||||
var config = this.config.modules[name];
|
||||
|
||||
// Don't shit out if dependencies not met
|
||||
if(_.has(config, 'dependencies')) {
|
||||
@ -202,7 +195,6 @@ DBot.prototype.reloadModules = function() {
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
this.config[name] = config;
|
||||
|
||||
// Groovy funky database shit
|
||||
if(!_.has(config, 'dbType') || config.dbType == 'olde') {
|
||||
@ -235,7 +227,7 @@ DBot.prototype.reloadModules = function() {
|
||||
|
||||
module.name = name;
|
||||
module.db = this.ddb.databanks[name];
|
||||
module.config = this.config[name];
|
||||
module.config = this.config.modules[name];
|
||||
|
||||
// Load the module data
|
||||
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
||||
|
Loading…
Reference in New Issue
Block a user