+ if len(args) != 0: who = args[0]
+ else: who = user
+
+ bot.msg(replyto, "%s is in %d place (%s points). Target is: %s %s" % (who, state.rank(who), state.points(who), state.targetuser(who), state.targetpoints(who)))
+
+@lib.hook(needchan=False)
+@lib.help(None, "shows top10 list")
+def top10(bot, user, chan, realtarget, *args):
+ if len(state.db['ranks']) == 0:
+ return bot.msg(state.db['chan'], "No one is ranked!")
+
+ max = len(state.db['ranks'])
+ if max > 10:
+ max = 10
+ replylist = ', '.join(["%s (%s) %s" % (person(x), country(x), pts(x)) for x in range(max)])
+ bot.msg(state.db['chan'], "Top 10: %s" % (replylist))
+
+@lib.hook(glevel=lib.ADMIN, needchan=False)
+@lib.help("<target score>", "changes the target score for this round")
+def settarget(bot, user, chan, realtarget, *args):
+ try:
+ state.db['target'] = int(args[0])
+ bot.msg(state.db['chan'], "Target has been changed to %s points!" % (state.db['target']))
+
+ if state.pointvote is not None:
+ state.pointvote.cancel()
+ state.pointvote = None
+ bot.msg(state.db['chan'], "Vote has been cancelled!")
+ except Exception as e:
+ print(e)
+ bot.msg(user, "Failed to set target.")
+
+@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)")
+
+@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))
+
+
+def specialQuestion(oldq):
+ newq = [oldq[0], oldq[1]]
+ qtype = oldq[0].upper()
+
+ if qtype == "!MONTH":
+ newq[0] = "What month is it currently (in UTC)?"
+ newq[1] = time.strftime("%B", time.gmtime()).lower()
+ elif qtype == "!MATH+":
+ try:
+ maxnum = int(oldq[1])
+ except ValueError:
+ maxnum = 10
+ randnum1 = random.randrange(0, maxnum+1)
+ randnum2 = random.randrange(0, maxnum+1)
+ newq[0] = "What is %d + %d?" % (randnum1, randnum2)
+ newq[1] = spellout(randnum1+randnum2)
+ elif qtype == "!ALGEBRA+":
+ try:
+ num1, num2 = [int(i) for i in oldq[1].split('!')]
+ except ValueError:
+ num1, num2 = 10, 10
+ randnum1 = random.randrange(0, num1+1)
+ randnum2 = random.randrange(randnum1, num2+1)
+ newq[0] = "What is x? %d = %d + x" % (randnum2, randnum1)
+ newq[1] = spellout(randnum2-randnum1)
+ else: pass #default to not modifying
+ return newq
+
+def spellout(num):
+ ones = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
+ teens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
+ tens = ['', '', 'twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
+
+ if num == 0:
+ return 'zero'
+
+ ihundreds = num / 100
+ itens = num % 100 / 10
+ iones = num % 10
+ buf = []
+
+ if ihundreds > 0:
+ buf.append("%s hundred" % (ones[ihundreds]))
+ if itens > 1:
+ buf.append(tens[itens])
+ if itens == 1:
+ buf.append(teens[iones])
+ elif iones > 0:
+ buf.append(ones[iones])
+ return ' '.join(buf)
+# return [
+# "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
+# "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
+# "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
+# ][num]