else:
oldhintstr = ''.join(self.hintstr)
- for i in range(self.reveal):
- revealcount = random.choice(self.revealpossibilities)
- revealloc = findnth(''.join(self.hintstr), '*', revealcount)
- self.revealpossibilities.remove(revealcount)
- self.hintstr[revealloc] = answer[revealloc]
+ try:
+ for i in range(self.reveal):
+ revealcount = random.choice(self.revealpossibilities)
+ revealloc = findnth(''.join(self.hintstr), '*', revealcount)
+ self.revealpossibilities.remove(revealcount)
+ self.hintstr[revealloc] = answer[revealloc]
+ except IndexError: pass # if everything is revealed, random.choice will IndexError
if oldhintstr != ''.join(self.hintstr): self.getchan().fastmsg("\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
self.hintsgiven += 1
self.db['users'] = {}
self.db['ranks'] = []
+ self.savedb()
stop()
self.closeshop()
except: return 0
status = False
+ f = None
try:
f = open(self.db['hofpath'], 'rb+')
for i in range(self.db['hoflines']): #skip this many lines
except Exception as e:
status = False
finally:
- f.close()
+ if f is not None:
+ f.close()
return status
def endPointVote(self):
bot.msg(user, "Error: no such QID.")
return
state.nextqid = qid
- bot.msg(user, "Done. Next question is %d: %s" % (qid, state.questions[qid][0]))
+ bot.msg(user, "Done. Next question is %d: %s" % (qid, state.questions[qid][0]), truncate=True)
@lib.hook(glevel=lib.STAFF, needchan=False)
@lib.help("<q>*<a>", "sets next question to one not in database")
def skip(bot, user, chan, realtarget, *args):
state.nextquestion(qskipped=True, skipwait=True)
-@lib.hook(needchan=False, wantchan=True)
+@lib.hook(('start','trivia'), needchan=False, wantchan=True)
@lib.help(None, "starts the trivia game")
def start(bot, user, chan, realtarget, *args):
if chan is not None: replyto = chan
bot.msg(user, "Failed to set questionpause.")
@lib.hook(glevel=1, needchan=False)
-@lib.help("<full question>", "finds a qid given a complete question")
+@lib.help("[@category] <full question>", "finds a qid given a complete question")
+@lib.argsGE(1)
def findq(bot, user, chan, realtarget, *args):
args = list(args)
if args[0].startswith("@"):
@lib.hook(glevel=1, needchan=False)
@lib.help("[@<category>] <regex>", "finds a qid given a regex or partial question")
+@lib.argsGE(1)
def findqre(bot, user, chan, realtarget, *args):
args = list(args)
if args[0].startswith("@"):
except:
bot.msg(user, "ID not valid.")
return
- bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1]))
+ bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1]), True)
@lib.hook(('delq', 'deleteq'), glevel=lib.STAFF, needchan=False)
@lib.help("[@<category>] <qid>", "removes a question from the database")