+ 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)")
+
+@lib.hooknum(332) # topic is...
+@lib.hooknum(331) # no topic set
+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(bot.parent.cfg.get('trivia', 'topiccommand', default="TOPIC %(chan)s :%(topic)s") % {'chan': state.db['chan'], 'topic': formatted})