fulvia/modules/countdown.py

33 lines
898 B
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
Provides a countdown to some particular date.
"""
from datetime import datetime
from module import commands, example
from tools.time import relativeTime
@commands("countdown")
@example(".countdown 2012 12 21")
def generic_countdown(bot, trigger):
"""
.countdown <year> <month> <day> - displays a countdown to a given date.
"""
text = trigger.group(2)
if not text:
2018-05-25 15:21:18 -04:00
return bot.msg("Please use correct format: .countdown 2012 12 21")
2018-03-16 03:13:43 -04:00
text = text.split()
if (len(text) != 3 or not text[0].isdigit() or not text[1].isdigit()
or not text[2].isdigit()):
2018-05-25 15:21:18 -04:00
return bot.msg("Please use correct format: .countdown 2012 12 21")
2018-03-16 03:13:43 -04:00
try:
date = datetime(int(text[0]), int(text[1]), int(text[2]))
except:
2018-05-25 15:21:18 -04:00
return bot.msg("Please use correct format: .countdown 2012 12 21")
2018-03-16 03:13:43 -04:00
2019-10-08 12:39:13 -04:00
msg = relativeTime(datetime.now(), date)
2018-03-16 03:13:43 -04:00
msg += " until " + trigger.group(2)
2018-05-25 15:21:18 -04:00
bot.msg(msg)