2011-08-16 18:41:29 +02:00
|
|
|
var fs = require('fs');
|
2011-08-18 19:03:00 +02:00
|
|
|
var jsbot = require('./jsbot');
|
2011-08-22 14:20:06 +02:00
|
|
|
var quote = require('./quotes');
|
2011-08-22 18:54:12 +02:00
|
|
|
var userCommands = require('./user');
|
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-18 19:03:00 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
this.adminCommands = {
|
|
|
|
'join': function(data, params) {
|
|
|
|
instance.join(params[1]);
|
|
|
|
instance.say(admin, 'Joined ' + params[1]);
|
|
|
|
},
|
|
|
|
|
|
|
|
'part': function(data, params) {
|
|
|
|
instance.part(params[1]);
|
|
|
|
instance.say(admin);
|
|
|
|
},
|
|
|
|
|
|
|
|
'reload': function(data, params) {
|
|
|
|
instance.say(admin, 'Reloading DB.');
|
|
|
|
try {
|
|
|
|
db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
|
|
|
} catch(err) {
|
|
|
|
instance.say(admin, 'DB reload failed.');
|
|
|
|
} finally {
|
|
|
|
instance.say(admin, 'DB Reload successful.');
|
|
|
|
}
|
|
|
|
},
|
2011-08-18 19:03:00 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
'say': function(data, params) {
|
|
|
|
var c = params[1];
|
|
|
|
var m = params.slice(2).join(' ');
|
|
|
|
instance.say(c, m);
|
2011-08-22 14:20:06 +02:00
|
|
|
}
|
2011-08-22 18:54:12 +02:00
|
|
|
};
|
2011-08-21 16:55:36 +02:00
|
|
|
|
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
///////////////////////////
|
|
|
|
var dbot = Class.create({
|
|
|
|
initialize: function(quotes, userCommands) {
|
|
|
|
this.admin = 'reality';
|
|
|
|
this.waitingForKarma = false;
|
|
|
|
this.name = 'depressionbot';
|
|
|
|
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
|
|
|
this.quotes = quotes(this.db.quoteArrs);
|
|
|
|
this.userCommands = userCommands.fetch(this);
|
|
|
|
|
|
|
|
this.instance = jsbot.createJSBot(this.name, 'elara.ivixor.net', 6667, this, function() {
|
|
|
|
this.instance.join('#realitest');
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
this.instance.addListener(this.userCommands.on, this.userCommands.listener);
|
|
|
|
|
|
|
|
this.instance.addListener('JOIN', function(data) {
|
|
|
|
if(data.user == 'Lamp') {
|
|
|
|
this.instance.say(data.channel, db.quoteArrs.lamp.random());
|
|
|
|
} else if(data.user == 'reality') {
|
|
|
|
this.instance.say(data.channel, db.realiPuns.random());
|
|
|
|
} else if(instance.inChannel(data.channel)) {
|
|
|
|
this.instance.say('aisbot', '.karma ' + data.user);
|
|
|
|
this.waitingForKarma = data.channel;
|
2011-08-21 16:55:36 +02:00
|
|
|
}
|
2011-08-22 18:54:12 +02:00
|
|
|
});
|
2011-08-22 14:20:06 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
this.instance.addListener('KICK', function(data) {
|
|
|
|
if(data.kickee == name) {
|
|
|
|
this.instance.join(data.channel);
|
|
|
|
this.instance.say(data.channel, 'Thou shalt not kick ' + name);
|
|
|
|
this.db.kicks[name] += 1;
|
2011-08-22 14:20:06 +02:00
|
|
|
} else {
|
2011-08-22 18:54:12 +02:00
|
|
|
if(this.db.kicks[data.kickee] == undefined) {
|
|
|
|
this.db.kicks[data.kickee] = 1;
|
|
|
|
} else {
|
|
|
|
this.db.kicks[data.kickee] += 1;
|
|
|
|
}
|
|
|
|
instance.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + this.db.kicks[data.kickee] + ' times)');
|
2011-08-22 14:20:06 +02:00
|
|
|
}
|
2011-08-16 18:41:29 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
this.save();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.instance.addListener('PRIVMSG', function(data) {
|
|
|
|
if(data.user == 'aisbot' && data.channel == name && waitingForKarma != false && data.message.match(/is at/)) {
|
|
|
|
var split = data.message.split(' ');
|
|
|
|
var target = split[0];
|
|
|
|
var karma = split[3];
|
|
|
|
|
|
|
|
if(karma.startsWith('-')) {
|
|
|
|
this.instance.say(waitingForKarma, target + this.db.hatedPhrases.random() + ' (' + karma + ')');
|
|
|
|
} else if(karma == '0') {
|
|
|
|
this.instance.say(waitingForKarma, target + this.db.neutralPhrases.random() + ' (0)');
|
|
|
|
} else {
|
|
|
|
this.instance.say(waitingForKarma, target + this.db.lovedPhrases.random() + ' (' + karma + ')');
|
2011-08-22 14:20:06 +02:00
|
|
|
}
|
2011-08-22 18:54:12 +02:00
|
|
|
|
|
|
|
waitingForKarma = false;
|
2011-08-22 14:20:06 +02:00
|
|
|
}
|
2011-08-22 18:54:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.instance.addListener('PRIVMSG', function(data) {
|
|
|
|
if(data.user == 'reality') {
|
|
|
|
var once = data.message.match(/I ([\d\w\s]* once.)/);
|
|
|
|
if(once != null) {
|
|
|
|
this.db.realiPuns.push('reality ' + once[1]);
|
|
|
|
this.instance.say(data.channel, '\'reality ' + once[1] + '\' saved.');
|
|
|
|
this.save();
|
|
|
|
}
|
2011-08-22 14:20:06 +02:00
|
|
|
}
|
2011-08-22 18:54:12 +02:00
|
|
|
});
|
|
|
|
},
|
2011-08-22 14:20:06 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
say: function(channel, data) {
|
|
|
|
this.instance.say(channel, data);
|
|
|
|
},
|
2011-08-22 14:20:06 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
save: function() {
|
|
|
|
fs.writeFile('db.json', JSON.stringify(this.db, null, ' '));
|
|
|
|
}
|
|
|
|
});
|
2011-08-22 14:20:06 +02:00
|
|
|
|
2011-08-22 18:54:12 +02:00
|
|
|
new dbot(quote.fetch(), userCommands);
|