]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/config.rb
Relocate help strings to proper locations, add help for 'mode' command
[user/henk/code/ruby/rbot.git] / lib / rbot / config.rb
index ef079429ed0f459d305773d4298c0cf60fcf3530..a1762988c98aab3d22b0c292fa1c7bfa0949328a 100644 (file)
@@ -65,10 +65,13 @@ module Irc
     alias :value :get
     def set(value, on_change = true)
       @manager.config[@key] = value
+      @manager.changed = true
       @on_change.call(@manager.bot, value) if on_change && @on_change
     end
     def unset
       @manager.config.delete(@key)
+      @manager.changed = true
+      @on_change.call(@manager.bot, value) if @on_change
     end
 
     # set string will raise ArgumentErrors on failed parse/validate
@@ -178,6 +181,7 @@ module Irc
     attr_reader :bot
     attr_reader :items
     attr_reader :config
+    attr_accessor :changed
 
     def initialize
       bot_associate(nil,true)
@@ -194,6 +198,7 @@ module Irc
       @bot = bot
       return unless @bot
 
+      @changed = false
       if(File.exist?("#{@bot.botclass}/conf.yaml"))
         begin
           newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
@@ -208,6 +213,7 @@ module Irc
       # if we got here, we need to run the first-run wizard
       BotConfigWizard.new(@bot).run
       # save newly created config
+      @changed = true
       save
     end
 
@@ -249,6 +255,10 @@ module Irc
 
     # write current configuration to #{botclass}/conf.yaml
     def save
+      if not @changed
+        debug "Not writing conf.yaml (unchanged)"
+        return
+      end
       begin
         debug "Writing new conf.yaml ..."
         File.open("#{@bot.botclass}/conf.yaml.new", "w") do |file|
@@ -261,6 +271,7 @@ module Irc
         debug "Officializing conf.yaml ..."
         File.rename("#{@bot.botclass}/conf.yaml.new",
                     "#{@bot.botclass}/conf.yaml")
+        @changed = false
       rescue => e
         error "failed to write configuration file conf.yaml! #{$!}"
         error "#{e.class}: #{e}"