From 8b57372691904b7d307eec65f0491bf2a88f1f48 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 22 Mar 2008 09:27:49 +0100 Subject: markov plugin: thread markov chain construction and use in listen() --- data/rbot/plugins/markov.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'data') diff --git a/data/rbot/plugins/markov.rb b/data/rbot/plugins/markov.rb index 60ecafec..e340d8b8 100644 --- a/data/rbot/plugins/markov.rb +++ b/data/rbot/plugins/markov.rb @@ -204,17 +204,18 @@ class MarkovPlugin < Plugin wordlist = message.split(/\s+/) return unless wordlist.length >= 2 - word1, word2 = :nonword, :nonword - wordlist.each do |word3| + Thread.new do + word1, word2 = :nonword, :nonword + wordlist.each do |word3| + k = "#{word1} #{word2}" + @registry[k] = @registry[k].push(word3) + word1, word2 = word2, word3 + end k = "#{word1} #{word2}" - @registry[k] = @registry[k].push(word3) - word1, word2 = word2, word3 - end - k = "#{word1} #{word2}" - @registry[k] = @registry[k].push(:nonword) + @registry[k] = @registry[k].push(:nonword) - return if m.replied? - random_markov(m, message) + random_markov(m, message) unless m.replied? + end end end -- cgit v1.2.3