From 7e96e3bc73955239bf47f7339cae45c700218ec0 Mon Sep 17 00:00:00 2001 From: rootcoma Date: Mon, 4 Nov 2013 23:53:55 -0800 Subject: [PATCH 1/5] Fixing up skip: time limits, cant skip after question is answered, fixed so only half have to skip --- config.py | 5 +++++ plugin.py | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/config.py b/config.py index 1733e10..c45eb8b 100644 --- a/config.py +++ b/config.py @@ -50,6 +50,11 @@ conf.registerChannelValue(TriviaTime, 'skipActiveTime', """Amount of time a user is considered active after answering a question""") ) +conf.registerChannelValue(TriviaTime, 'skipLimitTime', + registry.Integer(60, + """Time a user must wait to skip a question again after skipping in seconds""") + ) + conf.registerChannelValue(TriviaTime, 'timeout', registry.Integer(15, """Time in between hints""") diff --git a/plugin.py b/plugin.py index 5da36b8..a8ba34f 100644 --- a/plugin.py +++ b/plugin.py @@ -34,6 +34,7 @@ class TriviaTime(callbacks.Plugin): """ games info """ self.games = {} # separate game for each channel + self.skips = {} # separate game for each channel """ connections """ dbLocation = self.registryValue('sqlitedb') @@ -366,6 +367,10 @@ class TriviaTime(callbacks.Plugin): irc.error('No questions are currently being asked.') return + if self.games[channel].questionOver == True: + irc.error('No questions are currently being asked.') + return + if not self.storage.wasUserActiveIn(username, timeSeconds): irc.error('Only users who have answered a question in the last 10 minutes can skip.') return @@ -374,10 +379,23 @@ class TriviaTime(callbacks.Plugin): irc.error('You can only vote to skip once.') return + skipSeconds = self.registryValue('skipLimitTime', channel) + if username in self.skips: + if self.skips[username] - int(time.mktime(time.localtime())) < skipSeconds: + irc.error('You must wait to be able to skip again.') + return + self.games[channel].skipVoteCount[username] = 1 + self.skips[username] = int(time.mktime(time.localtime())) irc.sendMsg(ircmsgs.privmsg(channel, '%s voted to skip this question.' % username)) - if (len(self.games[channel].skipVoteCount) / totalActive) < self.registryValue('skipThreshold', channel): + if totalActive < 1: + return + + percentAnswered = ((1.0*len(self.games[channel].skipVoteCount))/(totalActive*1.0)) + + # not all have skipped yet, we need to get out of here + if percentAnswered < self.registryValue('skipThreshold', channel): irc.noReply() return @@ -392,7 +410,13 @@ class TriviaTime(callbacks.Plugin): except KeyError: pass irc.sendMsg(ircmsgs.privmsg(channel, 'Skipped question! (%d of %d voted)' % (len(self.games[channel].skipVoteCount), totalActive))) - self.games[channel].nextQuestion() + + timeout = self.registryValue('timeout', channel) + if timeout < 2: + timout = 2 + log.error('timeout was set too low(<2 seconds). setting to 2 seconds') + timeout += time.time() + self.games[channel].queueEvent(timeout, self.games[channel].nextQuestion) irc.noReply() skip = wrap(skip) @@ -593,6 +617,7 @@ class TriviaTime(callbacks.Plugin): self.loadGameState() # activate + self.questionOver = True self.active = True # stop any old game and start a new one @@ -693,6 +718,8 @@ class TriviaTime(callbacks.Plugin): # Have all of the answers been found? if len(self.guessedAnswers) == len(self.answers): + # question is over + self.questionOver = True if len(self.guessedAnswers) > 1: bonusPoints = 0 if len(self.correctPlayers) > 2: @@ -748,11 +775,14 @@ class TriviaTime(callbacks.Plugin): self.sendMessage(self.registryValue('recapNotCompleteKaos', self.channel) % (len(self.guessedAnswers), len(self.answers), int(self.totalAmountWon), len(self.correctPlayers))) else: self.sendMessage(self.registryValue('notAnswered', self.channel) % answer) - # provide next question - + + #reset stuff self.answers = [] self.alternativeAnswers = [] self.question = '' + self.questionOver = True + + # provide next question sleepTime = self.registryValue('sleepTime',self.channel) if sleepTime < 2: sleepTime = 2 @@ -850,6 +880,7 @@ class TriviaTime(callbacks.Plugin): return # reset and increment + self.questionOver = False self.shownHint = False self.skipVoteCount = {} self.question = '' @@ -1111,7 +1142,7 @@ class TriviaTime(callbacks.Plugin): def removeDuplicateQuestions(self): c = self.conn.cursor() - c.execute('''delete from triviaquestion where id not in (select min(id) from triviaquestion GROUP BY question, question_canonical)''') + c.execute('''delete from triviaquestion where id not in (select min(id) from triviaquestion GROUP BY question_canonical)''') num = c.rowcount self.conn.commit() c.close() From 6ecae89178780fd76063cda058d42788cb6c7573 Mon Sep 17 00:00:00 2001 From: rootcoma Date: Tue, 5 Nov 2013 00:35:10 -0800 Subject: [PATCH 2/5] Added .addquestion and .deletequestion commands, and added ability to delete questions --- plugin.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index a8ba34f..3c7c59f 100644 --- a/plugin.py +++ b/plugin.py @@ -107,6 +107,24 @@ class TriviaTime(callbacks.Plugin): irc.sendMsg(ircmsgs.privmsg(channel, 'Giving MVP to %s for being top #%d this WEEK' % (username, user[15]))) irc.queueMsg(ircmsgs.voice(channel, username)) + def deletequestion(self, irc, msg, arg, id): + if not self.storage.questionIdExists(id): + self.error('That question does not exist.') + return + self.storage.deleteQuestion(id) + irc.reply('Deleted question %d.' % id) + deletequestion = wrap(deletequestion, ['int']) + + def addquestion(self, irc, msg, arg, question): + channel = ircutils.toLower(msg.args[0]) + charMask = self.registryValue('charMask', channel) + if charMask not in question: + irc.error('The question must include the separating character %s' % (charMask)) + return + self.storage.insertQuestionsBulk([(question,question)]) + irc.reply('Added your question to the question database') + addquestion = wrap(addquestion, ['text']) + def addquestionfile(self, irc, msg, arg, filename): """[] Add a file of questions to the servers question database, filename defaults to configured quesiton file @@ -1133,7 +1151,7 @@ class TriviaTime(callbacks.Plugin): #skipped=0 divData = self.chunk(questions) # divide into 10000 rows each for chunk in divData: - c.executemany('''insert into triviaquestion values (NULL, ?, ?)''', + c.executemany('''insert into triviaquestion values (NULL, ?, ?, 0)''', chunk) self.conn.commit() skipped = self.removeDuplicateQuestions() @@ -1421,7 +1439,8 @@ class TriviaTime(callbacks.Plugin): c.execute('''create table triviaquestion ( id integer primary key autoincrement, question_canonical text, - question text + question text, + deleted integer not null default 0 )''') except: pass @@ -1763,7 +1782,7 @@ class TriviaTime(callbacks.Plugin): def getNumQuestions(self): c = self.conn.cursor() - result = c.execute('select count(*) from triviaquestion') + result = c.execute('select count(*) from triviaquestion where deleted=0') result = result.fetchone()[0] c.close() return result @@ -1842,7 +1861,7 @@ class TriviaTime(callbacks.Plugin): def getRandomQuestionNotAsked(self, channel, roundStart): c = self.conn.cursor() c.execute('''select * from triviaquestion - where id not in (select line_num from triviagameslog where channel=? and asked_at>=?) + where id not in (select line_num from triviagameslog where deleted=1 or (channel=? and asked_at>=?)) order by random()''', (str.lower(channel),roundStart)) data = [] for row in c: @@ -1877,7 +1896,7 @@ class TriviaTime(callbacks.Plugin): def getNumQuestionsNotAsked(self, channel, roundStart): c = self.conn.cursor() result = c.execute('''select count(id) from triviaquestion - where id not in (select line_num from triviagameslog where channel=? and asked_at>=?)''', + where id not in (select line_num from triviagameslog where deleted=1 or (channel=? and asked_at>=?))''', (channel,roundStart)) rows = result.fetchone()[0] c.close() @@ -1999,6 +2018,14 @@ class TriviaTime(callbacks.Plugin): c.close() return data + def deleteQuestion(self, questionId): + c = self.conn.cursor() + test = c.execute('''update triviaquestion set + deleted=1 + where id=?''', (questionId,)) + self.conn.commit() + c.close() + """ def transferUserLogs(self, userFrom, userTo): userFrom = str.lower(userFrom) From 8be667255572c8db68c5e71f8362163c2cac86ae Mon Sep 17 00:00:00 2001 From: rootcoma Date: Tue, 5 Nov 2013 01:59:30 -0800 Subject: [PATCH 3/5] Changing hints, cant have 3 masked in a row on hint 2 --- plugin.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index 3c7c59f..f5da511 100644 --- a/plugin.py +++ b/plugin.py @@ -845,18 +845,26 @@ class TriviaTime(callbacks.Plugin): divider = 3 if divider > len(ans): divider = len(ans)-1 - lettersInARow=divider + lettersInARow=divider-1 + maskedInARow=0 hints += ans[:divider] ansend = ans[divider:] hintsend = '' unmasked = 0 for i in range(len(ans)-divider): masked = ansend[i] - if lettersInARow < 3 and unmasked < (len(ans)-divider+1) and random.randint(0,100) < hintRatio: + if maskedInARow > 2 and unmasked < (len(ans)-divider): lettersInARow += 1 hintsend += ansend[i] unmasked += 1 + maskedInARow = 0 + elif lettersInARow < 3 and unmasked < (len(ans)-divider) and random.randint(0,100) < hintRatio: + lettersInARow += 1 + hintsend += ansend[i] + unmasked += 1 + maskedInARow = 0 else: + maskedInARow += 1 lettersInARow=0 hintsend += re.sub('\w', charMask, masked) hints += hintsend From 966b4b26e35d7e87f748a804042e622bd95e8d5f Mon Sep 17 00:00:00 2001 From: rootcoma Date: Tue, 5 Nov 2013 03:58:00 -0800 Subject: [PATCH 4/5] Adding question marks --- plugin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin.py b/plugin.py index f5da511..ef75aae 100644 --- a/plugin.py +++ b/plugin.py @@ -953,8 +953,12 @@ class TriviaTime(callbacks.Plugin): self.storage.insertGameLog(self.channel, self.numAsked, self.lineNumber, self.question) + tempQuestion = self.question.rstrip() + if tempQuestion[-1:] != '?': + tempQuestion += ' ?' + # bold the q - questionText = '%s' % self.question + questionText = '%s' % (tempQuestion) # KAOS? report # of answers if len(self.answers) > 1: From 4b108045d30e380ba21918f98c8faea011912c7d Mon Sep 17 00:00:00 2001 From: rootcoma Date: Tue, 5 Nov 2013 04:06:05 -0800 Subject: [PATCH 5/5] Fixing KAOS bonus --- plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin.py b/plugin.py index ef75aae..b95217f 100644 --- a/plugin.py +++ b/plugin.py @@ -740,8 +740,9 @@ class TriviaTime(callbacks.Plugin): self.questionOver = True if len(self.guessedAnswers) > 1: bonusPoints = 0 - if len(self.correctPlayers) > 2: - bonusPoints = self.registryValue('payoutKAOS', self.channel) + if len(self.correctPlayers) >= 2: + if len(self.answers) >= 10: + bonusPoints = self.registryValue('payoutKAOS', self.channel) bonusPointsText = '' if bonusPoints > 0: