aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-09-30 16:28:57 +0100
committerGravatar jesopo2019-09-30 16:28:57 +0100
commitf49f34a98f09ce3c752ceedfe2268fb406e926ce (patch)
tree551b736c5c18429309d644090a4cfcdb809a3311 /modules
parentsupport multiple `first_words` (diff)
signature
first_word -> first_words, better if statement
Diffstat (limited to 'modules')
-rw-r--r--modules/markov.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/modules/markov.py b/modules/markov.py
index 6b7cc1b7..bff01c7e 100644
--- a/modules/markov.py
+++ b/modules/markov.py
@@ -116,7 +116,7 @@ class Module(ModuleManager.BaseModule):
stderr.write("Failed to generate markov chain")
def _generate(self, channel_id, first_words):
- if first_word == None:
+ if not first_words:
first_words = self.bot.database.execute_fetchall("""SELECT
third_word, frequency FROM markov WHERE channel_id=? AND
first_word IS NULL AND second_word IS NULL AND third_word
@@ -134,21 +134,20 @@ class Module(ModuleManager.BaseModule):
second_word = self._choose(second_words)
words = [first_word, second_word]
- else:
- if len(first_words) == 1:
- first_word = first_word.lower()
- 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
+ elif len(first_words) == 1:
+ first_word = first_word.lower()
+ 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:
- words = [word.lower() for word in first_words]
+ 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:
+ words = [word.lower() for word in first_words]
for i in range(30):
two_words = words[-2:]