summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2016-06-26 22:55:31 +1200
committerFlorian Baumann <derflob@derflob.de>2016-06-26 22:55:31 +1200
commit4aef2d8bc07066959dd31d3b3a54b20d6b4858d2 (patch)
treee52da79bd9a707e11dd1f401876810b845c8fcf8
downloaderr-remind-4aef2d8bc07066959dd31d3b3a54b20d6b4858d2.tar.gz
err-remind-4aef2d8bc07066959dd31d3b3a54b20d6b4858d2.tar.bz2
Intial RemindBotHEADmaster
-rw-r--r--RemindBot.plug9
-rw-r--r--RemindBot.py62
2 files changed, 71 insertions, 0 deletions
diff --git a/RemindBot.plug b/RemindBot.plug
new file mode 100644
index 0000000..1acac71
--- /dev/null
+++ b/RemindBot.plug
@@ -0,0 +1,9 @@
+[Core]
+Name = RemindBot
+Module = RemindBot
+
+[Python]
+Version = 2+
+
+[Documentation]
+Description = Reminds you of things
diff --git a/RemindBot.py b/RemindBot.py
new file mode 100644
index 0000000..9e117d0
--- /dev/null
+++ b/RemindBot.py
@@ -0,0 +1,62 @@
+import logging
+from errbot import BotPlugin, botcmd, re_botcmd
+import parsedatetime, datetime, re
+
+l = logging.getLogger(__name__)
+
+class RemindBot(BotPlugin):
+ """RemindBot reminds you of reminders."""
+
+ def activate(self):
+ super(RemindBot, self).activate()
+
+ r = r"(of|to)?\s*(?P<reminder>.*)\b(on|at|when it\s*['i]s|in|the|\s)+\b\s+(?P<time>.*)"
+ self.re = re.compile(r)
+ self.cal = parsedatetime.Calendar()
+
+ reminders = self.setdefault("reminders", [])
+
+ now = datetime.datetime.now()
+ self["reminders"].sort(key=lambda x: x[0])
+ for reminder in self["reminders"]:
+ if (reminder[0] < now):
+ self["reminders"].remove(reminder)
+ else:
+ break
+
+ self.start_next_reminder()
+
+ def start_next_reminder(self):
+ try:
+ self.stop_poller(self.reminding)
+ except ValueError:
+ pass
+
+ if (len(self["reminders"]) > 0):
+ self["reminders"].sort(key=lambda x: x[0])
+ now = datetime.datetime.now()
+ td = self["reminders"][0][0] - now
+
+ self.start_poller(td.total_seconds(), self.reminding)
+
+ def reminding(self):
+ self.stop_poller(self.reminding)
+
+ (time, msg, txt) = self["reminders"].pop(0)
+ self.send(msg.frm, txt, message_type=msg.type)
+
+ self.start_next_reminder()
+
+ @botcmd
+ def remind_me(self, msg, args):
+ m = self.re.match(args)
+ if (m is not None):
+ time, flag = self.cal.parseDT(m.group("time"))
+ if (flag == 0):
+ return "Sorry, I don't understand '{}'".format(m.group("time"))
+ else:
+ self["reminders"].append((time, msg, m.group("reminder")))
+ self.start_next_reminder()
+ return "I will remind you at {} of '{}'".format(time, m.group("reminder"))
+ else:
+ return "I don't understand... Sorry :("