Commit 21236fc
Changed files (3)
lib
lib/del/message.rb
@@ -1,5 +1,6 @@
module Del
class Message
+ PREFIX = "/code"
attr_reader :text, :robot, :source
def initialize(text, robot:, source:)
@@ -12,6 +13,24 @@ module Del
source.reply(robot, message)
end
+ def execute_shell(command)
+ command = Array(command).flatten.join(' ')
+ reply("Okay, I will run #{command}.")
+ success = false
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
+ stdout.each_line do |line|
+ yield line if block_given?
+ reply("#{PREFIX} #{line}")
+ end
+ stderr.each_line do |line|
+ yield line if block_given?
+ reply("#{PREFIX} #{line}")
+ end
+ success = wait_thr.value.success?
+ end
+ success
+ end
+
def to_s
"#{source}: #{text}"
end
lib/del/version.rb
@@ -1,3 +1,3 @@
module Del
- VERSION = "0.1.15"
+ VERSION = "0.1.16"
end
lib/del.rb
@@ -1,5 +1,6 @@
require "json"
require "logger"
+require "open3"
require "socket"
require "xmpp4r"
require "xmpp4r/muc/helper/mucbrowser"