Skip to content

Instantly share code, notes, and snippets.

@diracdeltafunk
Last active April 5, 2016 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diracdeltafunk/17a3cde3f1a2a81a2e443f437f1f8049 to your computer and use it in GitHub Desktop.
Save diracdeltafunk/17a3cde3f1a2a81a2e443f437f1f8049 to your computer and use it in GitHub Desktop.
Robin Bot
var l;
var s;
var k;
var i;
var faces = [";)", ":)", ":(", "¯\\_(ツ)_/¯", "( ͡° ͜ʖ ͡°)"];
function type(message) {
$('input.c-form-control.text-counter-input').val("♫ " + message + " ♫");
setTimeout(function() {$('input.c-form-control.text-counter-input').submit()}, 50);
}
function respond() {
l = $('span.robin-message--message:last').text();
if(l == ":?") {
type("Commands are :? :face :roll <number>");
}
if(l.indexOf(":face") != -1) {
type(faces[Math.floor(Math.random() * faces.length)]);
}
if(l.indexOf(":roll") != -1) {
s = l.split(' ');
k = s.indexOf(":roll");
if (k != -1 && k < s.length) {
i = parseInt(s[k+1]);
if (i > 0) {
type("You rolled " + (Math.floor(Math.random() * i) + 1));
}
}
}
}
type("{USERNAME} chat bot initialized! Type :? for help");
$('.robin-chat--message-list').bind('DOMNodeInserted', respond);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment