3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00
dbot/run.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2011-08-16 18:41:29 +02:00
var fs = require('fs');
var jsbot = require('./jsbot');
var quote = require('./quotes');
var userCommands = require('./user');
var adminCommands = require('./admin');
var puns = require('./puns');
2011-08-22 20:24:23 +02:00
var kick = require('./kick');
var reality = require('./reality');
var karma = require('./karma');
2011-08-16 18:41:29 +02:00
///////////////////////////
Array.prototype.random = function() {
return this[Math.floor((Math.random()*this.length))];
2011-08-16 19:05:43 +02:00
};
2011-08-16 18:41:29 +02:00
///////////////////////////
2011-08-22 20:24:23 +02:00
var dbot = Class.create({
initialize: function(dModules, quotes) {
this.admin = 'reality';
this.waitingForKarma = false;
this.name = 'depressionbot';
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
this.quotes = quotes.fetch(this);
this.instance = jsbot.createJSBot(this.name, 'elara.ivixor.net', 6667, this, function() {
this.instance.join('#realitest');
}.bind(this));
this.modules = dModules.collect(function(n) {
var module = n.fetch(this);
this.instance.addListener(module.on, module.listener);
return n.fetch(this);
}.bind(this));
this.instance.connect();
},
say: function(channel, data) {
this.instance.say(channel, data);
},
save: function() {
fs.writeFile('db.json', JSON.stringify(this.db, null, ' '));
}
});
2011-08-22 20:24:23 +02:00
new dbot([userCommands, adminCommands, puns, kick, reality, karma], quote);