]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
a little more robustness around emtpy lookups
authorTom Gilbert <tom@linuxbrit.co.uk>
Wed, 31 Aug 2005 20:39:19 +0000 (20:39 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Wed, 31 Aug 2005 20:39:19 +0000 (20:39 +0000)
Also more robustness around reading/writing conf.yaml

data/rbot/plugins/seen.rb
lib/rbot/config.rb
lib/rbot/keywords.rb

index a8dc1af7b8afc3bdc298f9b6a77f30111b373c34..cc0c1792805a856cc7647f2e2dfa262bd2c3f29a 100644 (file)
@@ -21,6 +21,7 @@ class SeenPlugin < Plugin
   end
 
   def listen(m)
+    return if m.sourcenick.nil?
     # keep database up to date with who last said what
     if m.kind_of?(PrivMessage)
       return if m.private?
index 36160875139472b36332c14c15c2b93b61c6cf26..7475d6177ec19740c8b7c8f703ae75c0272fb3b7 100644 (file)
@@ -311,20 +311,30 @@ module Irc
                    :defaults => {:topic => false}
       
       if(File.exist?("#{@@bot.botclass}/conf.yaml"))
-        newconfig = YAML::load_file("#{@@bot.botclass}/conf.yaml")
-        @@config.update newconfig
-      else
-        # first-run wizard!
-        BotConfigWizard.new(@@bot).run
-        # save newly created config
-        save
+        begin
+          newconfig = YAML::load_file("#{@@bot.botclass}/conf.yaml")
+          @@config.update newconfig
+          return
+        rescue
+          $stderr.puts "failed to read conf.yaml: #{$!}"
+        end
       end
+      # if we got here, we need to run the first-run wizard
+      BotConfigWizard.new(@@bot).run
+      # save newly created config
+      save
     end
 
     # write current configuration to #{botclass}/conf.rbot
     def save
-      File.open("#{@@bot.botclass}/conf.yaml", "w") do |file|
-        file.puts @@config.to_yaml
+      begin
+        File.open("#{@@bot.botclass}/conf.yaml.new", "w") do |file|
+          file.puts @@config.to_yaml
+        end
+        File.rename("#{@@bot.botclass}/conf.yaml.new",
+                    "#{@@bot.botclass}/conf.yaml")
+      rescue
+        $stderr.puts "failed to write configuration file conf.yaml! #{$!}"
       end
     end
 
index 8065e8b807f13229bf12ee92b9dd47d8a72b3357..cc91155cd6f6ead6da683d6eb2f980d5be4ac40e 100644 (file)
@@ -250,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