]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/alias.rb
reaction plugin: no more :stuff, but :before and :after for the pre and postmatch...
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / alias.rb
index 218754a6eefc887e3a2830f62b17239422578ad1..1496755d099dd8db3d51005afb14940d737d2a8f 100644 (file)
@@ -43,15 +43,17 @@ class AliasPlugin < Plugin
     @data_path = "#{@bot.botclass}/alias/"
     @data_file = "#{@data_path}/aliases.yaml"
     # hash of alias => command entries
-    @aliases = if File.exist?(@data_file) &&
-                  data = YAML.load_file(@data_file) &&
-                  data.respond_to?(:each_pair)
-                 data
-               else
-                 warning _("Data file is not found or corrupt, reinitializing data")
-                 Hash.new
+    data = nil
+    aliases = if File.exist?(@data_file) &&
+                 (data = YAML.load_file(@data_file)) &&
+                 data.respond_to?(:each_pair)
+                data
+              else
+                warning _("Data file is not found or corrupt, reinitializing data")
+                Hash.new
                end
-    @aliases.each_pair do |a, c|
+    @aliases = Hash.new
+    aliases.each_pair do |a, c|
       begin
         add_alias(a, c)
       rescue AliasDefinitionError
@@ -62,7 +64,7 @@ class AliasPlugin < Plugin
   end 
 
   def save 
-    Dir.mkdir(@data_path) unless File.exist?(@data_path)
+    FileUtils.mkdir_p(@data_path)
     Utils.safe_save(@data_file) {|f| f.write @aliases.to_yaml}
   end