Sha256: c0f944d0a8c1503fee65142ac88e7d05e27c42d9220eda2b729f6689f0917eb2

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Lita
  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)
        puts 'Type "exit" or "quit" to end the session.'

        loop do
          print "#{robot.name} > "
          input = $stdin.gets.chomp.strip
          break if input == "exit" || input == "quit"
          message = Message.new(robot, input, source)
          message.command! if Lita.config.adapter.private_chat
          robot.receive(message)
        end
      end

      # Outputs outgoing messages to the shell.
      # @param target [Lita::Source] Unused, since there is only one user in the
      #   shell environment.
      # @param strings [Array<String>] An array of strings to output.
      # @return [void]
      def send_messages(target, strings)
        puts strings
      end

      # Adds a blank line for a nice looking exit.
      # @return [void]
      def shut_down
        puts
      end
    end

    Lita.register_adapter(:shell, Shell)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lita-2.2.0 lib/lita/adapters/shell.rb
lita-2.1.2 lib/lita/adapters/shell.rb
lita-2.1.1 lib/lita/adapters/shell.rb
lita-2.1.0 lib/lita/adapters/shell.rb
lita-2.0.0 lib/lita/adapters/shell.rb