lib/lita/robot.rb in lita-2.7.2 vs lib/lita/robot.rb in lita-3.0.0
- old
+ new
@@ -24,11 +24,11 @@
def initialize
@name = Lita.config.robot.name
@mention_name = Lita.config.robot.mention_name || @name
@alias = Lita.config.robot.alias
- @app = RackApp.new(self).to_app
+ @app = RackApp.new(self)
load_adapter
trigger(:loaded)
end
# The primary entry point from the adapter for an incoming message.
@@ -47,10 +47,26 @@
@adapter.run
rescue Interrupt
shut_down
end
+ # Makes the robot join a room with the specified ID.
+ # @param room_id [String] The ID of the room.
+ # @return [void]
+ # @since 3.0.0
+ def join(room_id)
+ @adapter.join(room_id)
+ end
+
+ # Makes the robot part from the room with the specified ID.
+ # @param room_id [String] The ID of the room.
+ # @return [void]
+ # @since 3.0.0
+ def part(room_id)
+ @adapter.part(room_id)
+ end
+
# Sends one or more messages to a user or room.
# @param target [Lita::Source] The user or room to send to. If the Source
# has a room, it will choose the room. Otherwise, it will send to the
# user.
# @param strings [String, Array<String>] One or more strings to send.
@@ -72,11 +88,11 @@
# to the adapter to perform any shut down tasks necessary for the chat
# service.
# @return [void]
def shut_down
trigger(:shut_down_started)
- @server.stop if @server
+ @server.stop(true) if @server
@server_thread.join if @server_thread
@adapter.shut_down
trigger(:shut_down_complete)
end
@@ -98,26 +114,26 @@
def load_adapter
adapter_name = Lita.config.robot.adapter
adapter_class = Lita.adapters[adapter_name.to_sym]
unless adapter_class
- Lita.logger.fatal("Unknown adapter: :#{adapter_name}.")
+ Lita.logger.fatal I18n.t("lita.robot.unknown_adapter", adapter: adapter_name)
abort
end
@adapter = adapter_class.new(self)
end
# Starts the web server.
def run_app
+ http_config = Lita.config.http
+
@server_thread = Thread.new do
- @server = Thin::Server.new(
- app,
- Lita.config.http.port.to_i,
- signals: false
- )
- @server.silent = true unless Lita.config.http.debug
- @server.start
+ @server = Puma::Server.new(app)
+ @server.add_tcp_listener(http_config.host, http_config.port.to_i)
+ @server.min_threads = http_config.min_threads
+ @server.max_threads = http_config.max_threads
+ @server.run
end
@server_thread.abort_on_exception = true
end
end