summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorYaohan Chen <yaohan.chen@gmail.com>2007-08-07 20:42:22 +0000
committerYaohan Chen <yaohan.chen@gmail.com>2007-08-07 20:42:22 +0000
commit609ecba1b5baa74ea657c6a5e010c3c1ed0dfb6c (patch)
tree17dd034b3dced49a0aa785ee4954de20950f0773 /data/rbot/plugins
parentd8231a3338c9a5adeb1433f478861f2c630cf4e8 (diff)
* use Util.safe_save in alias plugin
* handle corrupt data file in alias plugin
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/alias.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/data/rbot/plugins/alias.rb b/data/rbot/plugins/alias.rb
index 2fba9324..218754a6 100644
--- a/data/rbot/plugins/alias.rb
+++ b/data/rbot/plugins/alias.rb
@@ -43,9 +43,12 @@ 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)
- YAML.load_file(@data_file)
+ @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|
@@ -60,7 +63,7 @@ class AliasPlugin < Plugin
def save
Dir.mkdir(@data_path) unless File.exist?(@data_path)
- File.open(@data_file, 'w') {|f| f.write @aliases.to_yaml}
+ Utils.safe_save(@data_file) {|f| f.write @aliases.to_yaml}
end
def cmd_add(m, params)