var fs = require('fs'), _ = require('underscore')._, jsbot = require('./jsbot/jsbot'), DatabaseDriver = require('./database').DatabaseDriver; require('./snippets'); var DBot = function() { /*** Load the DB ***/ if(fs.existsSync('db.json')) { try { this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); } catch(err) { console.log('Error loading db.json. Stopping: ' + err); process.exit(); } } else { this.db = {}; } /*** Load the fancy DB ***/ this.ddb = new DatabaseDriver(); this.reloadConfig(); /*** Load main strings ***/ try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); } catch(err) { console.log('Probably a syntax error in strings.json: ' + err); this.strings = {}; } // Initialise run-time resources this.usage = {}; this.status = {}; this.sessionData = {}; // Populate bot properties with config data // Create JSBot and connect to each server this.instance = jsbot.createJSBot(this.config.name); _.each(this.config.servers, function(server, name) { this.instance.addConnection(name, server.server, server.port, this.config.admin, function(event) { var server = this.config.servers[event.server]; for(var i=0;i