Class: Ruboty::Handlers::Evaluate

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/handlers/evaluate.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(message) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruboty/handlers/evaluate.rb', line 8

def evaluate(message)
  thread = Thread.start do
    stdout, stderr, status = Open3.capture3(message[:command])
    message.reply(stdout.chomp) if stdout
    message.reply(stderr.chomp) if stderr

    unless status.success?
      message.reply("Command Failed:\n#{message[:command]}", code: true)
    end
  end
  Thread.start do
    sleep 10
    thread.kill
  end
end