]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
[config] adds a new param store_default
authorMatthias H <apoc@sixserv.org>
Thu, 6 Mar 2014 10:06:57 +0000 (11:06 +0100)
committerMatthias H <apoc@sixserv.org>
Thu, 6 Mar 2014 10:06:57 +0000 (11:06 +0100)
Creates a new option to store the default at first run.
This fixes the problem that random auth passwords are not
kept, it also allows us to always store the core.db config
value.

lib/rbot/botuser.rb
lib/rbot/config.rb
lib/rbot/ircbot.rb

index ab9a8de3f04f4da0dbbc66d60105c9299ec59428..97bab93cc34545c3ed4c875209107eec3dd2624c 100644 (file)
@@ -35,7 +35,8 @@ class Bot
   module Auth
 
     Config.register Config::StringValue.new( 'auth.password',
-      :default => [*?a..?z,*?A..?Z,*?0..?9].sample(8).join, :wizard => true,
+      :default => [*?a..?z,*?A..?Z,*?0..?9].sample(8).join, :store_default => true,
+      :wizard => true,
       :on_change => Proc.new {|bot, v| bot.auth.botowner.password = v},
       :desc => _('Password for the bot owner'))
     Config.register Config::BooleanValue.new( 'auth.login_by_mask',
index e6145a82ee95637d6a31528bf2a89598c6e0e1b8..ef63a2feb06c36f1372e75d412d199814b633543 100644 (file)
@@ -24,6 +24,7 @@ module Config
     attr_reader :desc
     attr_reader :key
     attr_reader :wizard
+    attr_reader :store_default
     attr_reader :requires_restart
     attr_reader :requires_rescan
     attr_reader :order
@@ -52,6 +53,7 @@ module Config
       @on_change = params[:on_change]
       @validate = params[:validate]
       @wizard = params[:wizard]
+      @store_default = params[:store_default]
       @requires_restart = params[:requires_restart]
       @requires_rescan = params[:requires_rescan]
       @auth_path = "config::key::#{key.sub('.','::')}"
@@ -274,6 +276,14 @@ module Config
           error "failed to read conf.yaml: #{$!}"
         end
       end
+      # config options with :store_default to true should store
+      # their default value at first run.
+      # Some defaults might change anytime the bot starts
+      #  for instance core.db or authpw
+      @items.values.find_all {|i| i.store_default }.each do |value|
+        @config[value.key] = value.default
+      end
+
       # if we got here, we need to run the first-run wizard
       Wizard.new(@bot).run
       # save newly created config
index 8b827f15fb59484c88c54df7e0523cd88a51638a..f74b1530cd51f8d1a1d4fcd0f525cad7b2eed8f5 100644 (file)
@@ -435,7 +435,7 @@ class Bot
       },
       :desc => "Percentage of IRC penalty to consider when sending messages to prevent being disconnected for excess flood. Set to 0 to disable penalty control.")
     Config.register Config::StringValue.new('core.db',
-      :default => default_db,
+      :default => default_db, :store_default => true,
       :wizard => true,
       :validate => Proc.new { |v| Registry::formats.include? v },
       :requires_restart => true,