+@lib.hook('maxmissed', clevel=lib.MASTER, needchan=False)
+def cmd_maxmissed(bot, user, chan, realtarget, *args):
+ try:
+ state.db['maxmissedquestions'] = int(args[0])
+ bot.msg(state.db['chan'], "Max missed questions before round ends has been changed to %s." % (state.db['maxmissedquestions']))
+ except:
+ bot.msg(user, "Failed to set maxmissed.")
+
+@lib.hook('hinttimer', clevel=lib.MASTER, needchan=False)
+def cmd_hinttimer(bot, user, chan, realtarget, *args):
+ try:
+ state.db['hinttimer'] = float(args[0])
+ bot.msg(state.db['chan'], "Time between hints has been changed to %s." % (state.db['hinttimer']))
+ except:
+ bot.msg(user, "Failed to set hint timer.")
+
+@lib.hook('hintnum', clevel=lib.MASTER, needchan=False)
+def cmd_hintnum(bot, user, chan, realtarget, *args):
+ try:
+ state.db['hintnum'] = int(args[0])
+ bot.msg(state.db['chan'], "Max number of hints has been changed to %s." % (state.db['hintnum']))
+ except:
+ bot.msg(user, "Failed to set hintnum.")
+
+@lib.hook('findq', clevel=lib.KNOWN, needchan=False)
+def cmd_findquestion(bot, user, chan, realtarget, *args):
+ matches = [str(i) for i in range(len(state.db['questions'])) if state.db['questions'][i]['question'] == ' '.join(args)] #FIXME: looser equality check
+ if len(matches) > 1:
+ bot.msg(user, "Multiple matches: %s" % (', '.join(matches)))
+ elif len(matches) == 1:
+ bot.msg(user, "One match: %s" % (matches[0]))
+ else:
+ bot.msg(user, "No match.")
+
+@lib.hook('delq', clevel=lib.OP, needchan=False)
+@lib.hook('deleteq', clevel=lib.OP, needchan=False)
+def cmd_deletequestion(bot, user, chan, realtarget, *args):
+ try:
+ backup = state.db['questions'][int(args[0])]
+ del state.db['questions'][int(args[0])]
+ bot.msg(user, "Deleted %s*%s" % (backup['question'], backup['answer']))
+ except:
+ bot.msg(user, "Couldn't delete that question.")
+
+@lib.hook('addq', clevel=lib.OP, needchan=False)
+def cmd_addquestion(bot, user, chan, realtarget, *args):
+ line = ' '.join([str(arg) for arg in args])
+ linepieces = line.split('*')
+ if len(linepieces) < 2:
+ bot.msg(user, "Error: need <question>*<answer>")
+ return
+ question = linepieces[0].strip()
+ answer = linepieces[1].strip()
+ state.db['questions'].append({'question':question,'answer':answer})
+ bot.msg(user, "Done. Question is #%s" % (len(state.db['questions'])-1))
+
+