Last active
October 20, 2015 10:51
-
-
Save jhartikainen/658ec8c27892bf09304c to your computer and use it in GitHub Desktop.
Slack JavaScript REPL bot
This file contains hidden or 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 Slack = require('slack-client'); | |
var vm = require('vm'); | |
var s = new Slack('api key here', true, true); | |
s.on('message', function(msg) { | |
if(msg.type != 'message') { | |
return; | |
} | |
var c = s.getChannelGroupOrDMByID(msg.channel); | |
var t = msg.text; | |
//the bot uses ~ as a trigger when to run JS code | |
if(t[0] != '~') { | |
return; | |
} | |
try { | |
var result = vm.runInThisContext(t.substr(1)); | |
} | |
catch(ex) { | |
result = ex; | |
} | |
console.log('sending %s to %s', result, c.name); | |
c.send('' + result); | |
}); | |
s.on('error', console.log); | |
s.login(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment