remind no longer requires message
This commit is contained in:
parent
840f9e925f
commit
1f77f1a88b
|
@ -111,47 +111,23 @@ def setup(bot):
|
|||
start_monitor(bot)
|
||||
|
||||
|
||||
scaling = collections.OrderedDict([
|
||||
('years', 365.25 * 24 * 3600),
|
||||
('year', 365.25 * 24 * 3600),
|
||||
('yrs', 365.25 * 24 * 3600),
|
||||
('y', 365.25 * 24 * 3600),
|
||||
|
||||
('months', 29.53059 * 24 * 3600),
|
||||
('month', 29.53059 * 24 * 3600),
|
||||
('mo', 29.53059 * 24 * 3600),
|
||||
|
||||
('weeks', 7 * 24 * 3600),
|
||||
('week', 7 * 24 * 3600),
|
||||
('wks', 7 * 24 * 3600),
|
||||
('wk', 7 * 24 * 3600),
|
||||
('w', 7 * 24 * 3600),
|
||||
|
||||
('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())
|
||||
|
||||
regex = (
|
||||
"(?=\d+[ywdhms])"
|
||||
"(?:(\d+)y)?"
|
||||
"(?:(\d+)w)?"
|
||||
"(?:(\d+)d)?"
|
||||
"(?:(\d+)h)?"
|
||||
"(?:(\d+)m)?"
|
||||
"(?:(\d+)s)?"
|
||||
)
|
||||
multiplier = [
|
||||
60*60*24*365,
|
||||
60*60*24*7,
|
||||
60*60*24,
|
||||
60*60,
|
||||
60,
|
||||
1
|
||||
]
|
||||
|
||||
@commands('remind')
|
||||
@example('.remind 3h45m Go to class')
|
||||
|
@ -160,29 +136,15 @@ def remind(bot, trigger):
|
|||
if not trigger.group(2):
|
||||
return bot.msg("Missing arguments for reminder command.")
|
||||
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
|
||||
message = filter(None, re.split(f"(\d+(?:\.\d+)? ?(?:(?i) {periods})) ?",
|
||||
trigger.group(2))[1:])
|
||||
reminder = ''
|
||||
stop = False
|
||||
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)
|
||||
for n, group in enumerate(re.search(regex, trigger.group(3)).groups()):
|
||||
if not group:
|
||||
continue
|
||||
duration += int(group) * multiplier[n]
|
||||
create_reminder(bot, trigger, duration, reminder)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user