Last active
August 29, 2015 14:01
-
-
Save jnaglick/dd0ef280d3c69578c633 to your computer and use it in GitHub Desktop.
HipChat Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var userCmds = { | |
'make me a sandwich': {'type': 'say', action: 'make your own stupid sandwich!'} | |
}; | |
botFunction = function() { | |
var m = $('.msgText').last().text(); | |
var msg = null | |
if (userCmds[m]) { | |
if (userCmds[m]['type'] == 'say') { | |
msg = userCmds[m]['action']; | |
} else { | |
msg = eval(userCmds[m]['action']); | |
} | |
} else { | |
var matchies = new RegExp('on .+ (do|say) .+').exec(m) | |
if (matchies) { | |
var newCmd = matchies[0].split(' ')[1]; | |
var doOrSay = matchies[0].split(' ')[2]; | |
var newAction = matchies[0].split(' ').slice(3).join(' '); | |
console.log('command for new action: ' + newCmd + ' as: ' + newAction); | |
userCmds[newCmd] = {type: doOrSay, action: newAction}; | |
msg = 'i added your stupid command' | |
} | |
} | |
return msg; | |
}; | |
$('.chat_display').bind('DOMSubtreeModified', function() { | |
var user = $('.nameBlock').last().text(); | |
if (user == 'b o t') { | |
return null; | |
} | |
var r = botFunction(); | |
if (r) { | |
$('#message_input').val(r); | |
chat.send_message(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
S
K
Y
N
E
T