+ if threading is not None and threading._Timer is not None and isinstance(self.steptimer, threading._Timer):
+ self.steptimer.cancel()
+ if json is not None and json.dump is not None:
+ json.dump(self.db, open(self.questionfile, "w"), indent=4, separators=(',',': '))
+
+ def getchan(self):
+ return self.parent.channel(self.chan)
+ def getbot(self):
+ return self.getchan().bot
+
+ def nexthint(self, hintnum):
+ if self.hintanswer is None:
+ if isinstance(self.curq['answer'], basestring): self.hintanswer = self.curq['answer']
+ else: self.hintanswer = random.choice(self.curq['answer'])
+ answer = self.hintanswer
+
+ if self.hintstr is None or self.revealpossibilities is None:
+ self.hintstr = list(re.sub(r'[a-zA-Z0-9]', '*', answer))
+ self.revealpossibilities = range(''.join(self.hintstr).count('*'))
+
+ reveal = int(len(self.hintstr) * (7/24.0))
+ for i in range(reveal):
+ revealcount = random.choice(self.revealpossibilities)
+ revealloc = findnth(''.join(self.hintstr), '*', revealcount)
+ self.revealpossibilities.remove(revealcount)
+ self.hintstr[revealloc] = answer[revealloc]
+ self.parent.channel(self.chan).bot.msg(self.chan, "Here's a hint: %s" % (''.join(self.hintstr)))
+
+ if hintnum < HINTNUM:
+ self.steptimer = threading.Timer(HINTTIMER, self.nexthint, args=[hintnum+1])
+ self.steptimer.start()
+ else:
+ self.steptimer = threading.Timer(HINTTIMER, self.nextquestion, args=[True])
+ self.steptimer.start()
+
+ def nextquestion(self, qskipped=False):
+ if qskipped:
+ self.getbot().msg(self.getchan(), "Fail! The correct answer was: %s" % (self.hintanswer))
+
+ if isinstance(self.steptimer, threading._Timer):
+ self.steptimer.cancel()
+ self.hintstr = None
+ self.hintanswer = None
+ self.revealpossibilities = None