From 666992674634526ae5b84fcbdc50bc7a0fd31f6e Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 23 Sep 2019 16:47:11 +0100 Subject: [PATCH] support first_word with no found second_word useful for "!markov " so that "" can be mid-chain --- modules/markov.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/markov.py b/modules/markov.py index a9fe11d5..bc727557 100644 --- a/modules/markov.py +++ b/modules/markov.py @@ -126,10 +126,20 @@ class Module(ModuleManager.BaseModule): frequency FROM markov WHERE channel_id=? AND first_word IS NULL AND second_word=? AND third_word NOT NULL""", [channel_id, first_word]) if not second_words: - return None - second_word = self._choose(second_words) + second_two_words = self.bot.database.execute_fetchall("""SELECT + second_word, third_word, frequency FROM markov WHERE + channel_id=? AND first_word=? AND second_word NOT NULL AND + third_word NOT NULL""", [channel_id, first_word]) + if not second_two_words: + return None + + second_word, third_word = self._choose( + [[[s, t], f] for s, t, f in second_two_words]) + words = [first_word, second_word, third_word] + else: + second_word = self._choose(second_words) + words = [first_word, second_word] - words = [first_word, second_word] for i in range(30): two_words = words[-2:] third_words = self.bot.database.execute_fetchall("""SELECT