Method: Cinch::Helpers#Timer

Defined in:
lib/cinch/helpers.rb

#Timer(interval, options = {}, &block) ⇒ Timer

Examples:

Used as a class method in a plugin

timer 5, method: :some_method
def some_method
  Channel("#cinch-bots").send(Time.now.to_s)
end

Used as an instance method in a plugin

match "start timer"
def execute(m)
  Timer(5) { puts "timer fired" }
end

Used as an instance method in a traditional on handler

on :message, "start timer" do
  Timer(5) { puts "timer fired" }
end

Parameters:

  • interval (Numeric)

    Interval in seconds

  • block (Proc)

    A proc to execute

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :method (Symbol) — default: :timer

    Method to call (only if no proc is provided)

  • :threaded (Boolean) — default: true

    Call method in a thread?

  • :shots (Integer) — default: Float::INFINITY

    How often should the timer fire?

  • :start_automatically (Boolean) — default: true

    If true, the timer will automatically start after the bot finished connecting.

  • :stop_automaticall (Boolean) — default: true

    If true, the timer will automatically stop when the bot disconnects.

Returns:

Since:

  • 2.0.0



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cinch/helpers.rb', line 93

def Timer(interval, options = {}, &block)
  options = {:method => :timer, :threaded => true, :interval => interval}.merge(options)
  block ||= self.method(options[:method])
  timer   = Cinch::Timer.new(bot, options, &block)
  timer.start

  if self.respond_to?(:timers)
    timers << timer
  end

  timer
end