lib/lita/adapters/shell.rb in lita-2.7.2 vs lib/lita/adapters/shell.rb in lita-3.0.0

- old
+ new

@@ -1,29 +1,20 @@ module Lita + # A namespace to hold all subclasses of {Adapter}. module Adapters # An adapter that runs Lita in a UNIX shell. class Shell < Adapter # Creates a "Shell User" and then loops a prompt and input, passing the # incoming messages to the robot. # @return [void] def run user = User.create(1, name: "Shell User") - source = Source.new(user: user) - puts 'Type "exit" or "quit" to end the session.' + @source = Source.new(user: user) + puts t("startup_message") robot.trigger(:connected) - loop do - print "#{robot.name} > " - input = $stdin.gets - if input.nil? - puts - break - end - input = input.chomp.strip - break if input == "exit" || input == "quit" - robot.receive(build_message(input, source)) - end + run_loop end # Outputs outgoing messages to the shell. # @param target [Lita::Source] Unused, since there is only one user in the # shell environment. @@ -48,9 +39,23 @@ def build_message(input, source) message = Message.new(robot, input, source) message.command! if Lita.config.adapter.private_chat message + end + + def run_loop + loop do + print "#{robot.name} > " + input = $stdin.gets + if input.nil? + puts + break + end + input = input.chomp.strip + break if input == "exit" || input == "quit" + robot.receive(build_message(input, @source)) + end end end Lita.register_adapter(:shell, Shell) end