Skip to content

Instantly share code, notes, and snippets.

@passcod
Created Nov 22, 2012
Embed
What would you like to do?
xbot nanowrimo sprint module/script
# Append to: nanowrime.py
import time
import datetime
from threading import Thread
class nanotimer(Thread):
def set(self, time = 15, func = lambda: 0, *args):
self.time = time * 60
self.func = func
self.args = args
def run(self):
time.sleep(self.time)
self.func(self.args)
def nanosprint(bot, args):
if len(args) != 2:
return util.give_help(bot, args[0], "[minutes]")
if 'sprint' in bot.inv:
diff = bot.inv['sprint']['duration'] - (datetime.datetime.now() - bot.inv['sprint']['start']).seconds) / 60.0
util.answer(bot, "Sprint is running... %.f minutes left!" % diff)
return
try:
t = int(args[1])
except ValueError:
return
tim = nanotimer()
tim.set(time=1, lambda bot, duration:
t = nanotimer()
t.set(duration, lambda bot:
del bot.inv['sprint']
util.answer(bot, "Sprint over!")
, bot)
bot.inv['sprint'] = {'start': datetime.datetime.now(), 'duration': duration}
util.answer(bot, "...set... GO!")
t.start()
, t, bot)
util.answer(bot, "%d-minute sprint starts in one minute. On your marks..." % t)
tim.start()
util.register(nanosprint, "common", "sprint")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment