+ bot.msg(replyto, "%s is in %d place (%s points). Target is: %s (%s points)." % (who, state.rank(who), state.points(who), state.targetuser(who), state.targetpoints(who)))
+
+@lib.hook('top10', needchan=False)
+def cmd_top10(bot, user, chan, realtarget, *args):
+ if len(state.db['ranks']) == 0:
+ return bot.msg(state.db['chan'], "No one is ranked!")
+
+ replylist = []
+ for nick in state.db['ranks'][0:10]:
+ user = state.db['users'][nick]
+ replylist.append("%s (%s)" % (user['realnick'], user['points']))
+ bot.msg(state.db['chan'], ', '.join(replylist))
+
+@lib.hook('settarget', glevel=lib.ADMIN, needchan=False)
+def cmd_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('vote', needchan=False)
+def cmd_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('maxmissed', glevel=lib.ADMIN, needchan=False)
+def cmd_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('hinttimer', glevel=lib.ADMIN, needchan=False)
+def cmd_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('hintnum', glevel=lib.ADMIN, needchan=False)
+def cmd_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('questionpause', glevel=lib.ADMIN, needchan=False)
+def cmd_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('findq', glevel=1, needchan=False)
+def cmd_findquestion(bot, user, chan, realtarget, *args):
+ matches = [str(i) for i in range(len(state.db['questions'])) if state.db['questions'][i][0] == ' '.join(args)] #TODO looser equality check
+ 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('delq', glevel=lib.STAFF, needchan=False)
+@lib.hook('deleteq', glevel=lib.STAFF, needchan=False)
+def cmd_deletequestion(bot, user, chan, realtarget, *args):
+ try:
+ backup = state.db['questions'][int(args[0])]
+ del state.db['questions'][int(args[0])]
+ bot.msg(user, "Deleted %s*%s" % (backup[0], backup[1]))
+ except:
+ bot.msg(user, "Couldn't delete that question.")
+
+@lib.hook('addq', glevel=lib.STAFF, needchan=False)
+def cmd_addquestion(bot, user, chan, realtarget, *args):
+ line = ' '.join([str(arg) for arg in args])
+ linepieces = line.split('*')
+ if len(linepieces) < 2:
+ bot.msg(user, "Error: need <question>*<answer>")
+ return
+ question = linepieces[0].strip()
+ answer = linepieces[1].strip()
+ state.db['questions'].append([question, answer])
+ bot.msg(user, "Done. Question is #%s" % (len(state.db['questions'])-1))
+
+
+@lib.hook('triviahelp', needchan=False)
+def cmd_triviahelp(bot, user, chan, realtarget, *args):
+ if user.glevel == 0:
+ bot.msg(user, "START")
+ bot.msg(user, "TOP10")
+ bot.msg(user, "POINTS [<user>]")
+ bot.msg(user, "RANK [<user>]")
+ else:
+ bot.msg(user, "START (ANYONE )")
+ bot.msg(user, "TOP10 (ANYONE )")
+ bot.msg(user, "POINTS [<user>] (ANYONE )")
+ bot.msg(user, "RANK [<user>] (ANYONE )")
+ if user.glevel >= 1:
+ bot.msg(user, "SKIP (>=KNOWN)")
+ bot.msg(user, "STOP (>=KNOWN)")
+ bot.msg(user, "FINDQ <question> (>=KNOWN)")
+ if user.glevel >= lib.STAFF:
+ bot.msg(user, "GIVE <user> [<points>] (>=STAFF)")
+ bot.msg(user, "SETNEXT <q>*<a> (>=STAFF)")
+ bot.msg(user, "ADDQ <q>*<a> (>=STAFF)")
+ bot.msg(user, "DELETEQ <q>*<a> (>=STAFF) [aka DELQ]")
+ if user.glevel >= lib.ADMIN:
+ bot.msg(user, "SETTARGET <points> (>=ADMIN)")
+ bot.msg(user, "MAXMISSED <questions> (>=ADMIN)")
+ bot.msg(user, "HINTTIMER <float seconds> (>=ADMIN)")
+ bot.msg(user, "HINTNUM <hints> (>=ADMIN)")
+ bot.msg(user, "QUESTIONPAUSE <float seconds> (>=ADMIN)")
+
+@lib.hooknum(417)
+def num_417(bot, textline):
+ bot.msg(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'],
+ 'top': state.db['users'][state.db['ranks'][0]]['realnick'],
+ 'top3': '/'.join([state.db['users'][state.db['ranks'][x]]['realnick'] for x in range(3) if x < len(state.db['ranks'])]),
+ 'topscore': state.db['users'][state.db['ranks'][0]]['points'],
+ 'target': state.db['target'],
+ }
+ 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+":
+ randnum1 = random.randrange(0, 11)
+ randnum2 = random.randrange(0, 11)
+ newq[0] = "What is %d + %d?" % (randnum1, randnum2)
+ newq[1] = spellout(randnum1+randnum2)
+ return newq
+
+def spellout(num):
+ return [
+ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
+ "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
+ "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
+ ][num]