+
+ word1, word2 = message.split(/\s+/)
+ return unless word1 and word2
+ line = generate_string(word1, word2)
+ return unless line
+ # we do nothing if the line we return is just an initial substring
+ # of the line we received
+ return if message.index(line) == 0
+ @bot.timer.add_once(delay) {
+ m.reply line, :nick => false, :to => :public
+ }
+ end
+
+ def chat(m, params)
+ line = generate_string(params[:seed1], params[:seed2])
+ if line != "#{params[:seed1]} #{params[:seed2]}"
+ m.reply line
+ else
+ m.reply "I can't :("
+ end
+ end
+
+ def rand_chat(m, params)
+ # pick a random pair from the db and go from there
+ word1, word2 = :nonword, :nonword
+ output = Array.new
+ 50.times do
+ wordlist = @registry["#{word1} #{word2}"]
+ break if wordlist.empty?
+ word3 = wordlist[rand(wordlist.length)]
+ break if word3 == :nonword
+ output << word3
+ word1, word2 = word2, word3
+ end
+ if output.length > 1
+ m.reply output.join(" ")
+ else
+ m.reply "I can't :("
+ end