X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Falias.rb;h=67f481dc6c02ff1df275128f054220afb1e1e352;hb=HEAD;hp=58d0ef01a0831639f03dd98b8aaf06064e2519b2;hpb=91a9024e21ec8b429605a036b5c9193442a580e3;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/alias.rb b/data/rbot/plugins/alias.rb index 58d0ef01..67f481dc 100644 --- a/data/rbot/plugins/alias.rb +++ b/data/rbot/plugins/alias.rb @@ -38,32 +38,29 @@ class AliasPlugin < Plugin def initialize super - @data_path = datafile - @data_file = File.join(@data_path, 'aliases.yaml') - # hash of alias => command entries - 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 = Hash.new - aliases.each_pair do |a, c| - begin - add_alias(a, c) - rescue AliasDefinitionError - warning _("Invalid alias entry %{alias} : %{command} in %{filename}: %{reason}") % - {:alias => a, :command => c, :filename => @data_file, :reason => $1} + @aliases = @registry[:aliases] + unless @aliases + # attempt to load aliases from data file yaml + filename = File.join(datafile, 'aliases.yaml') + if File.exists? filename + begin + @aliases = {} + YAML.load_file(filename).each_pair do |a, c| + add_alias(a, c) + end + rescue + warning _("Data file is not found or corrupt, reinitializing data") + @aliases = {} + end + else + @aliases = {} end - end - end + end + end - def save - FileUtils.mkdir_p(@data_path) - Utils.safe_save(@data_file) {|f| f.write @aliases.to_yaml} + def save + @registry[:aliases] = @aliases + @registry.flush end def cmd_add(m, params) @@ -110,7 +107,7 @@ class AliasPlugin < Plugin command.scan(/<(\w+)>/).flatten.to_set == text.split.grep(/\A[:*](\w+)\Z/) {$1}.to_set or raise AliasDefinitionError.new(_('The arguments in alias must match the substitutions in command, and vice versa')) - + begin map text, :action => :"alias_handle<#{text}>", :auth_path => 'run' rescue