Class: Lita::Adapters::Shell

Inherits:
Lita::Adapter show all
Defined in:
lib/lita/adapters/shell.rb

Overview

An adapter that runs Lita in a UNIX shell.

Constant Summary

Constants inherited from Lita::Adapter

Lita::Adapter::REQUIRED_METHODS

Instance Attribute Summary

Attributes inherited from Lita::Adapter

#robot

Attributes included from Configurable

#configuration_builder

Instance Method Summary collapse

Methods inherited from Lita::Adapter

#chat_service, #config, #join, #log, #mention_format, #part, require_config, #set_topic, t, translate, #translate

Methods included from Namespace

#namespace

Methods included from Configurable

#config, #inherited

Constructor Details

#initialize(robot) ⇒ Shell

Returns a new instance of Shell.



8
9
10
11
12
# File 'lib/lita/adapters/shell.rb', line 8

def initialize(robot)
  super

  self.user = User.create(1, name: "Shell User")
end

Instance Method Details

#roster(room) ⇒ Array<Lita::User>

Returns the users in the room, which is only ever the “Shell User.”

Parameters:

  • room (Lita::Room)

    The room to return a roster for. Not used in this adapter.

Returns:

Since:

  • 4.4.0



20
21
22
# File 'lib/lita/adapters/shell.rb', line 20

def roster(room)
  [user]
end

#runvoid

This method returns an undefined value.

Displays a prompt and requests input in a loop, passing the incoming messages to the robot.



28
29
30
31
32
33
34
35
# File 'lib/lita/adapters/shell.rb', line 28

def run
  room = robot.config.adapters.shell.private_chat ? nil : "shell"
  @source = Source.new(user: user, room: room)
  puts t("startup_message")
  robot.trigger(:connected)

  run_loop
end

#send_messages(_target, strings) ⇒ void

This method returns an undefined value.

Outputs outgoing messages to the shell.

Parameters:

  • _target (Lita::Source)

    Unused, since there is only one user in the shell environment.

  • strings (Array<String>)

    An array of strings to output.



42
43
44
45
46
47
48
49
# File 'lib/lita/adapters/shell.rb', line 42

def send_messages(_target, strings)
  strings = Array(strings)
  strings.reject!(&:empty?)
  unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ || !$stdout.tty?
    strings.map! { |string| "\e[32m#{string}\e[0m" }
  end
  puts strings
end

#shut_downvoid

This method returns an undefined value.

Adds a blank line for a nice looking exit.



53
54
55
# File 'lib/lita/adapters/shell.rb', line 53

def shut_down
  puts
end