]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
ircbot.rb: copy missing template files on startup
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Jun 2008 10:08:40 +0000 (12:08 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 24 Jun 2008 10:29:59 +0000 (12:29 +0200)
lib/rbot/ircbot.rb

index 932cc3b7322fb8ac73ebdcdcb61b581f15bd2c87..a8b5543eb02006982eacb49e3cfc2cd2135e52a3 100644 (file)
@@ -417,7 +417,19 @@ class Bot
     botclass = File.expand_path(botclass)
     @botclass = botclass.gsub(/\/$/, "")
 
-    unless FileTest.directory? botclass
+    if FileTest.directory? botclass
+      # compare the templates dir with the current botclass, and fill it in with
+      # any missing file.
+      # Sadly, FileUtils.cp_r doesn't have an :update option, so we have to do it
+      # manually
+      template = File.join Config::datadir, 'templates'
+      # note that we use the */** pattern because we don't want to match
+      # keywords.rbot, which gets deleted on load and would therefore be missing always
+      missing = Dir.chdir(template) { Dir.glob('*/**') } - Dir.chdir(botclass) { Dir.glob('*/**') }
+      missing.map do |f|
+        FileUtils.cp File.join(template, f), File.join(botclass, f)
+      end
+    else
       log "no #{botclass} directory found, creating from templates.."
       if FileTest.exist? botclass
         error "file #{botclass} exists but isn't a directory"