Jeopardy: skip/report, other minor improvements.

This commit is contained in:
oddluck 2020-02-05 12:08:04 +00:00
parent 51ade05c88
commit ac6e93c738

View File

@ -259,6 +259,7 @@ class Jeopardy(callbacks.Plugin):
return return
self.id = None self.id = None
self.hints = 0 self.hints = 0
self.revealed = 0
self.num -= 1 self.num -= 1
self.numAsked += 1 self.numAsked += 1
q = self.questions.pop(len(self.questions)-1).split('*') q = self.questions.pop(len(self.questions)-1).split('*')
@ -544,11 +545,18 @@ class Jeopardy(callbacks.Plugin):
channel = msg.channel channel = msg.channel
if self.registryValue('requireOps', channel) and msg.nick not in irc.state.channels[channel].ops and not ircdb.checkCapability(msg.prefix, 'admin'): if self.registryValue('requireOps', channel) and msg.nick not in irc.state.channels[channel].ops and not ircdb.checkCapability(msg.prefix, 'admin'):
return return
try: if self.games[channel]:
self.games[channel].active = False if self.games[channel].active:
self.games[channel].stop() if self.games[channel].correct:
irc.reply(_('Jeopardy! stopped.')) irc.reply("Jeopardy! stopped.")
except: else:
irc.reply("Jeopardy! stopped. (Answer: {0})".format(self.games[channel].a[0]))
try:
self.games[channel].active = False
self.games[channel].stop()
except:
return
else:
return return
stop = wrap(stop, ['channel']) stop = wrap(stop, ['channel'])
@ -625,7 +633,7 @@ class Jeopardy(callbacks.Plugin):
channel = msg.channel channel = msg.channel
if channel in self.games: if channel in self.games:
if self.games[channel].active: if self.games[channel].active:
irc.reply(self.games[channel].question) irc.reply(self.games[channel].question, prefixNick=False)
else: else:
return return
else: else:
@ -635,12 +643,20 @@ class Jeopardy(callbacks.Plugin):
def hint(self, irc, msg, args): def hint(self, irc, msg, args):
""" """
Repeat the latest hint. Repeat the latest hint. If game set for no hints, show the blanked out answer.
""" """
channel = msg.channel channel = msg.channel
if channel in self.games: if channel in self.games:
if self.games[channel].active and self.games[channel].numHints > 0: if self.games[channel].active and self.games[channel].numHints > 0:
irc.reply(self.games[channel].currentHint) irc.reply("Hint: {0}".format(self.games[channel].currentHint), prefixNick=False)
elif self.games[channel].active and self.games[channel].numHints == 0:
blankChar = self.registryValue('blankChar', channel)
blank = re.sub('\w', blankChar, self.games[channel].a[0])
irc.reply("HINT: {0}".format(blank), prefixNick=False)
if self.games[channel].revealed == 0:
reduction = self.registryValue('hintReduction', channel)
self.games[channel].p -= int(self.games[channel].p * reduction)
self.games[channel].revealed +=1
else: else:
return return
else: else:
@ -648,4 +664,58 @@ class Jeopardy(callbacks.Plugin):
hint = wrap(hint) hint = wrap(hint)
def report(self, irc, msg, args):
"""
Report the current question as invalid and skip to the next one. Only use this command if a question is unanswerable (e.g. audio/video clues)
"""
channel = msg.channel
if self.registryValue('requireOps', channel) and msg.nick not in irc.state.channels[channel].ops and not ircdb.checkCapability(msg.prefix, 'admin'):
return
if channel in self.games:
if self.games[channel].active:
r = requests.post('{0}/api/invalid'.format(self.jserviceUrl), data = {'id':self.games[channel].id})
if r.status_code == 200:
irc.reply('Question successfully reported. (Answer: {0})'.format(self.games[channel].a[0]), prefixNick=False)
else:
irc.reply('Error. Question not reported. (Answer: {0})'.format(self.games[channel].a[0]), prefixNick=False)
self.games[channel].unanswered = 0
self.games[channel].correct = True
self.games[channel].answered += 1
self.games[channel].newquestion()
try:
schedule.removeEvent('next_%s' % channel)
except KeyError:
pass
else:
return
else:
return
report = wrap(report)
def skip(self, irc, msg, args):
"""
Skip the current question.
"""
channel = msg.channel
if self.registryValue('requireOps', channel) and msg.nick not in irc.state.channels[channel].ops and not ircdb.checkCapability(msg.prefix, 'admin'):
return
if channel in self.games:
if self.games[channel].active:
irc.reply('Skipping question. (Answer: {0})'.format(self.games[channel].a[0]), prefixNick=False)
self.games[channel].unanswered = 0
self.games[channel].correct = True
self.games[channel].answered += 1
self.games[channel].newquestion()
try:
schedule.removeEvent('next_%s' % channel)
except KeyError:
pass
else:
return
else:
return
skip = wrap(skip)
Class = Jeopardy Class = Jeopardy