X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/2520caee2c7bf7d1e3c233c7fa37998ae5b73bf4..77a265cdce6e50ad965401f58a1a521f96b5377b:/modules/trivia.py diff --git a/modules/trivia.py b/modules/trivia.py index 32b4329..f7e6a69 100644 --- a/modules/trivia.py +++ b/modules/trivia.py @@ -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]