lib/lita/handlers/eval.rb in lita-eval-0.0.2 vs lib/lita/handlers/eval.rb in lita-eval-0.0.3

- old
+ new

@@ -2,18 +2,20 @@ require 'sicuro' module Lita module Handlers class Eval < Handler - route %r{\Aeval\s(.+)}i, :evaluate, command: true, help: { + route %r{\Aeval\s(.+)}i, :evaluate, command: true, help: { 'eval CODE' => 'Evaluates the given ruby code.' } def evaluate(response) code = response.matches[0][0] - response.reply Sicuro.eval("p(#{code})").to_s.strip - rescue - response.reply 'Sorry, I was unable to evaluate the given code.' + http_response = http.post 'http://eval.so/api/evaluate' do |req| + req.headers['Content-Type'] = 'application/json' + req.body = MultiJson.dump(language: 'ruby', code: "p(#{code})") + end + response.reply MultiJson.load(http_response.body)['stdout'].strip end end Lita.register_handler(Eval) end