Markov: handle empty reply chains more gracefully
This commit is contained in:
parent
25e41150af
commit
fb477a57b9
@ -497,9 +497,13 @@ class Markov(Module):
|
||||
# chop off the seed data at the start
|
||||
gen_words = gen_words[2:]
|
||||
|
||||
# chop off the end text, if it was the keyword indicating an end of chain
|
||||
if gen_words[-1] == self.stop:
|
||||
gen_words = gen_words[:-1]
|
||||
if len(gen_words):
|
||||
# chop off the end text, if it was the keyword indicating an end of chain
|
||||
if gen_words[-1] == self.stop:
|
||||
gen_words = gen_words[:-1]
|
||||
else:
|
||||
self.log.warning("after all this we have an empty list of words. "
|
||||
"there probably isn't any data for this context")
|
||||
|
||||
return ' '.join(gen_words)
|
||||
|
||||
@ -616,10 +620,12 @@ class Markov(Module):
|
||||
# check for addresses (the "whoever:" in
|
||||
# __start1 __start2 whoever: some words)
|
||||
addressing_suffixes = [':', ',']
|
||||
if chain[2][-1] in addressing_suffixes and avoid_address:
|
||||
if len(chain) > 2 and chain[2][-1] in addressing_suffixes and avoid_address:
|
||||
return chain[3:]
|
||||
else:
|
||||
elif len(chain) > 2:
|
||||
return chain[2:]
|
||||
else:
|
||||
return []
|
||||
|
||||
def _get_chatter_targets(self):
|
||||
"""Get all possible chatter targets."""
|
||||
|
Loading…
Reference in New Issue
Block a user