var fs = require('fs'); var timers = require('./timer'); var jsbot = require('./jsbot'); 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 { var rawDB = fs.readFileSync('db.json', 'utf-8'); } catch (e) { 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 = {}; } 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 this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); // Initialise run-time resources this.sessionData = {}; this.timers = timers.create(); // Populate bot properties with config data this.name = this.config.name || 'dbox'; this.admin = this.config.admin || [ 'reality' ]; this.moduleNames = this.config.modules || [ 'ignore', 'admin', 'command', 'dice', 'js', 'kick', 'puns', 'quotes', 'spelling', 'youare' ]; this.language = this.config.language || 'english'; this.webPort = this.config.webPort || 80; // It's the user's responsibility to fill this data structure up properly in // the config file. They can d-d-d-deal with it if they have problems. this.servers = this.config.servers || { 'freenode': { 'server': 'irc.freenode.net', 'port': 6667, 'nickserv': 'nickserv', 'password': 'lolturtles', 'channels': [ '#realitest' ] } }; // Create JSBot and connect to each server this.instance = jsbot.createJSBot(this.name); for(var name in this.servers) { if(this.servers.hasOwnProperty(name)) { var server = this.servers[name]; this.instance.addConnection(name, server.server, server.port, this.admin, function(event) { var server = this.servers[event.server]; for(var i=0;i