X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fkeywords.rb;h=83185d9ff5cca97721e714283f6f04a75de4ea11;hb=8836539ba33a7507c23af1f410dbf78d36503148;hp=3305af299899bab8116e1b3156448a530a75f64b;hpb=2a96c9198c1f6e13407d0999083f6ce5e0bc06fa;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/keywords.rb b/lib/rbot/keywords.rb index 3305af29..83185d9f 100644 --- a/lib/rbot/keywords.rb +++ b/lib/rbot/keywords.rb @@ -8,7 +8,7 @@ module Irc # is, and has a single value of bar). # Keywords can have multiple values, to_s() will choose one at random class Keyword - + # type of keyword (e.g. "is" or "are") attr_reader :type @@ -81,6 +81,12 @@ module Irc # handle it, checks for a keyword command or lookup, otherwise the message # is delegated to plugins class Keywords + BotConfig.register BotConfigBooleanValue.new('keyword.listen', + :default => false, + :desc => "Should the bot listen to all chat and attempt to automatically detect keywords? (e.g. by spotting someone say 'foo is bar')") + BotConfig.register BotConfigBooleanValue.new('keyword.address', + :default => true, + :desc => "Should the bot require that keyword lookups are addressed to it? If not, the bot will attempt to lookup foo if someone says 'foo?' in channel") # create a new Keywords instance, associated to bot +bot+ def initialize(bot) @@ -125,12 +131,10 @@ module Irc puts "upgrading keyword db #{f} (rbot 0.9.5 or prior) database format" newname = f.gsub(/\.db$/, ".kdb") old = BDB::Hash.open f, nil, - "r+", 0600, "set_pagesize" => 1024, - "set_cachesize" => [0, 32 * 1024, 0] - new = BDB::CIBtree.open newname, nil, - BDB::CREATE | BDB::EXCL | BDB::TRUNCATE, - 0600, "set_pagesize" => 1024, - "set_cachesize" => [0, 32 * 1024, 0] + "r+", 0600 + new = BDB::CIBtree.open(newname, nil, + BDB::CREATE | BDB::EXCL, + 0600) old.each {|k,v| new[k] = v } @@ -180,12 +184,10 @@ module Irc if File.exist?("#{@bot.botclass}/keywords.db") puts "upgrading old keywords (rbot 0.9.5 or prior) database format" old = BDB::Hash.open "#{@bot.botclass}/keywords.db", nil, - "r+", 0600, "set_pagesize" => 1024, - "set_cachesize" => [0, 32 * 1024, 0] + "r+", 0600 new = BDB::CIBtree.open "#{@bot.botclass}/keyword.db", nil, - BDB::CREATE | BDB::EXCL | BDB::TRUNCATE, - 0600, "set_pagesize" => 1024, - "set_cachesize" => [0, 32 * 1024, 0] + BDB::CREATE | BDB::EXCL, + 0600 old.each {|k,v| new[k] = v } @@ -209,6 +211,7 @@ module Irc # lookup keyword +key+, return it or nil def [](key) + return nil if key.nil? debug "keywords module: looking up key #{key}" if(@keywords.has_key?(key)) return Keyword.restore(@keywords[key]) @@ -243,6 +246,7 @@ module Irc # # handle a message asking about a keyword def keyword(m, key, dunno=true) + return if key.nil? unless(kw = self[key]) m.reply @bot.lang.get("dunno") if (dunno) return @@ -415,7 +419,9 @@ module Irc end else # in channel message, not to me - if(m.message =~ /^'(.*)$/ || (!@bot.config["keyword.noaddress"] && m.message =~ /^(.*\S)\s*\?\s*$/)) + # TODO option to do if(m.message =~ /^(.*)$/, ie try any line as a + # keyword lookup. + if(m.message =~ /^'(.*)$/ || (!@bot.config["keyword.address"] && m.message =~ /^(.*\S)\s*\?\s*$/)) keyword m, $1, false if(@bot.auth.allow?("keyword", m.source)) elsif(@bot.config["keyword.listen"] == true && (m.message =~ /^(.*?)\s+(is|are)\s+(.*)$/)) # TODO MUCH more selective on what's allowed here