diff --git a/countdown/ircplugin.py b/countdown/ircplugin.py index c135234..d7c2f6c 100644 --- a/countdown/ircplugin.py +++ b/countdown/ircplugin.py @@ -21,6 +21,7 @@ class Countdown(Plugin): """Report on countdown items.""" new_reminder_regex = (r'remind\s+(?P[^\s]+)\s+(?Pat|in|on)\s+(?P.*?)\s+' + r'(and\s+every\s+(?P.*?)\s+)?' r'(to|that|about)\s+(?P.*)') def __init__(self, bot, connection, event): @@ -75,7 +76,15 @@ class Countdown(Plugin): if reminder.at_time <= timezone.now(): log.info("sending %s to %s", reminder.reminder_message, reminder.reminder_target) self.bot.reply(None, reminder.reminder_message, explicit_target=reminder.reminder_target) - reminder.sent_reminder = True + + # if recurring, set a new at time, otherwise stop reminding + if reminder.recurring_period != '': + calendar = pdt.Calendar() + when_t = calendar.parseDT(reminder.recurring_period, reminder.at_time, + tzinfo=reminder.at_time.tzinfo)[0] + reminder.at_time = when_t + else: + reminder.sent_reminder = True reminder.save() time.sleep(1) @@ -100,6 +109,7 @@ class Countdown(Plugin): who = match.group('who') when_type = match.group('when_type') when = match.group('when') + recurring_period = match.group('recurring_period') text = match.group('text') log.debug("%s / %s / %s", who, when, text) @@ -126,6 +136,9 @@ class Countdown(Plugin): countdown_item = CountdownItem.objects.create(name=item_name, at_time=when_t, is_reminder=True, reminder_message=message, reminder_target=sent_location) + if recurring_period: + countdown_item.recurring_period = recurring_period + countdown_item.save() log.info("created countdown item %s", str(countdown_item)) if in_privmsg: diff --git a/countdown/migrations/0004_countdownitem_recurring_period.py b/countdown/migrations/0004_countdownitem_recurring_period.py new file mode 100644 index 0000000..608859f --- /dev/null +++ b/countdown/migrations/0004_countdownitem_recurring_period.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-02-24 01:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('countdown', '0003_auto_20170222_2025'), + ] + + operations = [ + migrations.AddField( + model_name='countdownitem', + name='recurring_period', + field=models.CharField(default='', max_length=64), + ), + ] diff --git a/countdown/models.py b/countdown/models.py index 1336657..6437ef1 100644 --- a/countdown/models.py +++ b/countdown/models.py @@ -21,6 +21,8 @@ class CountdownItem(models.Model): reminder_message = models.TextField(default="") reminder_target = models.CharField(max_length=64, default='') + recurring_period = models.CharField(max_length=64, default='') + created_time = models.DateTimeField(auto_now_add=True) def __str__(self):