X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Ffactoids.rb;h=5b5e2b7204f7bea44d388268a80a897b21ed5411;hb=16336b4a240a4265d1f2df1e30d7b68d3a924287;hp=aeb6557fc8d534d221f1fb2b90c2933c75bed0b0;hpb=4d622f38dc37b5f7777f9911dfc4fd0d45f5e188;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index aeb6557f..5b5e2b72 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -120,7 +120,7 @@ class FactoidsPlugin < Plugin super # TODO config - @dir = File.join(@bot.botclass,"factoids") + @dir = datafile @filename = "factoids.rbot" @factoids = FactoidList.new @triggers = Set.new @@ -331,7 +331,9 @@ class FactoidsPlugin < Plugin # When looking for words we separate them with # arbitrary whitespace, not whatever they came with pre = words.map { |w| Regexp.escape(w)}.join("\\s+") - return Regexp.new("\\b#{pre}\\b", true) + pre << '\b' if pre.match(/\b$/) + pre = '\b' + pre if pre.match(/^\b/) + return Regexp.new(pre, true) end def facts(m, params) @@ -377,7 +379,12 @@ class FactoidsPlugin < Plugin return if @triggers.empty? query = $1.strip.downcase if @triggers.include?(query) - facts(m, :words => query.split) + 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