+ return @@config.send(method, *args, &block)
+ end
+
+ def handle_list(m, params)
+ modules = []
+ if params[:module]
+ @@items.each_key do |key|
+ mod, name = key.to_s.split('.')
+ next unless mod == params[:module]
+ modules.push key unless modules.include?(name)
+ end
+ if modules.empty?
+ m.reply "no such module #{params[:module]}"
+ else
+ m.reply modules.join(", ")
+ end
+ else
+ @@items.each_key do |key|
+ name = key.to_s.split('.').first
+ modules.push name unless modules.include?(name)
+ end
+ m.reply "modules: " + modules.join(", ")
+ end
+ end
+
+ def handle_get(m, params)
+ key = params[:key].to_s.intern
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ return
+ end
+ value = @@items[key].to_s
+ m.reply "#{key}: #{value}"
+ end
+
+ def handle_desc(m, params)
+ key = params[:key].to_s.intern
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ end
+ puts @@items[key].inspect
+ m.reply "#{key}: #{@@items[key].desc}"
+ end
+
+ def handle_unset(m, params)
+ key = params[:key].to_s.intern
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ end
+ @@items[key].unset
+ handle_get(m, params)
+ m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
+ end
+
+ def handle_set(m, params)
+ key = params[:key].to_s.intern
+ value = params[:value].join(" ")
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ return
+ end
+ begin
+ @@items[key].set_string(value)
+ rescue ArgumentError => e
+ m.reply "failed to set #{key}: #{e.message}"
+ return
+ end
+ if @@items[key].requires_restart
+ m.reply "this config change will take effect on the next restart"
+ else
+ m.okay
+ end
+ end
+
+ def handle_add(m, params)
+ key = params[:key].to_s.intern
+ value = params[:value]
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ return
+ end
+ unless @@items[key].class <= BotConfigArrayValue
+ m.reply "config key #{key} is not an array"
+ return
+ end
+ begin
+ @@items[key].add(value)
+ rescue ArgumentError => e
+ m.reply "failed to add #{value} to #{key}: #{e.message}"
+ return
+ end
+ handle_get(m,{:key => key})
+ m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
+ end
+
+ def handle_rm(m, params)
+ key = params[:key].to_s.intern
+ value = params[:value]
+ unless @@items.has_key?(key)
+ m.reply "no such config key #{key}"
+ return
+ end
+ unless @@items[key].class <= BotConfigArrayValue
+ m.reply "config key #{key} is not an array"
+ return
+ end
+ begin
+ @@items[key].rm(value)
+ rescue ArgumentError => e
+ m.reply "failed to remove #{value} from #{key}: #{e.message}"
+ return
+ end
+ handle_get(m,{:key => key})
+ m.reply "this config change will take effect on the next restart" if @@items[key].requires_restart
+ end
+
+ def handle_help(m, params)
+ topic = params[:topic]
+ case topic
+ when false
+ m.reply "config module - bot configuration. usage: list, desc, get, set, unset, add, rm"
+ when "list"
+ m.reply "config list => list configuration modules, config list <module> => list configuration keys for module <module>"
+ when "get"
+ m.reply "config get <key> => get configuration value for key <key>"
+ when "unset"
+ m.reply "reset key <key> to the default"
+ when "set"
+ m.reply "config set <key> <value> => set configuration value for key <key> to <value>"
+ when "desc"
+ m.reply "config desc <key> => describe what key <key> configures"
+ when "add"
+ m.reply "config add <value> to <key> => add value <value> to key <key> if <key> is an array"
+ when "rm"
+ m.reply "config rm <value> from <key> => remove value <value> from key <key> if <key> is an array"
+ else
+ m.reply "no help for config #{topic}"
+ end
+ end
+ def usage(m,params)
+ m.reply "incorrect usage, try '#{@@bot.nick}: help config'"