database.execute() doesn't fetch data

This commit is contained in:
jesopo 2019-09-20 17:12:17 +01:00
parent ecf48aa33e
commit 532d1687c3

View file

@ -44,18 +44,16 @@ class Module(ModuleManager.BaseModule):
return random.choices(words, weights=frequencies, k=1)[0] return random.choices(words, weights=frequencies, k=1)[0]
def generate(self, channel_id): def generate(self, channel_id):
first_words = self.bot.database.execute("""SELECT third_word, frequency first_words = self.bot.database.execute_fetchall("""SELECT third_word,
FROM markov WHERE channel_id=? AND first_word IS NULL AND frequency FROM markov WHERE channel_id=? AND first_word IS NULL AND
second_word IS NULL AND third_word NOT NULL""", second_word IS NULL AND third_word NOT NULL""", [channel_id])
[channel_id])
if not first_words: if not first_words:
return None return None
first_word = self._choose(first_words) first_word = self._choose(first_words)
second_words = self.bot.database.execute("""SELECT third_word, frequency second_words = self.bot.database.execute_fetchall("""SELECT third_word,
FROM markov WHERE channel_id=? AND first_word IS NULL AND frequency FROM markov WHERE channel_id=? AND first_word IS NULL AND
second_word=? AND third_word NOT NULL""", second_word=? AND third_word NOT NULL""", [channel_id, first_word])
[channel_id, first_word])
if not second_words: if not second_words:
return None return None
second_word = self._choose(second_words) second_word = self._choose(second_words)
@ -63,9 +61,9 @@ class Module(ModuleManager.BaseModule):
words = [first_word, second_word] words = [first_word, second_word]
for i in range(30): for i in range(30):
two_words = words[-2:] two_words = words[-2:]
third_words = self.bot.database.execute("""SELECT third_word, third_words = self.bot.database.execute_fetchall("""SELECT
frequency FROM markov WHERE channel_id=? AND first_word=? AND third_word, frequency FROM markov WHERE channel_id=? AND
second_word=?""", [channel_id]+two_words) first_word=? AND second_word=?""", [channel_id]+two_words)
third_word = self._choose(third_words) third_word = self._choose(third_words)
if third_word == None: if third_word == None: