optionally provide name of new countdown items

This commit is contained in:
Brian S. Stephan 2021-04-24 12:55:51 -05:00
parent ab0d738851
commit dc5f243608
1 changed files with 11 additions and 3 deletions

View File

@ -22,7 +22,8 @@ class Countdown(Plugin):
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'(until\s+(?P<recurring_until>.*?)\s+)?'
r'(to|that|about)\s+(?P<text>.*)')
r'(to|that|about)\s+(?P<text>.*?)'
r'(?=\s+\("(?P<name>.*)"\)|$)')
def __init__(self, bot, connection, event):
"""Initialize some stuff."""
@ -42,7 +43,7 @@ class Countdown(Plugin):
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+list$',
self.handle_item_list, -20)
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+(\S+)$',
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!countdown\s+(.+)$',
self.handle_item_detail, -20)
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], self.new_reminder_regex,
self.handle_new_reminder, -50)
@ -99,9 +100,16 @@ class Countdown(Plugin):
recurring_period = match.group('recurring_period')
recurring_until = match.group('recurring_until')
text = match.group('text')
name = match.group('name')
log.debug("%s / %s / %s", who, when, text)
item_name = '{0:s}-{1:s}'.format(event.sender_nick, timezone.now().strftime('%s'))
if not name:
item_name = '{0:s}-{1:s}'.format(event.sender_nick, timezone.now().strftime('%s'))
else:
if CountdownItem.objects.filter(name=name).count() > 0:
self.bot.reply(event, "item with name '{0:s}' already exists".format(name))
return 'NO MORE'
item_name = name
# parse when to send the notification
if when_type == 'in':