remove history file, keep history per session

This commit is contained in:
Gordon Shumway 2019-09-03 03:05:44 -04:00 committed by GitHub
parent 15d698c956
commit 30fa5aab53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 12 deletions

View File

@ -127,13 +127,11 @@ class Jeopardy(callbacks.Plugin):
line = f.readline() line = f.readline()
f.close() f.close()
else: else:
self.historyfile = self.registryValue('historyFile') try:
if not os.path.exists(self.historyfile): self.history.setdefault(self.channel, default=[])
f = open(self.historyfile, 'w') except:
f.write('Nothing:Nothing\n') self.history = {}
f.close() self.history.setdefault(self.channel, [])
with open(self.historyfile) as f:
history = f.read().splitlines()
cluecount = self.num cluecount = self.num
failed = 0 failed = 0
if self.categories == 'random': if self.categories == 'random':
@ -157,7 +155,7 @@ class Jeopardy(callbacks.Plugin):
points = int(item['value']) points = int(item['value'])
else: else:
points = self.points points = self.points
if len(question) > 1 and airdate and answer and category and points and not invalid and "{0}:{1}".format(self.channel, id) not in history: if len(question) > 1 and airdate and answer and category and points and not invalid and "{0}:{1}".format(self.channel, id) not in self.history[self.channel]:
self.questions.append("{0}:{1}*({2}) [${3}] \x02{4}: {5}\x0F*{6}*{7}".format(self.channel, id, airdate[0], str(points), category, question, answer, points)) self.questions.append("{0}:{1}*({2}) [${3}] \x02{4}: {5}\x0F*{6}*{7}".format(self.channel, id, airdate[0], str(points), category, question, answer, points))
n += 1 n += 1
except Exception: except Exception:
@ -209,7 +207,7 @@ class Jeopardy(callbacks.Plugin):
points = int(item['value']) points = int(item['value'])
else: else:
points = self.points points = self.points
if len(question) > 1 and airdate and answer and category and points and not invalid and "{0}:{1}".format(self.channel, id) not in history and question not in asked: if len(question) > 1 and airdate and answer and category and points and not invalid and "{0}:{1}".format(self.channel, id) not in self.history[self.channel] and question not in asked:
self.questions.append("{0}:{1}*({2}) [${3}] \x02{4}: {5}\x0F*{6}*{7}".format(self.channel, id, airdate[0], str(points), category, question, answer, points)) self.questions.append("{0}:{1}*({2}) [${3}] \x02{4}: {5}\x0F*{6}*{7}".format(self.channel, id, airdate[0], str(points), category, question, answer, points))
asked.append(question) asked.append(question)
n += 1 n += 1
@ -277,9 +275,7 @@ class Jeopardy(callbacks.Plugin):
blank = re.sub('\w', blankChar, ans) blank = re.sub('\w', blankChar, ans)
self.reply("HINT: {0}".format(blank)) self.reply("HINT: {0}".format(blank))
if self.id: if self.id:
f = open(self.historyfile, 'a') self.history[self.channel].append(self.id)
f.write("{0}\n".format(self.id))
f.close()
def event(): def event():
self.timedEvent() self.timedEvent()
timeout = self.registryValue('timeout', self.channel) timeout = self.registryValue('timeout', self.channel)
@ -466,6 +462,7 @@ class Jeopardy(callbacks.Plugin):
results.append(search) results.append(search)
if not results: if not results:
irc.reply("Error. Could not find any results for {0}".format(categories)) irc.reply("Error. Could not find any results for {0}".format(categories))
return
else: else:
results = 'random' results = 'random'
if results and 'shuffle' in optlist: if results and 'shuffle' in optlist: