]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/games/hangman.rb
time: support POSIX time
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / games / hangman.rb
index 5cef596ee9f594730677da870f52fef03ddb6307..612b83501e68374053193782722e8c475d9b434e 100644 (file)
@@ -16,6 +16,7 @@ module RandomWord
 
   def self.get(count=1)
     res = Net::HTTP.post_form(URI.parse(SITE), {'numwords' => count})
+    raise _("random word generator site failed with #{res.code} - #{res.message}") unless Net::HTTPSuccess === res
     words = res.body.scan(%r{<a.*?\?w=(.*?)\n}).flatten
 
     count == 1 ? words.first : words
@@ -28,7 +29,7 @@ module Google
 
   def self.define(phrase)
     raw = Net::HTTP.get(URI.parse(URL+CGI.escape(phrase)))
-    res = raw.scan(REGEX).flatten.map { |e| e.strip }
+    res = raw.scan(REGEX).flatten.map { |e| e.ircify_html }
 
     res.empty? ? false : res.last
   end
@@ -303,11 +304,11 @@ class HangmanPlugin < Plugin
       target = if m.public?
         m.channel
       else
-        params[:channel]
+        @bot.server.channel(params[:channel])
       end
 
       # is the bot on the channel?
-      unless @bot.server.channels.names.include?(target.to_s)
+      unless @bot.myself.channels.include?(target)
         m.reply _("i'm not on that channel")
         return
       end
@@ -479,8 +480,13 @@ class HangmanPlugin < Plugin
 
   def define(m, params)
     if game = @games.previous(m.replyto)
-      return unless res = Google.define(game.word)
-      m.reply "#{Bold}#{game.word}#{Bold} -- #{res}"
+      if res = Google.define(game.word)
+        m.reply "#{Bold}#{game.word}#{Bold} -- #{res}"
+      else
+        m.reply _("looks like google has no definition for %{word}") % { :word => game.word }
+      end
+    else
+      m.reply _("no hangman game was played here recently, what do you want me to define?")
     end
   end
 end