Jeopardy: add timeReplies config

This commit is contained in:
oddluck 2020-02-19 10:48:32 +00:00
parent 0e11f766a5
commit ad5d33797d
3 changed files with 19 additions and 4 deletions

View File

@ -183,6 +183,11 @@ config [channel #channel] plugins.jeopardy.showHints True
``` ```
^ Show hint messages automatically. Overrides showTime ^ Show hint messages automatically. Overrides showTime
```
config [channel #channel] plugins.jeopardy.timeReplies 1
```
^ Number of time remaining replies to show when showHints False and showTime True
## Templates ## Templates

View File

@ -56,6 +56,10 @@ conf.registerChannelValue(Jeopardy, 'numHints',
registry.PositiveInteger(3, _("""The number of hints to be given for registry.PositiveInteger(3, _("""The number of hints to be given for
each question"""))) each question""")))
conf.registerChannelValue(Jeopardy, 'timeReplies',
registry.PositiveInteger(1, _("""The number of time remaining replies
if showHints False and showTime True""")))
conf.registerChannelValue(Jeopardy, 'delay', conf.registerChannelValue(Jeopardy, 'delay',
registry.Integer(4, _("""The number of seconds to increase the delay registry.Integer(4, _("""The number of seconds to increase the delay
between questions"""))) between questions""")))

View File

@ -121,6 +121,7 @@ class Jeopardy(callbacks.Plugin):
self.stop_template = Template(self.registryValue("template.stop", channel)) self.stop_template = Template(self.registryValue("template.stop", channel))
self.time_template = Template(self.registryValue("template.time", channel)) self.time_template = Template(self.registryValue("template.time", channel))
self.timeout = timeout self.timeout = timeout
self.timeReplies = self.registryValue('timeReplies', self.channel)
self.total = num self.total = num
self.unanswered = 0 self.unanswered = 0
if not os.path.exists(self.directory): if not os.path.exists(self.directory):
@ -325,7 +326,10 @@ class Jeopardy(callbacks.Plugin):
self.correct = False self.correct = False
self.reply(self.question) self.reply(self.question)
self.endTime = time.time() + self.timeout self.endTime = time.time() + self.timeout
self.waitTime = self.timeout / (self.numHints + 1) if self.showHints:
self.waitTime = self.timeout / (self.numHints + 1)
else:
self.waitTime = self.timeout / (self.timeReplies + 1)
if self.registryValue('keepHistory', self.channel): if self.registryValue('keepHistory', self.channel):
self.history[self.channel].append(int(self.id)) self.history[self.channel].append(int(self.id))
if self.timeout > 0: if self.timeout > 0:
@ -338,7 +342,8 @@ class Jeopardy(callbacks.Plugin):
self.hint() self.hint()
elif self.timeout > 0 and self.showHints or self.showTime: elif self.timeout > 0 and self.showHints or self.showTime:
eventTime = time.time() + self.waitTime eventTime = time.time() + self.waitTime
schedule.addEvent(event, eventTime, 'event_%s' % self.channel) if eventTime < self.endTime:
schedule.addEvent(event, eventTime, 'event_%s' % self.channel)
elif self.showBlank: elif self.showBlank:
self.hint() self.hint()
if self.numAsked > 1 and self.delay > 0: if self.numAsked > 1 and self.delay > 0:
@ -404,7 +409,8 @@ class Jeopardy(callbacks.Plugin):
def event(): def event():
self.timedEvent() self.timedEvent()
eventTime = time.time() + self.waitTime eventTime = time.time() + self.waitTime
schedule.addEvent(event, eventTime, 'event_%s' % self.channel) if eventTime < self.endTime:
schedule.addEvent(event, eventTime, 'event_%s' % self.channel)
def end(self): def end(self):
@ -453,7 +459,7 @@ class Jeopardy(callbacks.Plugin):
if self.timeout > 0: if self.timeout > 0:
eventTime = time.time() + self.waitTime eventTime = time.time() + self.waitTime
reply = self.hint_template.render(hint = self.currentHint, time = round(self.endTime - time.time())) reply = self.hint_template.render(hint = self.currentHint, time = round(self.endTime - time.time()))
if self.showHints or self.showTime: if self.showHints or self.showTime and eventTime < self.endTime:
schedule.addEvent(event, eventTime, 'event_%s' % self.channel) schedule.addEvent(event, eventTime, 'event_%s' % self.channel)
else: else:
reply = self.hint_template.render(hint = self.currentHint, time = None) reply = self.hint_template.render(hint = self.currentHint, time = None)