Sha256: a1468ff131e6f910d64499193433a487ce78feb9942af32d596f71ed6ca194b1

Contents?: true

Size: 1007 Bytes

Versions: 3

Compression:

Stored size: 1007 Bytes

Contents

module Lita
  class Robot
    attr_reader :name
    attr_accessor :mention_name

    def initialize
      @name = Lita.config.robot.name
      @mention_name = Lita.config.robot.mention_name || @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

3 entries across 3 versions & 1 rubygems

Version Path
lita-1.1.2 lib/lita/robot.rb
lita-1.1.1 lib/lita/robot.rb
lita-1.1.0 lib/lita/robot.rb