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-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
|
|
|
var 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.');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'say': function(data, params) {
|
|
|
|
var c = params[1];
|
|
|
|
var m = params.slice(2).join(' ');
|
|
|
|
instance.say(c, m);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var userCommands = {
|
|
|
|
'~kc': function(data, params) {
|
|
|
|
instance.say('aisbot', '.karma ' + data.message.split(' ')[1]);
|
|
|
|
waitingForKarma = data.channel;
|
|
|
|
},
|
|
|
|
|
|
|
|
'~q': function(data, params) {
|
2011-08-19 12:43:56 +02:00
|
|
|
var q = data.message.match(/~q ([\d\w\s]*)/)
|
|
|
|
if(q != undefined) {
|
2011-08-21 16:55:36 +02:00
|
|
|
instance.say(data.channel, quotes.get(q[1].trim()));
|
2011-08-18 19:03:00 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~qadd': function(data, params) {
|
2011-08-21 16:55:36 +02:00
|
|
|
var q = data.message.match(/~qadd ([\d\w\s]*)=(.+)$/);
|
|
|
|
if(q != null && q.length >= 3) {
|
|
|
|
instance.say(data.channel, quotes.add(q));
|
2011-08-18 19:03:00 +02:00
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
|
|
|
} else {
|
|
|
|
instance.say(data.channel, 'Burn the invalid syntax!');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-21 16:55:36 +02:00
|
|
|
'~qset': function(data, params) {
|
|
|
|
var q = data.message.match(/~qset ([\d\w\s]*)=(.+)$/);
|
|
|
|
if(q != undefined && q.length >= 3) {
|
|
|
|
instance.say(data.channel, quotes.set(q));
|
2011-08-18 19:03:00 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-21 16:55:36 +02:00
|
|
|
'~qcount': function(data, params) {
|
|
|
|
var q = data.message.match(/~qcount ([\d\w\s]*)/)[1].trim();
|
|
|
|
if(q != undefined) {
|
|
|
|
instance.say(data.channel, quotes.count(q));
|
|
|
|
}
|
2011-08-18 19:03:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~reality': function(data, params) {
|
|
|
|
instance.say(data.channel, db.realiPuns.random());
|
|
|
|
},
|
|
|
|
|
|
|
|
'~d': function(data, params) {
|
|
|
|
instance.say(data.channel, data.user + ': ' + db.quoteArrs['depressionbot'].random());
|
|
|
|
},
|
|
|
|
|
|
|
|
'~rq': function(data, params) {
|
2011-08-21 16:55:36 +02:00
|
|
|
instance.say(data.channel, quotes.random());
|
2011-08-18 19:03:00 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
'~kickcount': function(data, params) {
|
|
|
|
if(db.kicks[params[1]] == undefined) {
|
|
|
|
instance.say(data.channel, params[1] + ' has either never been kicked or does not exist.');
|
|
|
|
} else {
|
|
|
|
instance.say(data.channel, params[1] + ' has been kicked ' + db.kicks[params[1]] + ' times.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
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() {
|
2011-08-21 16:55:36 +02:00
|
|
|
instance.join('#realitest');
|
2011-08-16 18:41:29 +02:00
|
|
|
}.bind(this));
|
|
|
|
|
2011-08-21 16:55:36 +02:00
|
|
|
var quotes = function(quotes) {
|
|
|
|
var qArrs = quotes;
|
|
|
|
|
|
|
|
return {
|
|
|
|
get: function(key) {
|
|
|
|
if(quotes.hasOwnProperty(key)) {
|
|
|
|
return key + ': ' + qArrs[key].random();
|
|
|
|
} else {
|
|
|
|
return 'No quotes under ' + key;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
count: function(key) {
|
|
|
|
if(quotes.hasOwnProperty(key)) {
|
|
|
|
return key + ' has ' + quotes[key].length + ' quotes.';
|
|
|
|
} else {
|
|
|
|
return 'No quotes under ' + key;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function(key) {
|
|
|
|
if(!Object.isArray(quotes[key[1]])) {
|
|
|
|
quotes[key[1]] = [];
|
|
|
|
}
|
|
|
|
quotes[key[1]].push(key[2]);
|
|
|
|
return 'Quote saved in \'' + key[1] + '\' (' + db.quoteArrs[key[1]].length + ')';
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(key) {
|
|
|
|
if(!quotes.hasOwnProperty(key[1]) || (quotes.hasOwnProperty(key[1]) && quotes[key[1]].length == 1)) {
|
|
|
|
quotes[key[1]] = [key[2]];
|
|
|
|
return 'Quote saved as ' + key[1];
|
|
|
|
} else {
|
|
|
|
return 'No replacing arrays, you whore.';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
random: function() {
|
|
|
|
var rQuote = Object.keys(quotes).random();
|
|
|
|
return rQuote + ': ' + quotes[rQuote].random();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}(db.quoteArrs);
|
|
|
|
|
2011-08-16 18:41:29 +02:00
|
|
|
instance.addListener('JOIN', function(data) {
|
2011-08-16 19:05:43 +02:00
|
|
|
if(data.user == 'Lamp') {
|
2011-08-18 19:03:00 +02:00
|
|
|
instance.say(data.channel, db.quoteArrs.lamp.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-18 19:03:00 +02:00
|
|
|
db.kicks[name] += 1;
|
2011-08-16 18:41:29 +02:00
|
|
|
} else {
|
2011-08-18 19:03:00 +02:00
|
|
|
if(db.kicks[data.kickee] == undefined) {
|
|
|
|
db.kicks[data.kickee] = 1;
|
|
|
|
} else {
|
|
|
|
db.kicks[data.kickee] += 1;
|
|
|
|
}
|
|
|
|
instance.say(data.channel, data.kickee + '-- (' + data.kickee + ' has been kicked ' + db.kicks[data.kickee] + ' times)');
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
2011-08-18 19:03:00 +02:00
|
|
|
fs.writeFile('db.json', JSON.stringify(db, null, ' '));
|
2011-08-16 18:41:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
instance.addListener('PRIVMSG', function(data) {
|
2011-08-18 19:03:00 +02:00
|
|
|
if(data.user == 'aisbot' && data.channel == name && waitingForKarma != false && data.message.match(/is at/)) {
|
2011-08-16 19:05:43 +02:00
|
|
|
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-18 19:03:00 +02:00
|
|
|
params = data.message.split(' ');
|
|
|
|
if(data.user == admin && data.channel == name && adminCommands[params[0]] != undefined) {
|
|
|
|
adminCommands[params[0]](data, params);
|
2011-08-21 16:55:36 +02:00
|
|
|
} else {
|
2011-08-18 19:03:00 +02:00
|
|
|
if(data.channel == name) data.channel = data.user;
|
2011-08-21 16:55:36 +02:00
|
|
|
|
|
|
|
if(userCommands[params[0]] != undefined) {
|
|
|
|
userCommands[params[0]](data, params);
|
|
|
|
} else {
|
|
|
|
var q = data.message.match(/~([\d\w\s]*)/)
|
|
|
|
if(q != undefined) {
|
|
|
|
q = q[1].trim();
|
|
|
|
if(db.quoteArrs[q] != undefined) {
|
|
|
|
instance.say(data.channel, q + ': ' + db.quoteArrs[q].random());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-08-16 18:41:29 +02:00
|
|
|
}
|
|
|
|
});
|
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, ' '));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|