Class: Cinch::Plugin::Cooldown

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/plugin/cooldown.rb

Overview

An alteration to the Plugin Module to allow for configurable cooldowns.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(duration, time = Time.now) ⇒ Cooldown

Returns a new instance of Cooldown.



8
9
10
11
12
# File 'lib/cinch/plugin/cooldown.rb', line 8

def initialize(duration, time = Time.now)
  @time = time
  @duration = duration
  @expires_at = @time + @duration
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



6
7
8
# File 'lib/cinch/plugin/cooldown.rb', line 6

def duration
  @duration
end

#expires_atObject

Returns the value of attribute expires_at.



6
7
8
# File 'lib/cinch/plugin/cooldown.rb', line 6

def expires_at
  @expires_at
end

#timeObject

Returns the value of attribute time.



6
7
8
# File 'lib/cinch/plugin/cooldown.rb', line 6

def time
  @time
end

Instance Method Details

#cooled_down?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/cinch/plugin/cooldown.rb', line 25

def cooled_down?
  time_till_expire.zero?
end

#time_till_expireObject



19
20
21
22
23
# File 'lib/cinch/plugin/cooldown.rb', line 19

def time_till_expire
  period = @expires_at - Time.now
  return 0 if period < 0
  period
end

#time_till_expire_in_wordsObject



14
15
16
17
# File 'lib/cinch/plugin/cooldown.rb', line 14

def time_till_expire_in_words
  return 'until right now' if (expires_at - Time.now) < 0
  TimeLord::Period.new(expires_at, Time.now).to_words
end