+@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][0] == "@":
+ 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][0] == "@":
+ 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]))
+