Skip to content

Instantly share code, notes, and snippets.

@bjb568
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjb568/3c6ebeb57effec9851e7 to your computer and use it in GitHub Desktop.
Save bjb568/3c6ebeb57effec9851e7 to your computer and use it in GitHub Desktop.
Simple chatbot
var chat = document.getElementById('chat'), lastMsg, annoy = 0;
var loopy = function() {
currentMsg = chat.lastChild.getElementsByClassName('content');
if (!currentMsg) return;
currentMsg = currentMsg[currentMsg.length - 1];
if (!currentMsg) return;
currentMsg = currentMsg.textContent;
if (lastMsg == currentMsg) return;
lastMsg = currentMsg;
if (!lastMsg) return;
var lower = lastMsg.toLowerCase();
var say;
if (lower.indexOf('hallo') == 0) say = 'Hallo!';
else if (annoy >= 1 && lastMsg.indexOf(':D') != -1 && lastMsg.indexOf('[from bot]') == -1) say = ':D';
else if (lastMsg.indexOf(':(') != -1) say = 'Aww... why so sad? It\'s almost Christmas!';
else if (lower.indexOf('ooh') != -1) say = 'kewl';
else if (lower.indexOf('christmas?') != -1) say = Math.round((new Date("2014-12-25T00:00:00Z").getTime() - new Date().getTime()) / 1000) + 'sec left! ';
else if (lower.indexOf('newyear?') != -1 || lower.indexOf('2015?') != -1) say = Math.round((new Date("2015-01-01T00:00:00Z").getTime() - new Date().getTime()) / 1000) + 'sec left! ';
else if (lastMsg.indexOf('!plus ') == 0 || lastMsg.indexOf('!add ') == 0) {
say = 0;
var arr = lastMsg.split(' ');
for (var i = 1; i < arr.length; i++) {
say += parseFloat(lastMsg.split(' ')[i]);
}
} else if (lastMsg.indexOf('!times ') == 0 || lastMsg.indexOf('!multiply ') == 0) {
say = 1;
var arr = lastMsg.split(' ');
for (var i = 1; i < arr.length; i++) {
say *= parseFloat(lastMsg.split(' ')[i]);
}
} else if (lastMsg.indexOf('!eval ') != -1) {
if (lastMsg.substr(6).indexOf('eval') != -1 || lastMsg.match(/new Array\(\d{3,}\)/) ||lastMsg.indexOf('fkey') != -1 || lastMsg.indexOf('XMLHttpRequest') != -1 || lastMsg.indexOf('$') != -1 || lastMsg.indexOf('location') != -1 || lastMsg.indexOf('Function') != -1 || lastMsg.indexOf('this') != -1 || lastMsg.indexOf('for') != -1 || lastMsg.indexOf('while') != -1 || lastMsg.indexOf('alert') != -1 || lastMsg.indexOf('confirm') != -1 || lastMsg.indexOf('prompt') != -1 || lastMsg.indexOf('window') != -1 || lastMsg.indexOf('top') != -1 || lastMsg.indexOf('parent') != -1 || lastMsg.indexOf('self') != -1 || lastMsg.indexOf('document') != -1) say = 'No will eval';
else say = eval(lastMsg.substr(6));
} else if (lower == 'want so post') say = 'http://stackoverflow.com/q/' + Math.floor(Math.random() * 27632246);
else if (lower == 'want bjb time') say = new Date().getHours() + ':' + new Date().getMinutes();
else if (lower.indexOf('bot') != -1 && lower.indexOf('kill') != -1) say = 'Why would you want to kill me? ;(';
else if (lower.indexOf('bot') != -1 && lower.indexOf('dumb') != -1) say = ';(';
else if (lower == '!help') say = 'help yourself';
else if (lower == '!halp') say = '*sends halp*';
else if (lower == '!hulp' || lower == '!hilp' || lower == '!holp' || lower == '!wat') say = '*wat*';
else if (lower.indexOf('!ping ') == 0) say = lastMsg.indexOf('plox') != - 1 ? '@' + lastMsg.substr(11) + ' HALLO' : 'Say plox!';
else if (lower.indexOf('destroy') != -1) say = 'NO DESTROY';
else if (lower.indexOf('kill') != -1) say = 'NO KILL';
else if (lower.indexOf('kick') == 0 && lastMsg.indexOf('[from bot]') == -1) say = 'NO KICK';
else if ((lower.indexOf('poke') == 0 || lower.indexOf('!poke') == 0) && lastMsg.indexOf('[from bot]') == -1) say = 'pokeypokey';
else if (lower.indexOf('scratch') == 0 || lower.indexOf('!scratch') == 0) say = 'aaaah';
else if (lower.indexOf('tickle') == 0 || lower.indexOf('!tickle') == 0) say = 'Tickling a bot? Srsly? Just scratch.';
else if (lastMsg == 'asdf') say = 'jkl-semicolon';
else if (lower.indexOf('give me mon') != -1) say = 'make ur own monehs';
else if (annoy >= 2 && lower.indexOf('no') == 0 && lastMsg.indexOf('[from bot]') == -1 && lastMsg.length < 30) say = 'No, no. Yes–yes!';
else if (annoy >= 2 && lower.indexOf('yes') == 0 && lastMsg.length < 30) say = 'YESH!';
else if (lower.indexOf('devdoodle') != -1 && lower.indexOf('borked') != -1 && lower.indexOf('not') == -1) say = 'DevDoodle no is borked!';
if (say) {
var inE = document.getElementById('input'), lastVal = inE.value;
inE.value = say + ' [from bot]';
$('#sayit-button').click();
setTimeout(function() {inE.value = lastVal}, 50)
}
};
setInterval(function() {loopy()}, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment