]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/keywords.rb
test
[user/henk/code/ruby/rbot.git] / lib / rbot / keywords.rb
index 70802e35971555fcc64d26abb2772a9b4a2a12c6..cc91155cd6f6ead6da683d6eb2f980d5be4ac40e 100644 (file)
@@ -81,9 +81,11 @@ module Irc
   # handle it, checks for a keyword command or lookup, otherwise the message
   # is delegated to plugins
   class Keywords
-    BotConfig.register('keyword.listen', :type => :boolean, :default => false,
+    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('keyword.address', :type => :boolean, :default => true,
+    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+
@@ -213,6 +215,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])
@@ -247,6 +250,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
@@ -419,6 +423,8 @@ module Irc
         end
       else
         # in channel message, not to me
+        # 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+(.*)$/))