- while key = keys.delete_one
- wordlist = @chains[key]
- wordlist.last.delete(MARKER)
- unless wordlist.empty?
- output = key
- # split using / / so that we can properly catch the marker
- word1, word2 = output.split(/ /).map {|w| w.intern}
- break
- end
+ output = keys[rand(keys.size)].split(/ /)
+ end
+ output = output.split(/ /) unless output.is_a? Array
+ input = [word1, word2]
+ while output.length < @bot.config['markov.max_words'] and (output.first != MARKER or output.last != MARKER) do
+ if output.last != MARKER
+ output << pick_word(output[-2], output[-1])
+ end
+ if output.first != MARKER
+ output.insert 0, pick_word(output[0], output[1], @rchains)