From 0a67df08a79327d544d96fd1c0acbeae1fa2bcb4 Mon Sep 17 00:00:00 2001 From: rootcoma Date: Wed, 6 Nov 2013 12:50:44 -0800 Subject: [PATCH] adding '.' other hint command --- config.py | 9 +++++++-- plugin.py | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index d26a3ae..da6c1f3 100644 --- a/config.py +++ b/config.py @@ -30,6 +30,11 @@ conf.registerChannelValue(TriviaTime, 'quizfile', ) # timeout, number of hints, values +conf.registerChannelValue(TriviaTime, 'showOtherHintCommand', + registry.NormalizedString(""".""", + """The command to show alternative hints""") + ) + conf.registerChannelValue(TriviaTime, 'showHintCommandKAOS', registry.NormalizedString(""",""", """The command for showing the remaining KAOS""") @@ -122,7 +127,7 @@ conf.registerChannelValue(TriviaTime, 'charMask', # victory text, help messages, formatting conf.registerChannelValue(TriviaTime, 'starting', - registry.NormalizedString("""Another epic round of tivia is about to begin.""", + registry.NormalizedString("""Another epic round of trivia is about to begin.""", """Message shown when trivia starts""") ) @@ -142,7 +147,7 @@ conf.registerChannelValue(TriviaTime, 'alreadyStarted', ) conf.registerChannelValue(TriviaTime, 'answeredKAOS', - registry.NormalizedString("""\x02%s\x02 gets \x02d\x02 points for: \x02%s\x02""", + registry.NormalizedString("""\x02%s\x02 gets \x02%d\x02 points for: \x02%s\x02""", """Message for one correct guess during KAOS""") ) diff --git a/plugin.py b/plugin.py index 9b0a2bc..232f0ed 100644 --- a/plugin.py +++ b/plugin.py @@ -71,6 +71,12 @@ class TriviaTime(callbacks.Plugin): """ Catches all PRIVMSG, including channels communication """ + username = str.lower(msg.nick) + try: + user = ircdb.users.getUser(msg.prefix) # rootcoma!~rootcomaa@unaffiliated/rootcoma + username = str.lower(user.name) + except KeyError: + pass channel = ircutils.toLower(msg.args[0]) # Make sure that it is starting inside of a channel, not in pm if not irc.isChannel(channel): @@ -81,6 +87,8 @@ class TriviaTime(callbacks.Plugin): # Look for command to list remaining KAOS if msg.args[1] == self.registryValue('showHintCommandKAOS',channel): self.games[channel].getRemainingKAOS() + elif msg.args[1] == self.registryValue('showOtherHintCommand', channel): + self.games[channel].getOtherHint(username) else: # check the answer self.games[channel].checkAnswer(msg) @@ -648,6 +656,7 @@ class TriviaTime(callbacks.Plugin): # reset stats self.shownHint = False self.skipVoteCount = {} + self.shownOtherHint = {} self.streak = 0 self.lastWinner = '' self.hintsCounter = 0 @@ -858,7 +867,7 @@ class TriviaTime(callbacks.Plugin): divider = int(len(ans) * ratio) if divider > 3: divider = 3 - if divider > len(ans): + if divider >= len(ans): divider = len(ans)-1 hints += ans[:divider] masked = ans[divider:] @@ -867,7 +876,7 @@ class TriviaTime(callbacks.Plugin): divider = int(len(ans) * ratio) if divider > 3: divider = 3 - if divider > len(ans): + if divider >= len(ans): divider = len(ans)-1 lettersInARow=divider-1 maskedInARow=0 @@ -896,6 +905,29 @@ class TriviaTime(callbacks.Plugin): hints += ']' return hints + def getOtherHintString(self): + hintRatio = self.registryValue('hintShowRatio') # % to show each hint + ratio = float(hintRatio * .01) + timeElapsed = float(time.time() - self.askedAt) + showPercentage = float((timeElapsed + (self.registryValue('timeout', self.channel)/2)) / (self.registryValue('timeout', self.channel) * 2)) + charMask = self.registryValue('charMask', self.channel) + if len(self.answers) > 1 or len(self.answers) < 1: + return + ans = self.answers[0] + divider = int(len(ans) * ratio * showPercentage + 1) + if divider >= len(ans): + divider = len(ans)-1 + hints = 'Hint: \x02\x0312' + hints += ans[:divider] + return hints + + def getOtherHint(self, username): + if username in self.shownOtherHint: + return + self.shownOtherHint[username] = True + if len(self.answers) == 1: + self.sendMessage(self.getOtherHintString()) + def getRemainingKAOS(self): if len(self.answers) > 1: if self.shownHint == False: @@ -912,6 +944,7 @@ class TriviaTime(callbacks.Plugin): self.sendMessage('Hint %s: %s' % (self.hintsCounter, hints), 1, 9) #reset hint shown self.shownHint = False + self.shownOtherHint = {} timeout = 2 if len(self.answers) > 1: @@ -938,6 +971,7 @@ class TriviaTime(callbacks.Plugin): self.questionOver = False self.shownHint = False self.skipVoteCount = {} + self.shownOtherHint = {} self.question = '' self.answers = [] self.alternativeAnswers = []