Skip to content

Commit

Permalink
Merge pull request #18 from loljoho/feat/14-kaos-questions
Browse files Browse the repository at this point in the history
Feat/14 kaos questions
  • Loading branch information
loljoho committed Mar 3, 2019
2 parents a715902 + df53680 commit 8eb9c91
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def configure(advanced):
"""Seconds between KAOS hints""")
)

conf.registerChannelValue(TriviaTime.kaos, 'frequencyKAOS',
registry.Integer(5,
"""Number of rounds between KAOS questions""")
)

conf.registerChannelValue(TriviaTime.general, 'waitTime',
registry.Integer(20,
"""Seconds between the end of one question and the start of another""")
Expand Down
31 changes: 27 additions & 4 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,12 @@ def nextQuestion(self):
# Update DB with new round number
self.storage.updateGame(self.channel, self.numAsked)

# Retrieve new question from DB
retrievedQuestion = self.retrieveQuestion()
# Retrieve KAOS question from DB
if self.numAsked % self.registryValue('kaos.frequencyKAOS') == 0:
retrievedQuestion = self.retrieveQuestion(True)
# Retrieve new regular question from DB
else:
retrievedQuestion = self.retrieveQuestion(False)
self.questionID = retrievedQuestion['id']
self.questionType = retrievedQuestion['type']
self.question = retrievedQuestion['question']
Expand Down Expand Up @@ -580,9 +584,12 @@ def removeEvent(self):
except KeyError:
pass

def retrieveQuestion(self):
def retrieveQuestion(self, isKaos=False):
# Retrieve and parse question data from database
rawData = self.storage.getRandomQuestionNotAsked(self.channel, self.roundStartedAt)
if isKaos == True:
rawData = self.storage.getRandomKAOS(self.channel)
else:
rawData = self.storage.getRandomQuestionNotAsked(self.channel, self.roundStartedAt)
rawQuestion = rawData['question']
netTimesAnswered = rawData['num_answered'] - rawData['num_missed']
questionParts = rawQuestion.split('*')
Expand Down Expand Up @@ -900,6 +907,22 @@ def dropLevelTable(self):
pass
c.close()

def getRandomKAOS(self, channel):
c = self.conn.cursor()
c.execute('''SELECT *
FROM triviaquestion
WHERE deleted=0 AND
lower(substr(question,1,4))=? AND
id NOT IN

This comment has been minimized.

Copy link
@loljoho

loljoho Mar 31, 2019

Author Owner

Pretty sure the nested SELECT here gives us our culprit when all the KAOS questions have already been asked.

(SELECT tl.line_num
FROM triviagameslog tl
WHERE tl.channel_canonical=?)
ORDER BY random() LIMIT 1''',
('kaos',ircutils.toLower(channel)))
row = c.fetchone()
c.close()
return row

def getRandomQuestionNotAsked(self, channel, roundStart):
c = self.conn.cursor()
c.execute('''SELECT *
Expand Down

0 comments on commit 8eb9c91

Please sign in to comment.