Sha256: c4bdc1822786d685f42057a44ba2fe020a96f2a5920ed88e1b7879058c7fc7fb

Contents?: true

Size: 903 Bytes

Versions: 5

Compression:

Stored size: 903 Bytes

Contents

require "forwardable"

module Boty
  class DSL
    include Boty::Logger

    INSTANCES = {}
    private_constant :INSTANCES
    class << self
      alias_method :original_constructor, :new
    end

    attr_accessor :bot

    extend Forwardable
    def_delegators :bot,
                   :desc, :respond, :name, :brain, :know_how, :im, :say, :match
    def_delegators :message, :user, :channel

    def self.new(bot)
      INSTANCES[bot] ||= original_constructor bot
    end

    def initialize(bot)
      @bot = bot
    end

    def message
      @bot.trigger_message
    end

    def message_from_me?
      message.from? @bot
    end

    def hear(*args, &block)
      match(*args, &block)
    end

    def command(*args, &block)
      respond(*args, &block)
    end

    def match_im(*args, &block)
      command(*args, &block)
    end

    def http
      @http ||= Boty::HTTP.new
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boty-1.0.1 lib/boty/dsl.rb
boty-1.0.0 lib/boty/dsl.rb
boty-0.2.0 lib/boty/dsl.rb
boty-0.1.2 lib/boty/dsl.rb
boty-0.1.1 lib/boty/dsl.rb