countdown: add "recurring until" support
tacking onto the recurring option, this allows for having the recurringness end after a while. closes bss/dr.botzo#31
This commit is contained in:
parent
bdbba249cd
commit
1b1ae9638d
|
@ -22,6 +22,7 @@ class Countdown(Plugin):
|
||||||
|
|
||||||
new_reminder_regex = (r'remind\s+(?P<who>[^\s]+)\s+(?P<when_type>at|in|on)\s+(?P<when>.*?)\s+'
|
new_reminder_regex = (r'remind\s+(?P<who>[^\s]+)\s+(?P<when_type>at|in|on)\s+(?P<when>.*?)\s+'
|
||||||
r'(and\s+every\s+(?P<recurring_period>.*?)\s+)?'
|
r'(and\s+every\s+(?P<recurring_period>.*?)\s+)?'
|
||||||
|
r'(until\s+(?P<recurring_until>.*?)\s+)?'
|
||||||
r'(to|that|about)\s+(?P<text>.*)')
|
r'(to|that|about)\s+(?P<text>.*)')
|
||||||
|
|
||||||
def __init__(self, bot, connection, event):
|
def __init__(self, bot, connection, event):
|
||||||
|
@ -77,12 +78,17 @@ class Countdown(Plugin):
|
||||||
log.info("sending %s to %s", reminder.reminder_message, reminder.reminder_target)
|
log.info("sending %s to %s", reminder.reminder_message, reminder.reminder_target)
|
||||||
self.bot.reply(None, reminder.reminder_message, explicit_target=reminder.reminder_target)
|
self.bot.reply(None, reminder.reminder_message, explicit_target=reminder.reminder_target)
|
||||||
|
|
||||||
# if recurring, set a new at time, otherwise stop reminding
|
# if recurring and not hit until, set a new at time, otherwise stop reminding
|
||||||
if reminder.recurring_period != '':
|
if reminder.recurring_until is not None and timezone.now() >= reminder.recurring_until:
|
||||||
|
reminder.sent_reminder = True
|
||||||
|
elif reminder.recurring_period != '':
|
||||||
calendar = pdt.Calendar()
|
calendar = pdt.Calendar()
|
||||||
when_t = calendar.parseDT(reminder.recurring_period, reminder.at_time,
|
when_t = calendar.parseDT(reminder.recurring_period, reminder.at_time,
|
||||||
tzinfo=reminder.at_time.tzinfo)[0]
|
tzinfo=reminder.at_time.tzinfo)[0]
|
||||||
reminder.at_time = when_t
|
if reminder.recurring_until is None or when_t <= reminder.recurring_until:
|
||||||
|
reminder.at_time = when_t
|
||||||
|
else:
|
||||||
|
reminder.sent_reminder = True
|
||||||
else:
|
else:
|
||||||
reminder.sent_reminder = True
|
reminder.sent_reminder = True
|
||||||
reminder.save()
|
reminder.save()
|
||||||
|
@ -110,6 +116,7 @@ class Countdown(Plugin):
|
||||||
when_type = match.group('when_type')
|
when_type = match.group('when_type')
|
||||||
when = match.group('when')
|
when = match.group('when')
|
||||||
recurring_period = match.group('recurring_period')
|
recurring_period = match.group('recurring_period')
|
||||||
|
recurring_until = match.group('recurring_until')
|
||||||
text = match.group('text')
|
text = match.group('text')
|
||||||
log.debug("%s / %s / %s", who, when, text)
|
log.debug("%s / %s / %s", who, when, text)
|
||||||
|
|
||||||
|
@ -138,6 +145,9 @@ class Countdown(Plugin):
|
||||||
reminder_message=message, reminder_target=sent_location)
|
reminder_message=message, reminder_target=sent_location)
|
||||||
if recurring_period:
|
if recurring_period:
|
||||||
countdown_item.recurring_period = recurring_period
|
countdown_item.recurring_period = recurring_period
|
||||||
|
if recurring_until:
|
||||||
|
recurring_until_t = timezone.make_aware(parse(recurring_until))
|
||||||
|
countdown_item.recurring_until = recurring_until_t
|
||||||
countdown_item.save()
|
countdown_item.save()
|
||||||
log.info("created countdown item %s", str(countdown_item))
|
log.info("created countdown item %s", str(countdown_item))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.5 on 2017-02-24 01:12
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('countdown', '0004_countdownitem_recurring_period'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='countdownitem',
|
||||||
|
name='recurring_until',
|
||||||
|
field=models.DateTimeField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -22,6 +22,7 @@ class CountdownItem(models.Model):
|
||||||
reminder_target = models.CharField(max_length=64, default='')
|
reminder_target = models.CharField(max_length=64, default='')
|
||||||
|
|
||||||
recurring_period = models.CharField(max_length=64, default='')
|
recurring_period = models.CharField(max_length=64, default='')
|
||||||
|
recurring_until = models.DateTimeField(null=True, blank=True, default=None)
|
||||||
|
|
||||||
created_time = models.DateTimeField(auto_now_add=True)
|
created_time = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue