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
|
# chop off the seed data at the start
|
||||||
gen_words = gen_words[2:]
|
gen_words = gen_words[2:]
|
||||||
|
|
||||||
# chop off the end text, if it was the keyword indicating an end of chain
|
if len(gen_words):
|
||||||
if gen_words[-1] == self.stop:
|
# chop off the end text, if it was the keyword indicating an end of chain
|
||||||
gen_words = gen_words[:-1]
|
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)
|
return ' '.join(gen_words)
|
||||||
|
|
||||||
|
@ -616,10 +620,12 @@ class Markov(Module):
|
||||||
# check for addresses (the "whoever:" in
|
# check for addresses (the "whoever:" in
|
||||||
# __start1 __start2 whoever: some words)
|
# __start1 __start2 whoever: some words)
|
||||||
addressing_suffixes = [':', ',']
|
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:]
|
return chain[3:]
|
||||||
else:
|
elif len(chain) > 2:
|
||||||
return chain[2:]
|
return chain[2:]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
|
||||||
def _get_chatter_targets(self):
|
def _get_chatter_targets(self):
|
||||||
"""Get all possible chatter targets."""
|
"""Get all possible chatter targets."""
|
||||||
|
|
Loading…
Reference in New Issue