]> jfr.im git - erebus.git/blobdiff - modules/trivia.py
control - WHOIS command
[erebus.git] / modules / trivia.py
index 4adff017aaf4762eea2df2bb5064398dbe3fdc39..ae9a74ea63ee58759c5569c2fceda585651dfb4b 100644 (file)
@@ -53,8 +53,9 @@ def pts(num):
                return str(state.db['users'][state.db['ranks'][num]]['points'])
        except IndexError:
                return 0
+
 def country(num, default="??"):
-       return lib.mod('userinfo')._get(person(num), 'country', default=default)
+       return lib.mod('userinfo')._get(person(num), 'country', default=default).upper()
 
 class MyTimer(threading._Timer):
        def __init__(self, *args, **kwargs):
@@ -117,16 +118,19 @@ class TriviaState(object):
                answer = self.hintanswer
 
                if self.hintstr is None or self.revealpossibilities is None or self.reveal is None:
+                       oldhintstr = ""
                        self.hintstr = list(re.sub(r'[a-zA-Z0-9]', '*', answer))
                        self.revealpossibilities = range(''.join(self.hintstr).count('*'))
-                       self.reveal = int(''.join(self.hintstr).count('*') * (7/24.0))
+                       self.reveal = int(round(''.join(self.hintstr).count('*') * (7/24.0)))
+               else:
+                       oldhintstr = ''.join(self.hintstr)
 
                for i in range(self.reveal):
                        revealcount = random.choice(self.revealpossibilities)
                        revealloc = findnth(''.join(self.hintstr), '*', revealcount)
                        self.revealpossibilities.remove(revealcount)
                        self.hintstr[revealloc] = answer[revealloc]
-               self.parent.channel(self.chan).bot.fastmsg(self.chan, "\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
+               if oldhintstr != ''.join(self.hintstr): self.getchan().fastmsg("\00304,01Here's a hint: %s" % (''.join(self.hintstr)))
 
                self.hintsgiven += 1
 
@@ -273,7 +277,10 @@ class TriviaState(object):
                else:
                        nextq.append(time.time())
 
-               nextq[1] = nextq[1].lower()
+               if isinstance(nextq[1], basestring):
+                       nextq[1] = nextq[1].lower()
+               else:
+                       nextq[1] = [s.lower() for s in nextq[1]]
 
                qtext = "\00312,01Next up: "
                qtext += "(%5d)" % (random.randint(0,99999))
@@ -365,7 +372,10 @@ def trivia_checkanswer(bot, user, chan, *args):
        line = ' '.join([str(arg) for arg in args])
        if state.checkanswer(line):
                state.curq = None
-               bot.fastmsg(chan, "\00312%s\003 has it! The answer was \00312%s\003. New score: %d. Rank: %d. Target: %s (%s)." % (user, line, state.addpoint(user), state.rank(user), state.targetuser(user), state.targetpoints(user)))
+               if state.hintanswer.lower() == line.lower():
+                       bot.fastmsg(chan, "\00312%s\003 has it! The answer was \00312%s\003. New score: %d. Rank: %d. Target: %s (%s)." % (user, line, state.addpoint(user), state.rank(user), state.targetuser(user), state.targetpoints(user)))
+               else:
+                       bot.fastmsg(chan, "\00312%s\003 has it! The answer was \00312%s\003 (hinted answer: %s). New score: %d. Rank: %d. Target: %s (%s)." % (user, line, state.hintanswer, state.addpoint(user), state.rank(user), state.targetuser(user), state.targetpoints(user)))
                if state.hintsgiven == 0:
                        bot.msg(chan, "\00312%s\003 got an extra point for getting it before the hints! New score: %d." % (user, state.addpoint(user)))
                state.nextquestion()
@@ -519,7 +529,7 @@ def top10(bot, user, chan, realtarget, *args):
        max = len(state.db['ranks'])
        if max > 10:
                max = 10
-       replylist = ', '.join(["%s (%s) %s" % (person(x), country(x, "unknown"), pts(x)) for x in range(max)])
+       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)
@@ -620,33 +630,33 @@ def addq(bot, user, chan, realtarget, *args):
 
 @lib.hook(needchan=False)
 def triviahelp(bot, user, chan, realtarget, *args):
-       bot.msg(user,             "START")
-       bot.msg(user,             "TOP10")
-       bot.msg(user,             "POINTS        [<user>]")
-       bot.msg(user,             "RANK          [<user>]")
-       bot.msg(user,             "BADQ          <reason> (include info to identify question)")
+       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.msg(user,         "SKIP                            (>=KNOWN)")
-               bot.msg(user,         "STOP                            (>=KNOWN)")
-               bot.msg(user,         "FINDQ         <question>        (>=KNOWN)")
+               bot.slowmsg(user,         "SKIP                            (>=KNOWN)")
+               bot.slowmsg(user,         "STOP                            (>=KNOWN)")
+               bot.slowmsg(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]")
-                       bot.msg(user,     "BADQS                           (>=STAFF)")
-                       bot.msg(user,     "CLEARBADQS                      (>=STAFF)")
-                       bot.msg(user,     "DELBADQ       <reportid>        (>=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,     "DELETEQ       <q>*<a>           (>=STAFF)  [aka DELQ]")
+                       bot.slowmsg(user,     "BADQS                           (>=STAFF)")
+                       bot.slowmsg(user,     "CLEARBADQS                      (>=STAFF)")
+                       bot.slowmsg(user,     "DELBADQ       <reportid>        (>=STAFF)")
                        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)")
+                               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...")
+#      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)