Class: Robut::Plugin::Later

Inherits:
Object
  • Object
show all
Includes:
Robut::Plugin
Defined in:
lib/robut/plugin/later.rb

Overview

The Later plugin allows you to send messages/commands to robut based on a time delay. Like so:

@robut in 5 minutes lunch?
@robut in 1 hr echo @justin wake up!

him “lunch?” 5 minutes from now. In the case of the Lunch plugin, he would repond with a lunch suggestion. The Later plugin works with all other plugins as you follow this syntax:

@robut in <number> <mins|hrs|secs> [command]

Where command is the message you want to send to @robut in the future. For the time denominations it also recognizes minute, minutes, hour, hours, second, seconds.

Instance Attribute Summary

Attributes included from Robut::Plugin

#connection, #private_sender, #reply_to

Instance Method Summary collapse

Methods included from Robut::Plugin

#at_nick, #fake_message, included, #initialize, #nick, #reply, #sent_to_me?, #store, #without_nick, #words

Instance Method Details

#handle(time, sender_nick, message) ⇒ Object

Passes message back through the plugin chain if we’ve been given a time to execute it later.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/robut/plugin/later.rb', line 28

def handle(time, sender_nick, message)
  if sent_to_me?(message)
    phrase = words(message).join(' ')
    if phrase =~ timer_regex
      count = $1.to_i
      scale = $2
      future_message =  at_nick + ' ' + $3

      sleep_time = count * scale_multiplier(scale)

      if sleep_time >= 21_600
        reply "Too far into the future--ain't no body got (timeforthat)"
        return
      end

      reply("Ok, see you in #{count} #{scale}")
      connection = self.connection
      threader do
        sleep sleep_time
        fake_message(Time.now, sender_nick, future_message)
      end
      return true
    end
  end
end

#usageObject

Returns a description of how to use this plugin



22
23
24
# File 'lib/robut/plugin/later.rb', line 22

def usage
  "#{at_nick} in <number> <mins|hrs|secs> <command> - sends <command> to #{nick} after the specified interval"
end