X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/492f66eae0b39b23f2ac5372468cc3e3d0d05dbd..4e6a0586971c7250b365dcf93f69c33493391435:/modules/trivia.py?ds=sidebyside diff --git a/modules/trivia.py b/modules/trivia.py index 7fdab31..76eb28c 100644 --- a/modules/trivia.py +++ b/modules/trivia.py @@ -10,8 +10,8 @@ modinfo = { 'author': 'Erebus Team', 'license': 'public domain', 'compatible': [0], - 'depends': ['userinfo'], - 'softdeps': ['help'], + 'depends': [], + 'softdeps': ['help','userinfo'], } # preamble @@ -65,7 +65,10 @@ def pts(num): return 0 def country(num, default="??"): - return lib.mod('userinfo').get(person(num), 'country', default=default).upper() + try: + return lib.mod('userinfo').get(person(num), 'country', default=default).upper() + except KeyError: + return default.upper() class MyTimer(timerbase): def __init__(self, *args, **kwargs): @@ -74,6 +77,8 @@ class MyTimer(timerbase): class TriviaState(object): def __init__(self, parent=None, pointvote=False): + self.streak = 0 + self.streak_holder = None if parent is not None: self.gotParent(parent, pointvote) @@ -190,12 +195,12 @@ class TriviaState(object): except Exception as e: msg("DERP! %r" % (e)) - self.db['lastwinner'] = winner - self.db['lastwon'] = time.time() - if self.db['hofpath'] is not None and self.db['hofpath'] != '': self.writeHof() + self.db['lastwinner'] = winner + self.db['lastwon'] = time.time() + self.db['users'] = {} self.db['ranks'] = [] self.savedb() @@ -269,6 +274,8 @@ class TriviaState(object): if self.gameover == True: return self.doGameOver() if qskipped: + self.streak = 0 + self.streak_holder = None self.getchan().fastmsg("\00304Fail! The correct answer was: %s" % (self.hintanswer)) self.missedquestions += 1 else: @@ -426,12 +433,27 @@ def trivia_checkanswer(bot, user, chan, *args): line = ' '.join([str(arg) for arg in args]) if state.checkanswer(line): state.curq = None - 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))) + + if state.streak_holder == user: + state.streak += 1 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.streak >= 3: + bot.fastmsg(chan, "\00312%s\003 broke \00304%s\003's streak of \00307%d\003!" % (user, state.streak_holder, state.streak)) + state.streak_holder = user + state.streak = 1 + + response = "\00312%s\003 has it! The answer was \00312%s\003" % (user, line) + if state.hintanswer.lower() != line.lower(): + response += " (hinted answer: %s)" % (state.hintanswer) + response += ". New score: %d. Rank: %d. Target: %s %s" % (state.addpoint(user), state.rank(user), state.targetuser(user), state.targetpoints(user)) + bot.fastmsg(chan, response) + + if state.streak >= 3: + bot.msg(chan, "\00312%s\003 is on a streak! \00307%d\003 answers correct in a row!" % (user, state.streak)) + 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() @lib.hook(glevel=1, needchan=False, wantchan=True) @@ -482,7 +504,7 @@ def setnextid(bot, user, chan, realtarget, *args): bot.msg(user, "Error: no such QID.") return state.nextqid = qid - bot.msg(user, "Done. Next question is %d: %s" % (qid, state.questions[qid][0])) + bot.msg(user, "Done. Next question is %d: %s" % (qid, state.questions[qid][0]), truncate=True) @lib.hook(glevel=lib.STAFF, needchan=False) @lib.help("*", "sets next question to one not in database") @@ -678,7 +700,8 @@ def questionpause(bot, user, chan, realtarget, *args): bot.msg(user, "Failed to set questionpause.") @lib.hook(glevel=1, needchan=False) -@lib.help("", "finds a qid given a complete question") +@lib.help("[@category] ", "finds a qid given a complete question") +@lib.argsGE(1) def findq(bot, user, chan, realtarget, *args): args = list(args) if args[0].startswith("@"): @@ -702,6 +725,7 @@ def findq(bot, user, chan, realtarget, *args): @lib.hook(glevel=1, needchan=False) @lib.help("[@] ", "finds a qid given a regex or partial question") +@lib.argsGE(1) def findqre(bot, user, chan, realtarget, *args): args = list(args) if args[0].startswith("@"): @@ -745,7 +769,7 @@ def showq(bot, user, chan, realtarget, *args): except: bot.msg(user, "ID not valid.") return - bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1])) + bot.msg(user, "%s: %s*%s" % (qid, q[0], q[1]), True) @lib.hook(('delq', 'deleteq'), glevel=lib.STAFF, needchan=False) @lib.help("[@] ", "removes a question from the database") @@ -760,8 +784,8 @@ def delq(bot, user, chan, realtarget, *args): 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, "Deleted %s*%s" % (backup[0], backup[1]), True) + except Exception as e: bot.msg(user, "Couldn't delete that question. %r" % (e)) @lib.hook(glevel=lib.STAFF, needchan=False)