summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMatthias H <apoc@sixserv.org>2014-03-06 11:06:57 +0100
committerMatthias H <apoc@sixserv.org>2014-03-06 11:06:57 +0100
commitd642da9348926e418655685b92f0b68c11b710f1 (patch)
tree0d3577c205d622b219c8e7026592515a44fee084 /lib
parenta3f8a4e5568b1fca793b9345287be40c000f6024 (diff)
[config] adds a new param store_default
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/botuser.rb3
-rw-r--r--lib/rbot/config.rb10
-rw-r--r--lib/rbot/ircbot.rb2
3 files changed, 13 insertions, 2 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb
index ab9a8de3..97bab93c 100644
--- a/lib/rbot/botuser.rb
+++ b/lib/rbot/botuser.rb
@@ -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',
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index e6145a82..ef63a2fe 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -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
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 8b827f15..f74b1530 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -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,