1 class RemindPlugin < Plugin
2 # read a time in string format, turn it into "seconds from now".
3 # example formats handled are "5 minutes", "2 days", "five hours",
4 # "11:30", "15:45:11", "one day", etc.
6 # Throws:: RunTimeError "invalid time string" on parse failure
7 def timestr_offset(timestr)
8 Utils.parse_time_offset(timestr)
16 @reminders.each_value {|v|
24 def help(plugin, topic="")
25 "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"
27 def add_reminder(who, subject, timestr, repeat=false)
29 period = timestr_offset(timestr)
31 return "couldn't parse that time string (#{timestr}) :("
34 return "that time is in the past! (#{timestr})"
36 if(period < 30 && repeat)
37 return "repeats of less than 30 seconds are forbidden"
39 if(!@reminders.has_key?(who))
40 @reminders[who] = Hash.new
41 elsif(@reminders[who].has_key?(subject))
42 del_reminder(who, subject)
46 @reminders[who][subject] = @bot.timer.add(period) {
47 tstr = (Time.now + period).strftime("%H:%M:%S")
48 @bot.say who, "repeat reminder (next at #{tstr}): #{subject}"
51 @reminders[who][subject] = @bot.timer.add_once(period) {
52 tstr = Time.now.strftime("%H:%M:%S")
53 @bot.say who, "reminder (#{tstr}): #{subject}"
58 def del_reminder(who, subject=nil)
60 if(@reminders.has_key?(who) && @reminders[who].has_key?(subject))
61 @bot.timer.remove(@reminders[who][subject])
62 @reminders[who].delete(subject)
68 if(@reminders.has_key?(who))
69 @reminders[who].each_value {|v|
72 @reminders.delete(who)
80 who = params.has_key?(:who) ? params[:who] : m.sourcenick
81 string = params[:string].to_s
82 debug "in remind, string is: #{string}"
83 if(string =~ /^(.*)\s+in\s+(.*)$/)
86 if(err = add_reminder(who, subject, period))
87 m.reply "incorrect usage: " + err
90 elsif(string =~ /^(.*)\s+every\s+(.*)$/)
93 if(err = add_reminder(who, subject, period, true))
94 m.reply "incorrect usage: " + err
97 elsif(string =~ /^(.*)\s+at\s+(.*)$/)
100 if(err = add_reminder(who, subject, time))
101 m.reply "incorrect usage: " + err
110 def no_more(m, params)
111 who = params.has_key?(:who) ? params[:who] : m.sourcenick
112 deleted = params.has_key?(:string) ?
113 del_reminder(who, params[:string].to_s) : del_reminder(who)
117 m.reply "but I wasn't going to :/"
121 plugin = RemindPlugin.new
123 plugin.default_auth('other', false)
125 plugin.map 'remind me no more', :action => 'no_more'
126 plugin.map 'remind me no more [about] *string', :action => 'no_more'
127 plugin.map 'remind me [about] *string'
128 plugin.map 'remind :who no more', :auth_path => 'other', :action => 'no_more'
129 plugin.map 'remind :who no more [about] *string', :auth_path => 'other', :action => 'no_more'
130 plugin.map 'remind :who [about] *string', :auth_path => 'other'