+@lib.hook(needchan=False)
+@lib.help("<option>", "votes for a trarget score for next round")
+def vote(bot, user, chan, realtarget, *args):
+ if state.pointvote is not None:
+ if int(args[0]) in state.voteamounts:
+ state.voteamounts[int(args[0])] += 1
+ bot.msg(user, "Your vote has been recorded.")
+ else:
+ bot.msg(user, "Sorry - that's not an option!")
+ else:
+ bot.msg(user, "There's no vote in progress.")
+
+@lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<number>", "sets the max missed question before game stops")
+def 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(glevel=lib.ADMIN, needchan=False)
+@lib.help("<seconds>", "sets the time between hints")
+def 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(glevel=lib.ADMIN, needchan=False)
+@lib.help("<number>", "sets the number of hints given")
+def 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(glevel=lib.ADMIN, needchan=False)
+@lib.help("<seconds>", "sets the pause between questions")
+def questionpause(bot, user, chan, realtarget, *args):
+ try:
+ state.db['questionpause'] = float(args[0])
+ bot.msg(state.db['chan'], "Pause between questions has been changed to %s." % (state.db['questionpause']))
+ except:
+ bot.msg(user, "Failed to set questionpause.")
+
+@lib.hook(glevel=1, needchan=False)
+@lib.help("<full question>", "finds a qid given a complete question")
+def findq(bot, user, chan, realtarget, *args):
+ args = list(args)
+ if args[0].startswith("@"):
+ cat = args.pop(0)[1:].lower()
+ questions = state.db['questions'][cat]
+ else:
+ questions = state.questions
+
+ if len(args) == 0:
+ bot.msg(user, "You need to specify the question.")
+ return
+
+ searchkey = ' '.join(args).lower()
+ matches = [str(i) for i in range(len(questions)) if questions[i][0].lower() == searchkey]
+ 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(glevel=1, needchan=False)
+@lib.help("[@<category>] <regex>", "finds a qid given a regex or partial question")
+def findqre(bot, user, chan, realtarget, *args):
+ args = list(args)
+ if args[0].startswith("@"):
+ cat = args.pop(0)[1:].lower()
+ questions = state.db['questions'][cat]
+ else:
+ questions = state.questions
+
+ if len(args) == 0:
+ bot.msg(user, "You need to specify a search string.")
+ return
+
+ searcher = re.compile(' '.join(args), re.IGNORECASE)
+ matches = [str(i) for i in range(len(questions)) if searcher.search(questions[i][0]) is not None]
+ if len(matches) > 25:
+ bot.msg(user, "Too many matches! (>25)")
+ elif 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(glevel=lib.STAFF, needchan=False)
+@lib.help("[@<category>] <qid>", "displays the q*a for a qid", "category defaults to current")
+def showq(bot, user, chan, realtarget, *args):
+ args = list(args)
+ if args[0].startswith("@"):
+ cat = args.pop(0)[1:].lower()
+ questions = state.db['questions'][cat]
+ else:
+ questions = state.questions
+
+ try:
+ qid = int(args[0])
+ except:
+ bot.msg(user, "Specify a numeric question ID.")
+ return
+ try:
+ q = questions[qid]
+ except:
+ bot.msg(user, "ID not valid.")
+ return
+ bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1]))
+
+@lib.hook(('delq', 'deleteq'), glevel=lib.STAFF, needchan=False)
+@lib.help("[@<category>] <qid>", "removes a question from the database")
+def delq(bot, user, chan, realtarget, *args):
+ args = list(args)
+ if args[0].startswith("@"):
+ cat = args.pop(0)[1:].lower()
+ questions = state.db['questions'][cat]
+ else:
+ questions = state.questions
+
+ try:
+ backup = questions[int(args[0])]
+ del questions[int(args[0])]
+ bot.msg(user, "Deleted %s*%s" % (backup[0], backup[1]))
+ except:
+ bot.msg(user, "Couldn't delete that question. %r" % (e))
+
+@lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("[@<category>] <q>*<a>", "adds a question")
+def addq(bot, user, chan, realtarget, *args):
+ args = list(args)
+ if args[0].startswith("@"):
+ cat = args.pop(0)[1:].lower()
+ questions = state.db['questions'][cat]
+ else:
+ questions = state.questions
+
+ line = ' '.join([str(arg) for arg in args])
+ linepieces = line.split('*', 1)
+ if len(linepieces) < 2:
+ bot.msg(user, "Error: need <question>*<answer>")
+ return
+ question = linepieces[0].strip()
+ answer = linepieces[1].strip()
+ questions.append([question, answer])
+ bot.msg(user, "Done. Question is #%s" % (len(questions)-1))
+
+@lib.hook(needchan=False)
+@lib.help(None, "show current category")
+def showcat(bot, user, chan, realtarget, *args):
+ bot.msg(user, "Current category: %s" % (state.db['category']))
+
+@lib.hook(glevel=1, needchan=False)
+@lib.help("<category>", "change category")
+def setcat(bot, user, chan, realtarget, *args):
+ category = args[0].lower()
+ if category in state.db['questions']:
+ state.db['category'] = category
+ state.questions = state.db['questions'][category]
+ bot.msg(user, "Changed category to %s" % (category))
+ else:
+ bot.msg(user, "That category doesn't exist.")
+
+@lib.hook(needchan=False)
+@lib.help(None, "list categories", "the current category will be marked with a *")
+def listcats(bot, user, chan, realtarget, *args):
+ cats = ["%s%s (%d)" % ("*" if c == state.db['category'] else "", c, len(state.db['questions'][c])) for c in state.db['questions'].keys()]
+ bot.msg(user, "Categories: %s" % (', '.join(cats)))
+
+@lib.hook(glevel=lib.STAFF, needchan=False)
+@lib.help("<category>", "adds an empty category")
+def addcat(bot, user, chan, realtarget, *args):
+ category = args[0].lower()
+ if category not in state.db['questions']:
+ state.db['questions'][category] = []
+ bot.msg(user, "Added category %s" % (category))
+ else:
+ bot.msg(user, "Category already exists.")
+
+@lib.hook(glevel=lib.MANAGER, needchan=False)
+@lib.help("<category>", "deletes an entire category")
+def delcat(bot, user, chan, realtarget, *args):
+ category = args[0].lower()
+ if category == state.db['category']:
+ bot.msg(user, "Category currently in use!")
+ elif category in state.db['questions']:
+ length = len(state.db['questions'][category])
+ del state.db['questions'][category]
+ bot.msg(user, "Deleted category %s (%d questions)" % (category, length))
+ else:
+ bot.msg(user, "Category does not exist.")
+
+@lib.hook(needchan=False)
+def triviahelp(bot, user, chan, realtarget, *args):
+ bot.slowmsg(user, "START")
+ bot.slowmsg(user, "TOP10")
+ bot.slowmsg(user, "POINTS [<user>]")
+ bot.slowmsg(user, "RANK [<user>]")
+ bot.slowmsg(user, "BADQ <reason> (include info to identify question)")
+ if user.glevel >= 1:
+ bot.slowmsg(user, "SKIP (KNOWN)")
+ bot.slowmsg(user, "STOP (KNOWN)")
+ bot.slowmsg(user, "FINDQ <full question> (KNOWN)")
+ bot.slowmsg(user, "FINDQRE <regex> (KNOWN)")
+ bot.slowmsg(user, "SETNEXTID <qid> (KNOWN)")
+ if user.glevel >= lib.STAFF:
+ bot.slowmsg(user, "GIVE <user> [<points>] (STAFF)")
+ bot.slowmsg(user, "SETNEXT <q>*<a> (STAFF)")
+ bot.slowmsg(user, "ADDQ <q>*<a> (STAFF)")
+ bot.slowmsg(user, "DELQ <q>*<a> (STAFF) [aka DELETEQ]")
+ bot.slowmsg(user, "SHOWQ <qid> (STAFF)")
+ bot.slowmsg(user, "BADQS (STAFF)")
+ bot.slowmsg(user, "CLEARBADQS (STAFF)")
+ bot.slowmsg(user, "DELBADQ <reportid> (STAFF)")
+ if user.glevel >= lib.ADMIN:
+ bot.slowmsg(user, "SETTARGET <points> (ADMIN)")
+ bot.slowmsg(user, "MAXMISSED <questions> (ADMIN)")
+ bot.slowmsg(user, "HINTTIMER <float seconds> (ADMIN)")
+ bot.slowmsg(user, "HINTNUM <hints> (ADMIN)")
+ bot.slowmsg(user, "QUESTIONPAUSE <float seconds> (ADMIN)")