Sha256: 5f67f50c078669d8ef71949eb4de8cea0963590bc11b5e4ffa1fe9c365f6807a

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

class ProtonBot::Plug
  # Emits passed event - calls first matching hook from each plugin
  # @param dat [Hash] Event hash
  # @return [Plug] self
  def emit(dat = {})
    bot.plugins.each do |_, p|
      worked = []
      p.hooks.each do |h|
        next unless dat >= h.pattern && !worked.include?(h.object_id) && worked.empty?
        canrun = true
        h.chain.each do |l|
          next unless canrun
          canrun = l.call(dat, h)
        end
        worked << h.object_id
        h.block.call(dat) if canrun
      end
      worked = []
    end
    event_locks.each_with_index do |el, k|
      if dat >= el.pattern
        event_locks.delete_at(k)
        el.unlock
      end
    end
    self
  end

  # Emits passed event in new thread
  # @param dat [Hash] Event hash
  # @return [Plug] self
  def emitt(dat = {})
    d = dat.clone
    Thread.new do
      begin
        emit(d)
      rescue => e
        log_err(e)
      end
    end
    self
  end

  # Creates EventLock with given pattern.
  # @param pattern [Hash]
  # @return [Plug] self
  def wait_for(pattern)
    ProtonBot::EventLock.new(self, pattern)
    self
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
protonbot-0.3.4 lib/protonbot/plug_events.rb
protonbot-0.3.3 lib/protonbot/plug_events.rb
protonbot-0.3.2 lib/protonbot/plug_events.rb
protonbot-0.3.1 lib/protonbot/plug_events.rb
protonbot-0.3.0 lib/protonbot/plug_events.rb
protonbot-0.2.7 lib/protonbot/plug_events.rb
protonbot-0.2.6 lib/protonbot/plug_events.rb
protonbot-0.2.5 lib/protonbot/plug_events.rb
protonbot-0.2.4 lib/protonbot/plug_events.rb
protonbot-0.2.3 lib/protonbot/plug_events.rb
protonbot-0.2.2 lib/protonbot/plug_events.rb
protonbot-0.2.1 lib/protonbot/plug_events.rb
protonbot-0.2.0 lib/protonbot/plug_events.rb
protonbot-0.1.3 lib/protonbot/plug_events.rb
protonbot-0.1.2 lib/protonbot/plug_events.rb
protonbot-0.1.1 lib/protonbot/plug_events.rb
protonbot-0.1.0 lib/protonbot/plug_events.rb