]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rot13.rb
plugin(search): fix search and gcalc, closes #28, #29
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rot13.rb
index 1f367dbda9933ec3881ca10b0b9efd517ec8bf95..4176772631a1ec674fb7e51c1e16527488713921 100644 (file)
@@ -1,14 +1,25 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: ROT13 plugin
+#
 class RotPlugin < Plugin
+  def initialize
+    super
+    @bot.register_filter(:rot13) { |s|
+      ss = s.dup
+      ss[:text] = s[:text].tr("A-Za-z", "N-ZA-Mn-za-m")
+      ss
+    }
+  end
+
   def help(plugin, topic="")
     "rot13 <string> => encode <string> to rot13 or back"
   end
-  def privmsg(m)
-    unless(m.params && m.params =~ /^.+$/)
-      m.reply "incorrect usage: " + help(m.plugin)
-      return
-    end
-    m.reply m.params.tr("A-Za-z", "N-ZA-Mn-za-m");
+
+  def rot13(m, params)
+    m.reply @bot.filter(:rot13, params[:string].to_s).to_s
   end
 end
 plugin = RotPlugin.new
-plugin.register("rot13")
+plugin.map 'rot13 *string'