- return if @bot.config['factoids.address'] and !m.address?
- return if @factoids.empty?
- return if @triggers.empty?
- return unless m.message =~ /^(.*)\?\s*$/
- query = $1.strip.downcase
- if @triggers.include?(query)
- facts(m, :words => query.split)
+ if m.message =~ /^(.*)\?\s*$/
+ return if @bot.config['factoids.address'] and !m.address?
+ return if @factoids.empty?
+ return if @triggers.empty?
+ query = $1.strip.downcase
+ if @triggers.include?(query)
+ words = query.split
+ words.instance_variable_set(:@string_value, query)
+ def words.to_s
+ @string_value
+ end
+ facts(m, :words => words)
+ end
+ else
+ return if m.address? # we don't learn stuff directed at us which is not an explicit learn command
+ return if !@bot.config['factoids.listen_and_learn'] or @learn_patterns.empty?
+ @learn_patterns.each do |pat, i|
+ g = pat.match(m.message)
+ if g and g[i]
+ learn(m, :stuff => g[i], :silent => @bot.config['factoids.silent_listen_and_learn'])
+ break
+ end
+ end