Added a timeout list for extra hint command. (Issue #315)

This commit is contained in:
Yizhe Shen 2015-01-27 20:43:12 -05:00
parent 8a90d9c406
commit fe100c52eb
2 changed files with 19 additions and 5 deletions

View File

@ -56,6 +56,11 @@ conf.registerChannelValue(TriviaTime.general, 'globalStats',
"""Stats are global across all channels""")
)
conf.registerChannelValue(TriviaTime.hints, 'extraHintTime',
registry.Integer(90,
"""Number of seconds a user must wait between uses of the extra hint command.""")
)
conf.registerChannelValue(TriviaTime.hints, 'vowelsHint',
registry.Boolean(True,
"""Show all vowels on the third hint. If false, random letters will be shown instead""")

View File

@ -134,6 +134,7 @@ class TriviaTime(callbacks.Plugin):
Catches all PRIVMSG, including channels communication
"""
username = self.getUsername(msg.nick, msg.prefix)
usernameCanonical = ircutils.toLower(username)
channel = msg.args[0]
# Make sure that it is starting inside of a channel, not in pm
if not irc.isChannel(channel):
@ -143,15 +144,22 @@ class TriviaTime(callbacks.Plugin):
channelCanonical = ircutils.toLower(channel)
otherHintCommand = self.registryValue('commands.extraHint', channel)
extraHintTime = self.registryValue('hints.extraHintTime', channel)
game = self.getGame(irc, channel)
if game is not None:
# Look for command to list remaining KAOS
if msg.args[1] == otherHintCommand and game.question.find("KAOS:") == 0:
game.getRemainingKAOS()
# Check for extra hint command
if msg.args[1] == otherHintCommand:
if game.question.find("KAOS:") == 0:
game.getRemainingKAOS()
else:
game.getOtherHint()
game.hintTimeoutList.setTimeout(extraHintTime)
if not game.questionOver:
if game.hintTimeoutList.has(usernameCanonical):
self.reply(irc, msg, 'You must wait %d seconds to be able to use the extra hints command.' % (game.hintTimeoutList.getTimeLeft(usernameCanonical)))
else:
game.hintTimeoutList.append(usernameCanonical)
game.getOtherHint()
else:
# check the answer
game.checkAnswer(msg)
@ -1582,6 +1590,7 @@ class TriviaTime(callbacks.Plugin):
# reset stats
self.skips = TimeoutList(self.registryValue('skip.skipTime', channel))
self.hintTimeoutList = TimeoutList(self.registryValue('hints.extraHintTime', channel))
self.stopPending = False
self.shownHint = False
self.questionRepeated = False