]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/remind.rb
remove whitespace
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / remind.rb
index ef9d4be75525b9eecafc9a675519b03bbacec9e1..804e3f0bfd8968003182852d7b8b2f9b8727e6db 100644 (file)
@@ -1,5 +1,3 @@
-require 'rbot/utils'
-
 class RemindPlugin < Plugin
   # read a time in string format, turn it into "seconds from now".
   # example formats handled are "5 minutes", "2 days", "five hours",
@@ -60,18 +58,19 @@ class RemindPlugin < Plugin
           else
             raise "invalid time string"
         end
-      when (/^(\d+):(\d+):(\d+)$/)
+      when (/^(\d+):(\d+)(?:\:(\d+))?$/)
         hour = $1.to_i
         min = $2.to_i
         sec = $3.to_i
         now = Time.now
         later = Time.mktime(now.year, now.month, now.day, hour, min, sec)
-        return later - now
-      when (/^(\d+):(\d+)$/)
-        hour = $1.to_i
-        min = $2.to_i
-        now = Time.now
-        later = Time.mktime(now.year, now.month, now.day, hour, min, now.sec)
+
+        # if the given hour is earlier than current hour, given timestr
+        # must have been meant to be in the future
+        if hour < now.hour || hour <= now.hour && min < now.min
+          later += 60*60*24
+        end
+
         return later - now
       when (/^(\d+):(\d+)(am|pm)$/)
         hour = $1.to_i
@@ -114,6 +113,7 @@ class RemindPlugin < Plugin
       }
     }
     @reminders.clear
+    super
   end
   def help(plugin, topic="")
     "reminder plugin: remind <who> [about] <message> in <time>, remind <who> [about] <message> every <time>, remind <who> [about] <message> at <time>, remind <who> no more [about] <message>, remind <who> no more. Generally <who> should be 'me', but you can remind others (nick or channel) if you have remind_others auth"
@@ -138,14 +138,12 @@ class RemindPlugin < Plugin
 
     if(repeat)
       @reminders[who][subject] = @bot.timer.add(period) {
-        time = Time.now + period
-        tstr = time.strftime("%H:%M:%S")
+        tstr = (Time.now + period).strftime("%H:%M:%S")
         @bot.say who, "repeat reminder (next at #{tstr}): #{subject}"
       }
     else
       @reminders[who][subject] = @bot.timer.add_once(period) {
-        time = Time.now + period
-        tstr = time.strftime("%H:%M:%S")
+        tstr = Time.now.strftime("%H:%M:%S")
         @bot.say who, "reminder (#{tstr}): #{subject}"
       }
     end
@@ -205,24 +203,23 @@ class RemindPlugin < Plugin
   end
   def no_more(m, params)
     who = params.has_key?(:who) ? params[:who] : m.sourcenick
-    deleted = params.has_key?(:string) ? 
+    deleted = params.has_key?(:string) ?
               del_reminder(who, params[:string].to_s) : del_reminder(who)
     if deleted
       m.okay
-    else 
+    else
       m.reply "but I wasn't going to :/"
     end
   end
 end
 plugin = RemindPlugin.new
+
+plugin.default_auth('other', false)
+
 plugin.map 'remind me no more', :action => 'no_more'
-plugin.map 'remind me no more about *string', :action => 'no_more'
-plugin.map 'remind me no more *string', :action => 'no_more'
-plugin.map 'remind me about *string'
-plugin.map 'remind me *string'
-plugin.map 'remind :who no more', :auth => 'remind_other', :action => 'no_more'
-plugin.map 'remind :who no more about *string', :auth => 'remind_other', :action => 'no_more'
-plugin.map 'remind :who no more *string', :auth => 'remind_other', :action => 'no_more'
-plugin.map 'remind :who about *string', :auth => 'remind_other'
-plugin.map 'remind :who *string', :auth => 'remind_other'
+plugin.map 'remind me no more [about] *string', :action => 'no_more'
+plugin.map 'remind me [about] *string'
+plugin.map 'remind :who no more', :auth_path => 'other', :action => 'no_more'
+plugin.map 'remind :who no more [about] *string', :auth_path => 'other', :action => 'no_more'
+plugin.map 'remind :who [about] *string', :auth_path => 'other'