X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Fconfig.rb;h=f042e87e1089dc1fe40923cce2dfb34a7969847b;hb=d4ebd66d357b9200edabd1f6d4fa1b3c72d048e6;hp=47bed108a37449181486d356cb76f38e3130410b;hpb=eee6a74ea1547b5c0e8757c64cace42fc9aea9bf;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb index 47bed108..f042e87e 100644 --- a/lib/rbot/core/config.rb +++ b/lib/rbot/core/config.rb @@ -1,9 +1,18 @@ #-- vim:sw=2:et #++ - +# +# :title: rbot config management from IRC +# +# Author:: Giuseppe "Oblomov" Bilotta +# Copyright:: (C) 2006,2007 Giuseppe Bilotta +# License:: GPL v2 class ConfigModule < CoreBotModule + def save + @bot.config.save + end + def handle_list(m, params) modules = [] if params[:module] @@ -13,12 +22,12 @@ class ConfigModule < CoreBotModule modules.push key unless modules.include?(name) end if modules.empty? - m.reply "no such module #{params[:module]}" + m.reply _("no such module %{module}") % {:module => params[:module]} else m.reply modules.join(", ") end else - @bot.configitems.each_key do |key| + @bot.config.items.each_key do |key| name = key.to_s.split('.').first modules.push name unless modules.include?(name) end @@ -29,9 +38,10 @@ class ConfigModule < CoreBotModule def handle_get(m, params) key = params[:key].to_s.intern unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" + m.reply _("no such config key %{key}") % {:key => key} return end + return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto) value = @bot.config.items[key].to_s m.reply "#{key}: #{value}" end @@ -39,42 +49,46 @@ class ConfigModule < CoreBotModule def handle_desc(m, params) key = params[:key].to_s.intern unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" + m.reply _("no such config key %{key}") % {:key => key} end - puts @bot.config.items[key].inspect m.reply "#{key}: #{@bot.config.items[key].desc}" end def handle_unset(m, params) key = params[:key].to_s.intern unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" + m.reply _("no such config key %{key}") % {:key => key} end + return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto) @bot.config.items[key].unset handle_get(m, params) - m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart - m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan + m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart + m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan end def handle_set(m, params) key = params[:key].to_s.intern value = params[:value].join(" ") unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" - return + m.reply _("no such config key %{key}") % {:key => key} unless params[:silent] + return false end + return false if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto) begin @bot.config.items[key].set_string(value) rescue ArgumentError => e - m.reply "failed to set #{key}: #{e.message}" - return + m.reply _("failed to set %{key}: %{error}") % {:key => key, :error => e.message} unless params[:silent] + return false end if @bot.config.items[key].requires_restart - m.reply "this config change will take effect on the next restart" + m.reply _("this config change will take effect on the next restart") unless params[:silent] + return :restart elsif @bot.config.items[key].requires_rescan - m.reply "this config change will take effect on the next rescan" + m.reply _("this config change will take effect on the next rescan") unless params[:silent] + return :rescan else - m.okay + m.okay unless params[:silent] + return true end end @@ -82,44 +96,46 @@ class ConfigModule < CoreBotModule key = params[:key].to_s.intern value = params[:value] unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" + m.reply _("no such config key %{key}") % {:key => key} return end - unless @bot.config.items[key].class <= BotConfigArrayValue - m.reply "config key #{key} is not an array" + unless @bot.config.items[key].kind_of?(BotConfigArrayValue) + m.reply _("config key %{key} is not an array") % {:key => key} return end + return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto) begin @bot.config.items[key].add(value) rescue ArgumentError => e - m.reply "failed to add #{value} to #{key}: #{e.message}" + m.reply _("failed to add %{value} to %{key}: %{error}") % {:value => value, :key => key, :error => e.message} return end handle_get(m,{:key => key}) - m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart - m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan + m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart + m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan end def handle_rm(m, params) key = params[:key].to_s.intern value = params[:value] unless @bot.config.items.has_key?(key) - m.reply "no such config key #{key}" + m.reply _("no such config key %{key}") % {:key => key} return end - unless @bot.config.items[key].class <= BotConfigArrayValue - m.reply "config key #{key} is not an array" + unless @bot.config.items[key].kind_of?(BotConfigArrayValue) + m.reply _("config key %{key} is not an array") % {:key => key} return end + return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto) begin @bot.config.items[key].rm(value) rescue ArgumentError => e - m.reply "failed to remove #{value} from #{key}: #{e.message}" + m.reply _("failed to remove %{value} from %{key}: %{error}") % {:value => value, :key => key, :error => e.message} return end handle_get(m,{:key => key}) - m.reply "this config change will take effect on the next restart" if @bot.config.items[key].requires_restart - m.reply "this config change will take effect on the next rescan" if @bot.config.items[key].requires_rescan + m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart + m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan end def bot_save(m, param) @@ -128,11 +144,11 @@ class ConfigModule < CoreBotModule end def bot_rescan(m, param) - m.reply "saving ..." + m.reply _("saving ...") @bot.save - m.reply "rescanning ..." + m.reply _("rescanning ...") @bot.rescan - m.reply "done. #{@plugins.status(true)}" + m.reply _("done. %{plugin_status}") % {:plugin_status => @bot.plugins.status(true)} end def bot_nick(m, param) @@ -151,33 +167,44 @@ class ConfigModule < CoreBotModule # end def bot_version(m, param) - m.reply "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/" + m.reply _("I'm a v. %{version} rubybot, (c) Tom Gilbert and the rbot development team - http://linuxbrit.co.uk/rbot/") % {:version => $version} end def handle_help(m, params) m.reply help(params[:topic]) end - def help(topic="") - case topic - when false - "config module - bot configuration. usage: list, desc, get, set, unset, add, rm" - when "list" - "config list => list configuration modules, config list => list configuration keys for module " - when "get" - "config get => get configuration value for key " - when "unset" - "reset key to the default" - when "set" - "config set => set configuration value for key to " - when "desc" - "config desc => describe what key configures" - when "add" - "config add to => add value to key if is an array" - when "rm" - "config rm from => remove value from key if is an array" + def help(plugin, topic="") + case plugin + when "config" + case topic + when "" + _("config-related tasks: config topics, save, rescan") + when "list" + _("config list => list configuration modules, config list => list configuration keys for module ") + when "get" + _("config get => get configuration value for key ") + when "unset" + _("reset key to the default") + when "set" + _("config set => set configuration value for key to ") + when "desc" + _("config desc => describe what key configures") + when "add" + _("config add to => add value to key if is an array") + when "rm" + _("config rm from => remove value from key if is an array") + else + _("config module - bot configuration. usage: list, desc, get, set, unset, add, rm") + # else + # "no help for config #{topic}" + end + when "save" + _("save => save current dynamic data and configuration") + when "rescan" + _("rescan => reload modules and static facts") else - "no help for config #{topic}" + _("config-related tasks: config, save, rescan") end end @@ -249,4 +276,8 @@ conf.map 'config help :topic', conf.default_auth('*', false) conf.default_auth('show::status', true) +# TODO these shouldn't be set here, we need a way to let the default +# permission be specified together with the BotConfigValue +conf.default_auth('key', true) +conf.default_auth('key::auth::password', false)