Sha256: d4a3fe4c968c1349c3b8ff4e20b4508a352a4861037cf9eab8ad981d397b1553

Contents?: true

Size: 775 Bytes

Versions: 2

Compression:

Stored size: 775 Bytes

Contents

module Hipbot
  class Response < Struct.new(:reaction, :message)
    include Helpers

    delegate :sender, :recipients, :body, :room, :to => :message
    delegate :bot, :to => Hipbot

    def invoke arguments
      Hipbot.logger.info("REACTION #{reaction.inspect}")
      instance_exec(*arguments, &reaction.block)
      true
    rescue Exception => e
      Hipbot.logger.error(e)
      instance_exec(e, &Hipbot.error_handler)
      false
    end

    protected

    def reply message, room = self.room
      room.nil? ? Hipbot.send_to_user(sender, message) : Hipbot.send_to_room(room, message)
    end

    def method_missing method, *args, &block
      plugin.send(method, *args, &block)
    end

    def plugin
      reaction.plugin.with_response(self)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hipbot-1.0.0.rc2 lib/hipbot/response.rb
hipbot-1.0.0.rc1 lib/hipbot/response.rb