remind no longer requires message

This commit is contained in:
iou1name 2019-06-28 08:06:39 -04:00
parent 840f9e925f
commit 1f77f1a88b

View File

@ -111,47 +111,23 @@ def setup(bot):
start_monitor(bot) start_monitor(bot)
scaling = collections.OrderedDict([ regex = (
('years', 365.25 * 24 * 3600), "(?=\d+[ywdhms])"
('year', 365.25 * 24 * 3600), "(?:(\d+)y)?"
('yrs', 365.25 * 24 * 3600), "(?:(\d+)w)?"
('y', 365.25 * 24 * 3600), "(?:(\d+)d)?"
"(?:(\d+)h)?"
('months', 29.53059 * 24 * 3600), "(?:(\d+)m)?"
('month', 29.53059 * 24 * 3600), "(?:(\d+)s)?"
('mo', 29.53059 * 24 * 3600), )
multiplier = [
('weeks', 7 * 24 * 3600), 60*60*24*365,
('week', 7 * 24 * 3600), 60*60*24*7,
('wks', 7 * 24 * 3600), 60*60*24,
('wk', 7 * 24 * 3600), 60*60,
('w', 7 * 24 * 3600), 60,
1
('days', 24 * 3600), ]
('day', 24 * 3600),
('d', 24 * 3600),
('hours', 3600),
('hour', 3600),
('hrs', 3600),
('hr', 3600),
('h', 3600),
('minutes', 60),
('minute', 60),
('mins', 60),
('min', 60),
('m', 60),
('seconds', 1),
('second', 1),
('secs', 1),
('sec', 1),
('s', 1),
])
periods = '|'.join(scaling.keys())
@commands('remind') @commands('remind')
@example('.remind 3h45m Go to class') @example('.remind 3h45m Go to class')
@ -160,29 +136,15 @@ def remind(bot, trigger):
if not trigger.group(2): if not trigger.group(2):
return bot.msg("Missing arguments for reminder command.") return bot.msg("Missing arguments for reminder command.")
if trigger.group(3) and not trigger.group(4): if trigger.group(3) and not trigger.group(4):
return bot.msg("No message given for reminder.") reminder = ''
else:
reminder = trigger.group(4)
duration = 0 duration = 0
message = filter(None, re.split(f"(\d+(?:\.\d+)? ?(?:(?i) {periods})) ?", for n, group in enumerate(re.search(regex, trigger.group(3)).groups()):
trigger.group(2))[1:]) if not group:
reminder = '' continue
stop = False duration += int(group) * multiplier[n]
for piece in message:
grp = re.match('(\d+(?:\.\d+)?) ?(.*) ?', piece)
if grp and not stop:
length = float(grp.group(1))
factor = scaling.get(grp.group(2).lower(), 60)
duration += length * factor
else:
reminder = reminder + piece
stop = True
if duration == 0:
return bot.reply("Sorry, didn't understand the input.")
if duration % 1:
duration = int(duration) + 1
else:
duration = int(duration)
create_reminder(bot, trigger, duration, reminder) create_reminder(bot, trigger, duration, reminder)