- # 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.
-
- if(File.exist?("#{@bot.botclass}/conf.yaml"))
- newconfig = YAML::load_file("#{@bot.botclass}/conf.yaml")
- @config.update(newconfig)
- else
- # first-run wizard!
- wiz = BotConfigWizard.new(@bot)
- newconfig = wiz.run(@config)
- @config.update(newconfig)