]> jfr.im git - erebus.git/blobdiff - modules/trivia.py
trivia bugfix
[erebus.git] / modules / trivia.py
index 32b43293d62b38e4ef9324b8d15604e23441b315..f7e6a698716b7d269add3234bec586cd72440102 100644 (file)
@@ -195,6 +195,7 @@ class TriviaState(object):
                self.nextquestion() #start the game!
 
        def nextquestion(self, qskipped=False, iteration=0, skipwait=False):
+               self.curq = None
                if self.gameover == True:
                        return self.doGameOver()
                if qskipped:
@@ -218,15 +219,16 @@ class TriviaState(object):
 
                if self.missedquestions > self.db['maxmissedquestions']:
                        stop()
-                       self.getbot().msg(self.getchan(), "%d questions unanswered! Stopping the game.")
+                       self.getbot().msg(self.getchan(), "%d questions unanswered! Stopping the game." % (self.missedquestions))
+                       return
 
                if skipwait:
-                       self._nextquestion(qskipped, iteration)
+                       self._nextquestion(iteration)
                else:
-                       self.nextquestiontimer = threading.Timer(self.db['questionpause'], self._nextquestion, args=[qskipped, iteration])
+                       self.nextquestiontimer = threading.Timer(self.db['questionpause'], self._nextquestion, args=[iteration])
                        self.nextquestiontimer.start()
 
-       def _nextquestion(self, qskipped, iteration):
+       def _nextquestion(self, iteration):
                if self.nextq is not None:
                        nextqid = None
                        nextq = self.nextq
@@ -336,6 +338,7 @@ state = TriviaState()
 def trivia_checkanswer(bot, user, chan, *args):
        line = ' '.join([str(arg) for arg in args])
        if state.checkanswer(line):
+               state.curq = None
                bot.msg(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.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)))
@@ -343,7 +346,7 @@ def trivia_checkanswer(bot, user, chan, *args):
 
 @lib.hook('points', needchan=False)
 def cmd_points(bot, user, chan, realtarget, *args):
-       if realtarget == chan.name: replyto = chan
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        if len(args) != 0: who = args[0]
@@ -391,10 +394,15 @@ def cmd_skip(bot, user, chan, realtarget, *args):
 
 @lib.hook('start', needchan=False)
 def cmd_start(bot, user, chan, realtarget, *args):
-       if realtarget == chan.name: replyto = chan
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
+       if chan is not None and chan.name != state.db['chan']:
+               bot.msg(replyto, "That command isn't valid here.")
+               return
+
        if state.curq is None and state.pointvote is None and state.nextquestiontimer is None:
+               bot.msg(state.db['chan'], "%s has started the game!" % (user))
                state.nextquestion(skipwait=True)
        elif state.pointvote is not None:
                bot.msg(replyto, "There's a vote in progress!")
@@ -410,8 +418,9 @@ def cmd_stop(bot, user, chan, realtarget, *args):
 
 def stop():
        try:
-               if state.curq is not None:
+               if state.curq is not None or state.nextq is not None:
                        state.curq = None
+                       state.nextq = None
                        try:
                                state.steptimer.cancel()
                        except Exception as e:
@@ -464,7 +473,7 @@ def cmd_delbadq(bot, user, chan, realtarget, *args):
 
 @lib.hook('rank', needchan=False)
 def cmd_rank(bot, user, chan, realtarget, *args):
-       if realtarget == chan.name: replyto = chan
+       if chan is not None and realtarget == chan.name: replyto = chan
        else: replyto = user
 
        if len(args) != 0: who = args[0]