lib/robut/plugin/later.rb in robut-0.2.1 vs lib/robut/plugin/later.rb in robut-0.3.0

- old
+ new

@@ -10,35 +10,39 @@ # 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, +# the time denominations it also recognizes minute, minutes, hour, hours, # second, seconds. # -class Robut::Plugin::Later < Robut::Plugin::Base +class Robut::Plugin::Later + include Robut::Plugin + # Returns a description of how to use this plugin + def usage + "#{at_nick} in <number> <mins|hrs|secs> <command> - sends <command> to #{nick} after the specified interval" + end + # Passes +message+ back through the plugin chain if we've been given # a time to execute it later. 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) - + reply("Ok, see you in #{count} #{scale}") - + connection = self.connection threader do sleep sleep_time - # TODO: ensure this connection is threadsafe - plugins = Robut::Plugin.plugins.map { |p| p.new(connection, private_sender) } - connection.handle_message(plugins, Time.now, sender_nick, future_message) + fake_message(Time.now, sender_nick, future_message) end return true end end end @@ -67,7 +71,7 @@ def threader Thread.new do yield end end - + end