X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fcore%2Fconfig.rb;h=717408a23e286d215f88ee91672467a165468186;hb=57e7f0b22d7188c1d29c7b020a93450cda202ca8;hp=9de7a8613e81bb2455fb384c8a38560ed5907ff7;hpb=12906a51f698aebe1c9a5e19b15555ebbbcc4368;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb index 9de7a861..717408a2 100644 --- a/lib/rbot/core/config.rb +++ b/lib/rbot/core/config.rb @@ -9,6 +9,14 @@ class ConfigModule < CoreBotModule + def version_string + _("I'm a v. %{version} rubybot%{copyright}%{url}") % { + :version => $version, + :copyright => ", #{Irc::Bot::COPYRIGHT_NOTICE}", + :url => " - #{Irc::Bot::SOURCE_URL}" + } + end + def save @bot.config.save end @@ -22,7 +30,7 @@ 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 @@ -38,7 +46,7 @@ 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) @@ -49,43 +57,42 @@ 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}" unless params[:silent] + 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}" unless params[:silent] + 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" unless params[:silent] + 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" unless params[:silent] + m.reply _("this config change will take effect on the next rescan") unless params[:silent] return :rescan else m.okay unless params[:silent] @@ -97,46 +104,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].kind_of?(BotConfigArrayValue) - m.reply "config key #{key} is not an array" + 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].kind_of?(BotConfigArrayValue) - m.reply "config key #{key} is not an array" + 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) @@ -145,11 +152,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. #{@bot.plugins.status(true)}" + m.reply _("done. %{plugin_status}") % {:plugin_status => @bot.plugins.status(true)} end def bot_nick(m, param) @@ -168,7 +175,19 @@ class ConfigModule < CoreBotModule # end def bot_version(m, param) - m.reply "I'm a v. #{$version} rubybot, (c) Tom Gilbert and the rbot development team - http://linuxbrit.co.uk/rbot/" + m.reply version_string + end + + def ctcp_listen(m) + who = m.private? ? "me" : m.target + case m.ctcp.intern + when :VERSION + m.ctcp_reply version_string + @bot.irclog "@ #{m.source} asked #{who} about version info" + when :SOURCE + m.ctcp_reply Irc::Bot::SOURCE_URL + @bot.irclog "@ #{m.source} asked #{who} about source info" + end end def handle_help(m, params) @@ -180,32 +199,34 @@ class ConfigModule < CoreBotModule when "config" case topic when "" - "config-related tasks: config topics, save, rescan" + _("config-related tasks: config topics, save, rescan") when "list" - "config list => list configuration modules, config list => list configuration keys for module " + _("config list => list configuration modules, config list => list configuration keys for module ") when "get" - "config get => get configuration value for key " + _("config get => get configuration value for key ") when "unset" - "reset key to the default" + _("reset key to the default") when "set" - "config set => set configuration value for key to " + _("config set => set configuration value for key to ") when "desc" - "config desc => describe what key configures" + _("config desc => describe what key configures") when "add" - "config add to => add value to key if is an array" + _("config add to => add value to key if is an array") when "rm" - "config rm from => remove value from key if is an array" + _("config rm from => remove value from key if is an array") else - "config module - bot configuration. usage: list, desc, get, set, unset, add, rm" + _("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" + _("save => save current dynamic data and configuration") when "rescan" - "rescan => reload modules and static facts" + _("rescan => reload modules and static facts") + when "version" + _("version => describes software version") else - "config-related tasks: config, save, rescan" + _("config-related tasks: config, save, rescan, version") end end