X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fconfig.rb;h=4f81c6951050e89bc5719c664a05a4832a1a38e6;hb=81e0b9c7405c3731f6df1e50f6b32a35c224dfa7;hp=23a445f978a5ccfeb245bb59aeac2834c521d2bd;hpb=22f6e518f5b82b9311ce2d1cb56bd269bbb5994f;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb index 23a445f9..4f81c695 100644 --- a/lib/rbot/config.rb +++ b/lib/rbot/config.rb @@ -40,7 +40,9 @@ module Config @order = @@order @@order += 1 @key = key.to_sym - if params.has_key? :default + if @manager.overrides.key?(@key) + @default = @manager.overrides[@key] + elsif params.has_key? :default @default = params[:default] else @default = false @@ -184,7 +186,7 @@ module Config unless newval.include? val newval << val validate_item(val) or raise ArgumentError, "invalid item: #{val}" - validate(newval) or raise ArgumentError, "invalid value: #{newval.to_s}" + validate(newval) or raise ArgumentError, "invalid value: #{newval.inspect}" set(newval) end end @@ -226,6 +228,7 @@ module Config attr_reader :bot attr_reader :items attr_reader :config + attr_reader :overrides attr_accessor :changed def initialize @@ -235,6 +238,21 @@ module Config def reset_config @items = Hash.new @config = Hash.new(false) + + # We allow default values for config keys to be overridden by + # the config file /etc/rbot.conf + # The main purpose for this is to allow distro or system-wide + # settings such as external program paths (figlet, toilet, ispell) + # to be set once for all the bots. + @overrides = Hash.new + etcfile = "/etc/rbot.conf" + if File.exist?(etcfile) + log "Loading defaults from #{etcfile}" + etcconf = YAML::load_file(etcfile) + etcconf.each { |k, v| + @overrides[k.to_sym] = v + } + end end # Associate with bot _bot_ @@ -348,6 +366,7 @@ module Config end def run() + $stdout.sync = true puts _("First time rbot configuration wizard") puts "====================================" puts _("This is the first time you have run rbot with a config directory of: #{@bot.botclass}")