Sha256: 6bb0ed82be7f00749295f480447e2693b26525452d425eaf5614958a319ccaba

Contents?: true

Size: 736 Bytes

Versions: 1

Compression:

Stored size: 736 Bytes

Contents

class ProtonBot::Hook
  def cooldown!(seconds, verbose = true)
    self.extra[:cooldown_seconds] = seconds
    self.extra[:cooldown_verbose] = verbose
    self.chain << proc do |dat, hook|
      if dat[:bot].plugins['core'].getpermsr(dat[:plug], dat[:host]).include? 'nocooldown'
        true
      elsif hook.extra[:last_used]
        curtime = Time.now.to_i
        cmp = hook.extra[:last_used] - curtime + hook.extra[:cooldown_seconds]
        if (cmp) <= 0
          hook.extra[:last_used] = curtime
          true
        else
          dat.nreply("You need to wait %B#{cmp}%N more seconds to use this!")
          false
        end
      else
        hook.extra[:last_used] = Time.now.to_i
        true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
protonbot-0.2.4 lib/protonbot/core_plugin/apis/cooldowns.rb