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 timedelta
|
||||
|
||||
nemubotversion = 3.0
|
||||
nemubotversion = 3.2
|
||||
|
||||
def help_tiny ():
|
||||
"""Line inserted in the response to the command !help"""
|
||||
|
@ -14,20 +14,36 @@ def help_tiny ():
|
|||
def help_full ():
|
||||
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":
|
||||
if len (msg.cmd) > 1:
|
||||
i = int(msg.cmd[1])
|
||||
start = datetime.now() + timedelta(minutes=15)
|
||||
length = timedelta(hours=1,minutes=30) * i
|
||||
msg.send_chn("After %d cycles: %s (during %d:%d)" % (i, start.strftime("%H:%M"), length.seconds/3600, (length.seconds%3600)/60))
|
||||
|
||||
def cmd_sleep(data, msg):
|
||||
if len (msg.cmd) > 1 and re.match("[0-9]{1,2}[h':.,-]([0-9]{1,2})?[m'\":.,-]?",
|
||||
msg.cmd[1]) is not None:
|
||||
# First, parse the hour
|
||||
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.cmd[1])
|
||||
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:
|
||||
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"))
|
||||
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))
|
||||
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"))
|
||||
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 False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue