if user in self.db['streaks']:
return self.db['streaks'][user]
else:
- return 0
+ return [0,0]
def targetuser(self, user):
if len(self.db['ranks']) == 0: return "no one is ranked!"
bot.fastmsg(chan, response)
user_lower = str(user).lower()
+ new_max_streak = ""
if user_lower not in state.db['streaks']:
- state.db['streaks'][user_lower] = 0
- if state.streak > state.db['streaks'][user_lower]:
- state.db['streaks'][user_lower] = state.streak
+ state.db['streaks'][user_lower] = [0, 0]
+ if state.streak > state.db['streaks'][user_lower][0]:
+ state.db['streaks'][user_lower] = [state.streak, time.time()]
+ new_max_streak = " That's a new record for them!"
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))
+ bot.msg(chan, "\00312%s\003 is on a streak! \00307%d\003 answers correct in a row!%s" % (user, state.streak, new_max_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)))
bot.msg(user, "Failed to set questionpause.")
@lib.hook(glevel=1, needchan=False)
-@lib.help("[@category] <question>", "finds a question (qid) given a (partial) question")
+@lib.help("[@<category>] <question>", "finds a question (qid) given a (partial) question")
@lib.argsGE(1)
def findq(bot, user, chan, realtarget, *args):
args = list(args)
if len(args) != 0: who = args[0]
else: who = user
- bot.msg(replyto, "%s's highest streak is %d" % (who, state.get_streak(who)))
+ streak = state.get_streak(who)
+ bot.msg(replyto, "%s's highest streak is %d, set %s" % (who, streak[0], time.strftime("%d %b %Y %H:%M:%S %Z", time.gmtime(streak[1]))))
@lib.hook(needchan=False)
@lib.help(None, "shows top streaks of all time")
def topstreaks(bot, user, chan, realtarget, *args):
+ time_format = "%Y-%m-%d"
db = state.db['streaks']
- streaks = [(k, db[k]) for k in db.keys()]
+ streaks = [(nick, db[nick][0], db[nick][1]) for nick in db.keys()]
streaks.sort(key=lambda v: v[1], reverse=True)
- return "Top streaks of all time: %s (%d), %s (%d), %s (%d)." % (streaks[0][0], streaks[0][1], streaks[1][0], streaks[1][1], streaks[2][0], streaks[2][1])
+ return "Top streaks of all time: %s (%d %s), %s (%d %s), %s (%d %s)." % (streaks[0][0], streaks[0][1], time.strftime(time_format, time.gmtime(streaks[0][2])), streaks[1][0], streaks[1][1], time.strftime(time_format, time.gmtime(streaks[1][2])), streaks[2][0], streaks[2][1], time.strftime(time_format, time.gmtime(streaks[2][2])))
@lib.hook(glevel=lib.MANAGER, needchan=False)
-@lib.help("<nick> <new streak>", "set a user's max streak")
-@lib.argsEQ(2)
+@lib.help("<nick> <new streak> [<timestamp>]", "set a user's max streak")
+@lib.argsGE(2)
def setstreak(bot, user, chan, realtarget, *args):
temp = 0
target = args[0].lower()
try:
newstreak = int(args[1])
except ValueError:
- return "Syntax: SETSTREAK <nick> <new streak>"
+ return "Error: <new streak> must be integer"
+ timestamp = time.time()
+ if len(args) > 2:
+ try:
+ timestamp = int(args[2])
+ except ValueError:
+ return "Error: <timestamp> must be integer (unix timestamp)"
if target in state.db['streaks']:
temp = state.db['streaks'][target]
if newstreak == 0:
del state.db['streaks'][target]
if newstreak > 0:
- state.db['streaks'][target] = newstreak
- return "Done. Streak used to be %d" % (temp)
+ state.db['streaks'][target] = [newstreak, timestamp]
+ return "Done. Streak used to be %d set %d" % (temp[0], temp[1])
@lib.hook(needchan=False)
def triviahelp(bot, user, chan, realtarget, *args):