]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/keywords.rb
use a db env for the databases to avoid some corruption problems (I hope)
[user/henk/code/ruby/rbot.git] / lib / rbot / keywords.rb
index daf3b40b011f2399be63914cfea6af1b23924932..83185d9ff5cca97721e714283f6f04a75de4ea11 100644 (file)
@@ -131,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
         }
@@ -186,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
         }
@@ -215,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])
@@ -249,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
@@ -421,6 +419,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+(.*)$/))