Skip to content

Instantly share code, notes, and snippets.

@jnaglick
Last active August 29, 2015 14:01
Show Gist options
  • Save jnaglick/dd0ef280d3c69578c633 to your computer and use it in GitHub Desktop.
Save jnaglick/dd0ef280d3c69578c633 to your computer and use it in GitHub Desktop.
HipChat Bot
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();
}
});
@jnaglick
Copy link
Author

S
K
Y
N
E
T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment