]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/shiritori.rb
+ use the message() delegate instead of listen() when possible
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / shiritori.rb
index 590e990d362a25b0567e5f2e07f903d5f9e5ffe4..84ee9620d869b566f258529345a0b8c566daad51 100644 (file)
 # playing several games, each per channel. A game can be turn-based, where only new
 # players can interrupt a turn to join, or a free mode where anyone can speak at any
 # time.
+#
+# In Japanese mode, if present, the plugin can use normalize-japanese 
+# <http://neruchan.mine.nu:60880/normalize-japanese.rb> to allow
+# katakana words be used like hiragana.
 # 
 # TODO
 # * a system to describe settings, so they can be displayed, changed and saved
@@ -199,7 +203,7 @@ class ShiritoriGame
   
   # announce the current word, and player if take_turns?
   def announce
-    say (if take_turns?
+    say(if take_turns?
       _("%{current_player}, it's your turn. %{previous_word} -> %{current_word}") %
        { :current_player => current_player, :previous_word => previous_word,
          :current_word => current_word }
@@ -367,7 +371,13 @@ class ShiritoriPlugin < Plugin
         :listen => /\A\S+\Z/u,
         :overlap_lengths => 1..4,
         :desc => 'Use Japanese words in hiragana; 1-4 kana at the beginning of the next word must overlap with those at the end of the previous word.',
-        # Optionally use a module to normalize Japanese words, enabling input in multiple writing systems
+        :normalize =>
+          begin
+            require 'normalize-japanese'
+            lambda {|w| w.to_hiragana}
+          rescue LoadError
+            lambda {|w| w}
+          end
       }
     }
   end
@@ -443,8 +453,7 @@ class ShiritoriPlugin < Plugin
   end
   
   # all messages from a channel is sent to its shiritori game if any
-  def listen(m)
-    return unless m.kind_of?(PrivMessage)
+  def message(m)
     return unless @games.has_key?(m.channel)
     # send the message to the game in the channel to handle it
     @games[m.channel].handle_message m
@@ -454,6 +463,7 @@ class ShiritoriPlugin < Plugin
   def cleanup
     @games.each_key {|g| g.die}
     @games.clear
+    super
   end
 end