Sha256: f9f22adf200e778637b73be61656930609903314b6320c5e66f6e34e17bc5ba9

Contents?: true

Size: 638 Bytes

Versions: 1

Compression:

Stored size: 638 Bytes

Contents

require 'lita'
require 'sicuro'

module Lita
  module Handlers
    class Eval < Handler
      route %r{\Aeval\s(.+)}i, :evaluate, command: true, help: {
        'eval CODE' => 'Evaluates the given ruby code.'
      }

      def evaluate(response)
        code = response.matches[0][0]
        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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-eval-0.0.3 lib/lita/handlers/eval.rb