fulvia/modules/countdown.py

33 lines
910 B
Python
Executable File

#!/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:
return bot.msg("Please use correct format: .countdown 2012 12 21")
text = text.split()
if (len(text) != 3 or not text[0].isdigit() or not text[1].isdigit()
or not text[2].isdigit()):
return bot.msg("Please use correct format: .countdown 2012 12 21")
try:
date = datetime(int(text[0]), int(text[1]), int(text[2]))
except:
return bot.msg("Please use correct format: .countdown 2012 12 21")
msg = relativeTime(bot.config, datetime.now(), date)
msg += " until " + trigger.group(2)
bot.msg(msg)