lib/lita/robot.rb in lita-4.3.2 vs lib/lita/robot.rb in lita-4.4.0

- old
+ new

@@ -34,19 +34,24 @@ # @since 4.0.0 attr_reader :registry def_delegators :registry, :config, :adapters, :handlers, :hooks + # @!method mention_format(name) + # @see Lita::Adapter#mention_format + # @since 4.4.0 + def_delegators :adapter, :mention_format + # @param registry [Lita::Registry] The registry for the robot's configuration and plugins. def initialize(registry = Lita) @registry = registry @name = config.robot.name @mention_name = config.robot.mention_name || @name @alias = config.robot.alias @app = RackApp.build(self) @auth = Authorization.new(config) - trigger(:loaded) + trigger(:loaded, room_ids: persisted_rooms) end # The primary entry point from the adapter for an incoming message. # Dispatches the message to all registered handlers. # @param message [Lita::Message] The incoming message. @@ -74,18 +79,20 @@ # 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) + Lita.redis.sadd("persisted_rooms", 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) + Lita.redis.srem("persisted_rooms", 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 @@ -168,9 +175,14 @@ Lita.logger.fatal I18n.t("lita.robot.unknown_adapter", adapter: adapter_name) abort end adapter_class.new(self) + end + + # A list of room IDs the robot should join. + def persisted_rooms + Lita.redis.smembers("persisted_rooms").sort end # Starts the web server. def run_app http_config = config.http