]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/rot13.rb
script plugin: hook on message() rather than listen()
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / rot13.rb
index 447d0803198d1342d7d5fc258a65d86192f01c0c..36155962953ea07247bd01439bb779b83e380a84 100644 (file)
@@ -1,9 +1,24 @@
+#-- 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 rot13(m, params)
-    m.reply params[:string].join(" ").tr("A-Za-z", "N-ZA-Mn-za-m");
+    m.reply @bot.filter(:rot13, params[:string].to_s)
   end
 end
 plugin = RotPlugin.new