lib/lita/adapters/shell.rb in lita-4.3.2 vs lib/lita/adapters/shell.rb in lita-4.4.0
- old
+ new
@@ -3,15 +3,31 @@
module Adapters
# An adapter that runs Lita in a UNIX shell.
class Shell < Adapter
config :private_chat, default: false
- # Creates a "Shell User" and then loops a prompt and input, passing the
- # incoming messages to the robot.
+ def initialize(robot)
+ super
+
+ self.user = User.create(1, name: "Shell User")
+ end
+
+ # rubocop:disable Lint/UnusedMethodArgument
+
+ # Returns the users in the room, which is only ever the "Shell User."
+ # @param room [Lita::Room] The room to return a roster for. Not used in this adapter.
+ # @return [Array<Lita::User>] The users in the room.
+ # @since 4.4.0
+ def roster(room)
+ [user]
+ end
+
+ # rubocop:enable Lint/UnusedMethodArgument
+
+ # Displays a prompt and requests input in a loop, passing the incoming messages to the robot.
# @return [void]
def run
- user = User.create(1, name: "Shell User")
room = robot.config.adapters.shell.private_chat ? nil : "shell"
@source = Source.new(user: user, room: room)
puts t("startup_message")
robot.trigger(:connected)
@@ -37,9 +53,11 @@
def shut_down
puts
end
private
+
+ attr_accessor :user
def build_message(input, source)
message = Message.new(robot, input, source)
message.command! if robot.config.adapters.shell.private_chat
message