Sha256: 0fc67a6b1b0d35152a27fd60391cca66189613b26a0d823b173d12720ac13ad7

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

STARTED = Time.now

class Robut::Presence

  # The Robut::Connection that has all the connection info.
  attr_accessor :connection

  def initialize(connection)
    self.connection = connection
  end

  # Sends the chat message +message+ through +plugins+.
  def handle_message(plugins, time, nick, message)
    # ignore all messages sent by robut. If you really want robut to
    # reply to itself, you can use +fake_message+.
    return if nick == connection.config.nick

    time = Time.now
    return if time < (STARTED + 10)
    plugins.each do |plugin|
      begin
        rsp = plugin.handle(time, nick, message)
        break if rsp == true
      rescue => e
        error = "UH OH! #{plugin.class.name} just crashed!"

        if nick
          reply(error, nick) # Connection#reply
        else
          reply(error)       # Room#reply
        end
        if connection.config.logger
          connection.config.logger.error e
          connection.config.logger.error e.backtrace.join("\n")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sclemmer-robut-0.5.4 lib/robut/presence.rb
sclemmer-robut-0.5.3 lib/robut/presence.rb
sclemmer-robut-0.5.2 lib/robut/presence.rb