@bot.config['markov.probability'] = @registry['probability']
@registry.delete('probability')
end
- @lastline = false
+ @learning_queue = Queue.new
+ @learning_thread = Thread.new do
+ while s = @learning_queue.pop
+ learn s
+ sleep 0.5
+ end
+ end
+ @learning_thread.priority = -1
+ end
+
+ def cleanup
+ debug 'closing learning thread'
+ @learning_queue.push nil
+ @learning_thread.join
+ debug 'learning thread closed'
end
def generate_string(word1, word2)
return unless should_talk
word1, word2 = message.split(/\s+/)
+ return unless word1 and word2
line = generate_string(word1, word2)
return unless line
return if line == message
end
end
- def listen(m)
- return unless m.kind_of?(PrivMessage) && m.public?
+ def message(m)
+ return unless m.public?
return if m.address?
return if ignore? m.source
# in channel message, the kind we are interested in
- message = clean_str m.message
+ message = clean_str m.plainmessage
if m.action?
message = "#{m.sourcenick} #{message}"
end
+ @learning_queue.push message
+ random_markov(m, message) unless m.replied?
+ end
+
+ def learn(message)
+ # debug "learning #{message}"
wordlist = message.split(/\s+/)
return unless wordlist.length >= 2
- @lastline = message
word1, word2 = :nonword, :nonword
wordlist.each do |word3|
- @registry["#{word1} #{word2}"] = @registry["#{word1} #{word2}"].push(word3)
+ k = "#{word1} #{word2}"
+ @registry[k] = @registry[k].push(word3)
word1, word2 = word2, word3
end
- @registry["#{word1} #{word2}"] = @registry["#{word1} #{word2}"].push(:nonword)
-
- return if m.replied?
- random_markov(m, message)
+ k = "#{word1} #{word2}"
+ @registry[k] = @registry[k].push(:nonword)
end
end