Sha256: b962b7c5a3df87a955b2a20cdb006a2d442bf265d9a4d6bf81f765201ef762d9

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

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

    delegate :sender, :room, to: :message
    delegate :bot, to: Hipbot

    def initialize *_
      super
      Hipbot.logger.info("RESPONSE WITH #{reaction}")
    end

    def invoke arguments
      handle_errors do
        instance_exec(*arguments, &reaction.block)
      end
    rescue Exception => e
      instance_exec(e, &Hipbot.exception_handler)
    end

    def reply message, room = self.room
      (room || sender).send_message(message)
    end

    protected

    def handle_errors
      error = catch(:error){ yield; false }
      reply(error) if error
    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

1 entries across 1 versions & 1 rubygems

Version Path
hipbot-1.0.4 lib/hipbot/response.rb