2011-08-16 18:41:29 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
jsbot = require('./jsbot');
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
|
|
|
var admin = 'reality';
|
|
|
|
var waitingForKarma = false;
|
|
|
|
var name = 'depressionbot';
|
|
|
|
var db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));
|
|
|
|
|
|
|
|
var instance = jsbot.createJSBot(name, 'elara.ivixor.net', 6667, function() {
|
|
|
|
instance.join('#42');
|
|
|
|
instance.join('#itonlygetsworse');
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
instance.addListener('JOIN', function(data) {
|
2011-08-16 19:05:43 +02:00
|
|
|
if(data.user == 'Lamp') {
|
|
|
|
instance.say(data.channel, db.lampPuns.random());
|
2011-08-17 18:51:47 +02:00
|
|
|
} else if(data.user == 'reality') {
|
2011-08-17 14:52:01 +02:00
|
|
|
instance.say(data.channel, db.realiPuns.random());
|
2011-08-16 19:05:43 +02:00
|
|
|
} else if(instance.inChannel(data.channel)) {
|
|
|
|
instance.say('aisbot', '.karma ' + data.user);
|
|
|
|
waitingForKarma = data.channel;
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.addListener('KICK', function(data) {
|
2011-08-16 19:05:43 +02:00
|
|
|
if(data.kickee == name) {
|
|
|
|
instance.join(data.channel);
|
2011-08-16 20:59:11 +02:00
|
|
|
instance.say(data.channel, 'Thou shalt not kick ' + name);
|
2011-08-16 18:41:29 +02:00
|
|
|
} else {
|
2011-08-16 19:05:43 +02:00
|
|
|
instance.say(data.channel, data.kickee + '--');
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.addListener('PRIVMSG', function(data) {
|
2011-08-16 19:05:43 +02:00
|
|
|
if(data.user == 'aisbot' && data.channel == name && waitingForKarma != false) {
|
|
|
|
var split = data.message.split(' ');
|
2011-08-16 18:41:29 +02:00
|
|
|
var target = split[0];
|
|
|
|
var karma = split[3];
|
|
|
|
|
|
|
|
if(karma.startsWith('-')) {
|
|
|
|
instance.say(waitingForKarma, target + db.hatedPhrases.random() + ' (' + karma + ')');
|
|
|
|
} else if(karma == '0') {
|
|
|
|
instance.say(waitingForKarma, 'All ' + target + ' knows is that their gut says \'maybe.\' (0)');
|
|
|
|
} else {
|
|
|
|
instance.say(waitingForKarma, target + db.lovedPhrases.random() + ' (' + karma + ')');
|
|
|
|
}
|
|
|
|
|
|
|
|
waitingForKarma = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.addListener('PRIVMSG', function(data) {
|
2011-08-16 19:05:43 +02:00
|
|
|
if(data.user == admin && data.channel == name) {
|
|
|
|
params = data.message.split(' ');
|
2011-08-16 18:41:29 +02:00
|
|
|
switch(params[0]) {
|
|
|
|
case 'join':
|
|
|
|
instance.join(params[1]);
|
2011-08-16 20:59:11 +02:00
|
|
|
instance.say(admin, 'Joined ' + params[1]);
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
|
|
|
case 'part':
|
|
|
|
instance.part(params[1]);
|
2011-08-16 20:59:11 +02:00
|
|
|
instance.say(admin, 'Left ' + params[1]);
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
|
|
|
case 'reload':
|
|
|
|
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.');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'say':
|
|
|
|
var c = params[1];
|
|
|
|
var m = params.slice(2).join(' ');
|
|
|
|
instance.say(c, m);
|
|
|
|
break;
|
2011-08-17 18:51:47 +02:00
|
|
|
case 'add':
|
|
|
|
// not very safe, but you're the admin so suck it
|
|
|
|
var c = params[1];
|
|
|
|
var m = params.slice(2).join(' ');
|
|
|
|
db[c].push(m);
|
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
|
|
|
instance.say(admin, 'Added.');
|
|
|
|
break;
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.addListener('PRIVMSG', function(data) {
|
2011-08-17 18:31:22 +02:00
|
|
|
if(data.channel == name) data.channel = data.user;
|
|
|
|
|
|
|
|
if(data.message.startsWith('~')) {
|
2011-08-16 19:05:43 +02:00
|
|
|
var params = data.message.split(' ');
|
2011-08-16 18:41:29 +02:00
|
|
|
switch(params[0]) {
|
|
|
|
case '~kc':
|
2011-08-16 19:05:43 +02:00
|
|
|
instance.say('aisbot', '.karma ' + data.message.split(' ')[1]);
|
|
|
|
waitingForKarma = data.channel;
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
|
|
|
case '~qset':
|
2011-08-16 19:05:43 +02:00
|
|
|
var qset = data.message.match(/~qset ([\d\w\s]*)=(.+)$/);
|
2011-08-16 18:41:29 +02:00
|
|
|
if(qset != null && qset.length >= 3) {
|
|
|
|
db.quotes[qset[1]] = qset[2];
|
2011-08-16 19:05:43 +02:00
|
|
|
instance.say(data.channel, 'Quote saved as \'' + qset[1] + '\'');
|
2011-08-16 18:41:29 +02:00
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
|
|
|
} else {
|
2011-08-16 19:05:43 +02:00
|
|
|
instance.say(data.channel, 'Burn the invalid syntax!');
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '~q':
|
2011-08-16 19:05:43 +02:00
|
|
|
var q = data.message.match(/~q ([\d\w\s]*)/)[1].trim();
|
|
|
|
instance.say(data.channel, q + ': ' + db.quotes[q]);
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
2011-08-17 18:02:38 +02:00
|
|
|
case '~qa':
|
|
|
|
var q = data.message.match(/~qa ([\d\w\s]*)/)[1].trim();
|
|
|
|
if(db.quoteArrs[q] != undefined) {
|
|
|
|
instance.say(data.channel, q + ': ' + db.quoteArrs[q].random());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '~qadd':
|
|
|
|
var qadd = data.message.match(/~qadd ([\d\w\s]*)=(.+)$/);
|
|
|
|
if(qadd != null && qadd.length >= 3) {
|
|
|
|
if(Object.isArray(db.quoteArrs[qadd[1]])) {
|
|
|
|
db.quoteArrs[qadd[1]].push(qadd[2]);
|
|
|
|
} else {
|
|
|
|
db.quoteArrs[qadd[1]] = [qadd[2]];
|
|
|
|
}
|
|
|
|
instance.say(data.channel, 'Quote saved in \'' + qadd[1] + '\'');
|
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
|
|
|
} else {
|
|
|
|
instance.say(data.channel, 'Burn the invalid syntax!');
|
|
|
|
}
|
|
|
|
break;
|
2011-08-17 18:31:22 +02:00
|
|
|
case '~qcount':
|
|
|
|
var qcount = data.message.match(/~qcount ([\d\w\s]*)/)[1].trim();
|
|
|
|
if(db.quoteArrs[qcount] != undefined) {
|
|
|
|
instance.say(data.channel, qcount + ' has ' + db.quoteArrs[qcount].length + ' quotes.');
|
|
|
|
} else {
|
|
|
|
instance.say(data.channel, qcount + ' doesn\'t exist.');
|
|
|
|
}
|
|
|
|
break;
|
2011-08-16 18:41:29 +02:00
|
|
|
case '~lamp':
|
2011-08-16 19:05:43 +02:00
|
|
|
instance.say(data.channel, db.lampPuns.random());
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
2011-08-17 14:52:01 +02:00
|
|
|
case '~reality':
|
|
|
|
instance.say(data.channel, db.realiPuns.random());
|
|
|
|
break;
|
2011-08-16 18:41:29 +02:00
|
|
|
case '~rq':
|
2011-08-16 20:59:11 +02:00
|
|
|
var rQuote = Object.keys(db.quotes).random();
|
|
|
|
instance.say(data.channel, rQuote + ': ' + db.quotes[rQuote]);
|
2011-08-16 18:41:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-08-17 14:52:01 +02:00
|
|
|
|
|
|
|
instance.addListener('PRIVMSG', function(data) {
|
|
|
|
if(data.user == 'reality') {
|
|
|
|
var once = data.message.match(/I ([\d\w\s]* once.)/);
|
|
|
|
if(once != null) {
|
|
|
|
db.realiPuns.push('reality ' + once[1]);
|
|
|
|
instance.say(data.channel, '\'reality ' + once[1] + '\' saved.');
|
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|