forked from maxpowa/inumuta-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countdown.py
39 lines (36 loc) · 1.35 KB
/
countdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding=utf-8
"""
countdown.py - Sopel Countdown Module
Copyright 2011, Michael Yanovich, yanovich.net
Licensed under the Eiffel Forum License 2.
http://sopel.dfbta.net
"""
from __future__ import unicode_literals, absolute_import, print_function, division
from sopel.module import commands, NOLIMIT
import datetime
@commands('countdown')
def generic_countdown(bot, trigger):
"""
.countdown <year> <month> <day> - displays a countdown to a given date.
"""
text = trigger.group(2)
if not text:
bot.say("Please use correct format: .countdown 2012 12 21")
return NOLIMIT
text = trigger.group(2).split()
if text and (len(text) == 3 and text[0].isdigit() and text[1].isdigit()
and text[2].isdigit()):
try:
diff = (datetime.datetime(int(text[0]), int(text[1]), int(text[2]))
- datetime.datetime.today())
except:
bot.say("Please use correct format: .countdown 2012 12 21")
return NOLIMIT
bot.say(str(diff.days) + " days, " + str(diff.seconds // 3600)
+ " hours and "
+ str(diff.seconds % 3600 // 60 )
+ " minutes until "
+ text[0] + " " + text[1] + " " + text[2])
else:
bot.say("Please use correct format: .countdown 2012 12 21")
return NOLIMIT