Covert sleepytime module to V3.2
This commit is contained in:
parent
3692a167cc
commit
9b5c1d2e60
1 changed files with 31 additions and 15 deletions
|
@ -5,7 +5,7 @@ import imp
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
nemubotversion = 3.0
|
nemubotversion = 3.2
|
||||||
|
|
||||||
def help_tiny ():
|
def help_tiny ():
|
||||||
"""Line inserted in the response to the command !help"""
|
"""Line inserted in the response to the command !help"""
|
||||||
|
@ -14,20 +14,36 @@ def help_tiny ():
|
||||||
def help_full ():
|
def help_full ():
|
||||||
return "TODO"
|
return "TODO"
|
||||||
|
|
||||||
|
def load(context):
|
||||||
|
from hooks import Hook
|
||||||
|
context.hooks.add_hook(context.hooks.cmd_hook, Hook(cmd_sleep, "sleeptime"))
|
||||||
|
context.hooks.add_hook(context.hooks.cmd_hook, Hook(cmd_sleep, "sleepytime"))
|
||||||
|
|
||||||
def parseanswer (msg):
|
|
||||||
if msg.cmd[0] == "sleepytime" or msg.cmd[0] == "sleeptime":
|
def cmd_sleep(data, msg):
|
||||||
if len (msg.cmd) > 1:
|
if len (msg.cmd) > 1 and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
|
||||||
i = int(msg.cmd[1])
|
msg.cmd[1]) is not None:
|
||||||
start = datetime.now() + timedelta(minutes=15)
|
# First, parse the hour
|
||||||
length = timedelta(hours=1,minutes=30) * i
|
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.cmd[1])
|
||||||
msg.send_chn("After %d cycles: %s (during %d:%d)" % (i, start.strftime("%H:%M"), length.seconds/3600, (length.seconds%3600)/60))
|
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"))
|
||||||
|
msg.send_chn("You should try to fall asleep at one of the following times: %s" % ', '.join(g))
|
||||||
|
|
||||||
|
# Just get awake times
|
||||||
else:
|
else:
|
||||||
f = [datetime.now() + timedelta(minutes=15)]
|
f = [datetime.now() + timedelta(minutes=15)]
|
||||||
g = list()
|
g = list()
|
||||||
for i in range(0,6):
|
for i in range(0,6):
|
||||||
f.append(f[i] + timedelta(hours=1,minutes=30))
|
f.append(f[i] + timedelta(hours=1,minutes=30))
|
||||||
g.append(f[i+1].strftime("%H:%M"))
|
g.append(f[i+1].strftime("%H:%M"))
|
||||||
msg.send_chn("If you head to bed right now, you should try to wake up at one of the following times: %s"% ', '.join(g))
|
msg.send_chn("If you head to bed right now, you should try to wake up at one of the following times: %s"% ', '.join(g))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
return False
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue