]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/translator.rb
url plugin: only chop non-word characters on 404
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / translator.rb
index 5f2dece7a942a8dcf014fd7e2568efaeeee6b55f..a32ea16dfa059d56789a83ae0f4942f4b54c1e08 100644 (file)
@@ -318,6 +318,10 @@ class TranslatorPlugin < Plugin
     end
   end
 
+  def languages
+    @languages ||= @translators.map { |t| t.last.directions.keys }.flatten.uniq
+  end
+
   def update_default
     @default_translators = bot.config['translator.default_list'] & @translators.keys
   end
@@ -353,7 +357,7 @@ class TranslatorPlugin < Plugin
         end
         m.reply(if params[:show_provider]
                   _('%{translation} (provided by %{translator})') %
-                    {:translation => translation, :translator => tname}
+                    {:translation => translation, :translator => tname.gsub("_", " ")}
                 else
                   translation
                 end)
@@ -374,7 +378,9 @@ class TranslatorPlugin < Plugin
 end
 
 plugin = TranslatorPlugin.new
+req = Hash[*%w(from to).map { |e| [e.to_sym, /#{plugin.languages.join("|")}/] }.flatten]
+
 plugin.map 'translate [:from] [:to] *phrase',
-           :action => :cmd_translator, :thread => true
+           :action => :cmd_translator, :thread => true, :requirements => req
 plugin.map 'translator [:from] [:to] *phrase',
-           :action => :cmd_translator, :thread => true
+           :action => :cmd_translator, :thread => true, :requirements => req