- # respond to config messages, to provide runtime configuration
- # management
- # messages will be:
- # get (implied)
- # set
- # unset
- # and for arrays:
- # add
- # remove
- @handler = MessageMapper.new(self)
- @handler.map 'config list :module', :action => 'handle_list',
- :defaults => {:module => false}
- @handler.map 'config get :key', :action => 'handle_get'
- @handler.map 'config desc :key', :action => 'handle_desc'
- @handler.map 'config describe :key', :action => 'handle_desc'
- @handler.map 'config set :key *value', :action => 'handle_set'
- @handler.map 'config unset :key', :action => 'handle_unset'
-
- # TODO
- # have this class persist key/values in hash using yaml as it kinda
- # already does.
- # have other users of the class describe config to it on init, like:
- # @config.add(:key => 'server.name', :type => 'string',
- # :default => 'localhost', :restart => true,
- # :help => 'irc server to connect to')
- # that way the config module doesn't have to know about all the other
- # classes but can still provide help and defaults.
- # Classes don't have to add keys, they can just use config as a
- # persistent hash, but then they won't be presented by the config
- # module for runtime display/changes.
- # (:restart, if true, makes the bot reply to changes with "this change
- # will take effect after the next restart)
- # :proc => Proc.new {|newvalue| ...}
- # (:proc, proc to run on change of setting)
- # or maybe, @config.add_key(...) do |newvalue| .... end
- # :validate => /regex/
- # (operates on received string before conversion)
- # Special handling for arrays so the config module can be used to
- # add/remove elements as well as changing the whole thing
- # Allow config options to list possible valid values (if type is enum,
- # for example). Then things like the language module can list the
- # available languages for choosing.
-
+ # 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_
+ def bot_associate(bot, reset=false)
+ reset_config if reset
+ @bot = bot
+ return unless @bot
+
+ @changed = false