+ 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)")
+
+@lib.hooknum(417)
+def num_417(bot, textline):
+# bot.fastmsg(state.db['chan'], "Whoops, it looks like that question didn't quite go through! (E:417). Let's try another...")
+ state.nextquestion(qskipped=False, skipwait=True)
+
+@lib.hooknum(332)
+def num_TOPIC(bot, textline):
+ pieces = textline.split(None, 4)
+ chan = pieces[3]
+ if chan != state.db['chan']:
+ return
+ gottopic = pieces[4][1:]
+
+ formatted = state.db['topicformat'] % {
+ 'chan': state.db['chan'],
+ 'top1': "%s (%s)" % (person(0), pts(0)),
+ 'top3': '/'.join([
+ "%s (%s)" % (person(x), pts(x))
+ for x in range(3) if x < len(state.db['ranks'])
+ ]),
+ 'top3c': ', '.join([
+ "%s (%s) %s" % (person(x), country(x), pts(x))
+ for x in range(3) if x < len(state.db['ranks'])
+ ]),
+ 'top10': ' '.join([
+ "%s (%s)" % (person(x), pts(x))
+ for x in range(10) if x < len(state.db['ranks'])
+ ]),
+ 'top10c': ' '.join([
+ "%s (%s, %s)" % (person(x), pts(x), country(x))
+ for x in range(10) if x < len(state.db['ranks'])
+ ]),
+ 'lastwinner': state.db['lastwinner'],
+ 'lastwon': time.strftime("%b %d", time.gmtime(state.db['lastwon'])),
+ 'target': state.db['target'],
+ 'category': state.db['category'],
+ }
+ if gottopic != formatted:
+ state.getbot().conn.send("TOPIC %s :%s" % (state.db['chan'], formatted))