3 class RemindPlugin < Plugin
9 @reminders.each_value {|v|
16 def help(plugin, topic="")
17 if(plugin =~ /^remind\+$/)
18 "see remind. remind+ can be used to remind someone else of something, using <nick> instead of 'me'. However this will generally require a higher auth level than remind."
20 "remind me [about] <message> in <time>, remind me [about] <message> every <time>, remind me [about] <message> at <time>, remind me no more [about] <message>, remind me no more"
23 def add_reminder(who, subject, timestr, repeat=false)
25 period = Irc::Utils.timestr_offset(timestr)
27 return "couldn't parse that time string (#{timestr}) :("
30 return "that time is in the past! (#{timestr})"
32 if(period < 30 && repeat)
33 return "repeats of less than 30 seconds are forbidden"
35 if(!@reminders.has_key?(who))
36 @reminders[who] = Hash.new
37 elsif(@reminders[who].has_key?(subject))
38 del_reminder(who, subject)
42 @reminders[who][subject] = @bot.timer.add(period) {
43 time = Time.now + period
44 tstr = time.strftime("%H:%M:%S")
45 @bot.say who, "repeat reminder (next at #{tstr}): #{subject}"
48 @reminders[who][subject] = @bot.timer.add_once(period) {
49 time = Time.now + period
50 tstr = time.strftime("%H:%M:%S")
51 @bot.say who, "reminder (#{tstr}): #{subject}"
56 def del_reminder(who, subject=nil)
58 if(@reminders.has_key?(who) && @reminders[who].has_key?(subject))
59 @bot.timer.remove(@reminders[who][subject])
60 @reminders[who].delete(subject)
63 if(@reminders.has_key?(who))
64 @reminders[who].each_value {|v|
67 @reminders.delete(who)
73 if(m.params =~ /^(\S+)\s+(?:about\s+)?(.*)\s+in\s+(.*)$/)
80 unless(m.plugin =~ /^remind\+$/)
81 m.reply "incorrect usage: use remind+ to remind persons other than yourself"
85 if(err = add_reminder(who, subject, period))
86 m.reply "incorrect usage: " + err
89 elsif(m.params =~ /^(\S+)\s+(?:about\s+)?(.*)\s+every\s+(.*)$/)
96 unless(m.plugin =~ /^remind\+$/)
97 m.reply "incorrect usage: use remind+ to remind persons other than yourself"
101 if(err = add_reminder(who, subject, period, true))
102 m.reply "incorrect usage: " + err
105 elsif(m.params =~ /^(\S+)\s+(?:about\s+)?(.*)\s+at\s+(.*)$/)
112 unless(m.plugin =~ /^remind\+$/)
113 m.reply "incorrect usage: use remind+ to remind persons other than yourself"
117 if(err = add_reminder(who, subject, time))
118 m.reply "incorrect usage: " + err
121 elsif(m.params =~ /^(\S+)\s+no\s+more\s+(?:about\s+)?(.*)$/)
127 unless(m.plugin =~ /^remind\+$/)
128 m.reply "incorrect usage: use remind+ to remind persons other than yourself"
132 del_reminder(who, subject)
133 elsif(m.params =~ /^(\S+)\s+no\s+more$/)
138 unless(m.plugin =~ /^remind\+$/)
139 m.reply "incorrect usage: use remind+ to remind persons other than yourself"
145 m.reply "incorrect usage: " + help(m.plugin)
151 plugin = RemindPlugin.new
152 plugin.register("remind")
153 plugin.register("remind+")