summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-13 13:17:14 (GMT)
committer sand <daniel@spatof.org>2013-05-13 13:17:14 (GMT)
commitd769ca5373b9b0c6c339dc152ad5391910ead8be (patch)
tree0957407a7906f04e436af84939a4c4619823baa7
parentf8c1e514e64e7aa0d94a861088713639d455586a (diff)
Fix per plugin markov, quando il db รจ vuoto
-rw-r--r--pinolo/plugins/markov.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/pinolo/plugins/markov.py b/pinolo/plugins/markov.py
index 25f3b10..4d75ce8 100644
--- a/pinolo/plugins/markov.py
+++ b/pinolo/plugins/markov.py
@@ -115,6 +115,10 @@ class MarkovBrain(object):
self.tokens[context][next_word] = (weight + 1)
def say(self, seed=None, max_words=50):
+ # Empty database, we can't talk.
+ if not self.tokens:
+ return
+
starter = random.choice(self.tokens.keys())
sequence = deque(tuple(starter))
sentence = list(starter)
@@ -177,6 +181,3 @@ class MarkovPlugin(Plugin):
if self._counter >= self.SAVE_EVERY:
self._counter = 0
self.markov.save()
-
- def on_cmd_save(self, event):
- self.markov.save()