Class: Lita::Adapters::Shell
- Inherits:
-
Lita::Adapter
- Object
- Lita::Adapter
- Lita::Adapters::Shell
- 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
Attributes included from Configurable
Instance Method Summary collapse
-
#initialize(robot) ⇒ Shell
constructor
A new instance of Shell.
-
#roster(room) ⇒ Array<Lita::User>
Returns the users in the room, which is only ever the “Shell User.”.
-
#run ⇒ void
Displays a prompt and requests input in a loop, passing the incoming messages to the robot.
-
#send_messages(_target, strings) ⇒ void
Outputs outgoing messages to the shell.
-
#shut_down ⇒ void
Adds a blank line for a nice looking exit.
Methods inherited from Lita::Adapter
#chat_service, #config, #join, #log, #mention_format, #part, require_config, #set_topic, t, translate, #translate
Methods included from Namespace
Methods included from Configurable
Constructor Details
#initialize(robot) ⇒ 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.”
20 21 22 |
# File 'lib/lita/adapters/shell.rb', line 20 def roster(room) [user] end |
#run ⇒ void
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.
42 43 44 45 46 47 48 49 |
# File 'lib/lita/adapters/shell.rb', line 42 def (_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_down ⇒ void
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 |