Sha256: 0f520bf97acf067d2792b6922b1292e6be4ca277b2464308b42231c26610ed1b

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

module Lita
  class Robot
    attr_reader :name

    def initialize
      @name = Lita.config.robot.name
      load_adapter
    end

    def receive(message)
      Lita.handlers.each { |handler| handler.dispatch(self, message) }
    end

    def run
      @adapter.run
    rescue Interrupt
      shut_down
    end

    def send_messages(target, *strings)
      @adapter.send_messages(target, strings.flatten)
    end
    alias_method :send_message, :send_messages

    def set_topic(target, topic)
      @adapter.set_topic(target, topic)
    end

    def shut_down
      @adapter.shut_down
    end

    private

    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}.")
        abort
      end

      @adapter = adapter_class.new(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-1.0.0 lib/lita/robot.rb