2012-07-16 22:45:41 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
|
|
|
import re
|
|
|
|
import imp
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
|
|
|
|
2012-11-04 14:32:39 +00:00
|
|
|
nemubotversion = 3.3
|
2012-07-16 22:45:41 +00:00
|
|
|
|
|
|
|
def help_tiny ():
|
|
|
|
"""Line inserted in the response to the command !help"""
|
|
|
|
return "as http://sleepyti.me/, give you the best time to go to bed"
|
|
|
|
|
|
|
|
def help_full ():
|
2012-11-04 14:32:39 +00:00
|
|
|
return "If you would like to sleep soon, use !sleepytime to know the best time to wake up; use !sleepytime hh:mm if you want to wake up at hh:mm"
|
2012-07-16 22:45:41 +00:00
|
|
|
|
2012-08-16 03:42:54 +00:00
|
|
|
def load(context):
|
|
|
|
from hooks import Hook
|
2012-10-15 00:20:01 +00:00
|
|
|
add_hook("cmd_hook", Hook(cmd_sleep, "sleeptime"))
|
|
|
|
add_hook("cmd_hook", Hook(cmd_sleep, "sleepytime"))
|
2012-07-16 22:45:41 +00:00
|
|
|
|
2012-08-16 03:42:54 +00:00
|
|
|
|
2012-08-22 19:05:33 +00:00
|
|
|
def cmd_sleep(msg):
|
2012-11-04 14:32:39 +00:00
|
|
|
if len (msg.cmds) > 1 and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
|
|
|
|
msg.cmds[1]) is not None:
|
2012-08-16 03:42:54 +00:00
|
|
|
# First, parse the hour
|
2012-11-04 14:32:39 +00:00
|
|
|
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.cmds[1])
|
2012-08-16 03:42:54 +00:00
|
|
|
f = [datetime(datetime.today().year,
|
|
|
|
datetime.today().month,
|
|
|
|
datetime.today().day,
|
|
|
|
hour=int(p.group(1)))]
|
|
|
|
if p.group(2) is not None:
|
|
|
|
f[0] += timedelta(minutes=int(p.group(2)))
|
|
|
|
g = list()
|
|
|
|
for i in range(0,6):
|
|
|
|
f.append(f[i] - timedelta(hours=1,minutes=30))
|
|
|
|
g.append(f[i+1].strftime("%H:%M"))
|
2012-08-30 23:54:57 +00:00
|
|
|
return Response(msg.sender,
|
|
|
|
"You should try to fall asleep at one of the following"
|
|
|
|
" times: %s" % ', '.join(g), msg.channel)
|
2012-08-16 03:42:54 +00:00
|
|
|
|
|
|
|
# Just get awake times
|
2012-07-16 22:45:41 +00:00
|
|
|
else:
|
2012-08-16 03:42:54 +00:00
|
|
|
f = [datetime.now() + timedelta(minutes=15)]
|
|
|
|
g = list()
|
|
|
|
for i in range(0,6):
|
|
|
|
f.append(f[i] + timedelta(hours=1,minutes=30))
|
|
|
|
g.append(f[i+1].strftime("%H:%M"))
|
2012-08-30 23:54:57 +00:00
|
|
|
return Response(msg.sender,
|
|
|
|
"If you head to bed right now, you should try to wake"
|
|
|
|
" up at one of the following times: %s" %
|
|
|
|
', '.join(g), msg.channel)
|