diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-22 09:27:49 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-03-22 09:27:49 +0100 |
commit | 8b57372691904b7d307eec65f0491bf2a88f1f48 (patch) | |
tree | 84e9f2304bd06179eb1b92a1af62c654898e892a | |
parent | bf2a5a05b86773da8351ae01d94b0fecd5c4519a (diff) |
markov plugin: thread markov chain construction and use in listen()
-rw-r--r-- | data/rbot/plugins/markov.rb | 19 |
1 files changed, 10 insertions, 9 deletions
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 |