X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgames%2Fhangman.rb;h=612b83501e68374053193782722e8c475d9b434e;hb=c4e7896a87d97988926d3b57f62599384c5c7189;hp=dbabb72c6fbb98520c5c4a6a552ae81d17b2756a;hpb=52c9564c96dbf95e5c883e41940527f2394ba55a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/hangman.rb b/data/rbot/plugins/games/hangman.rb index dbabb72c..612b8350 100644 --- a/data/rbot/plugins/games/hangman.rb +++ b/data/rbot/plugins/games/hangman.rb @@ -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{_<) ', ' (-_-) ', ' (o_~) ', ' (^_^) ', '\(^o^)/'] HEALTH = STAGES.size-1 @@ -241,16 +242,16 @@ class HangmanPlugin < Plugin def help(plugin, topic="") case topic - when "" - return "hangman game plugin - topics: play, stop" when "play" - return "hangman play on with word => use in private chat with the bot to start a game with custom word\n"+ - "hangman play random [with [max|min] length [<|>|== ]] => hangman with a random word from #{RandomWord::SITE}\n"+ - "hangman play with wordlist => hangman with random word from " + return [_("hangman play on with word => use in private chat with the bot to start a game with custom word\n"), + _("hangman play random [with [max|min] length [<|>|== ]] => hangman with a random word from %{site}\n"), + _("hangman play with wordlist => hangman with random word from ")].join % { :site => RandomWord::SITE } when "stop" - return "hangman stop => quits the current game" + return _("hangman stop => quits the current game") when "define" - return "define => seeks a definition for the previous answer using google" + return _("hangman define => seeks a definition for the previous answer using google") + else + return _("hangman game plugin - topics: play, stop, define") end end @@ -261,7 +262,7 @@ class HangmanPlugin < Plugin begin wordlist = Wordlist.get(params[:wordlist].join("/"), :spaces => true) rescue - raise "no such wordlist" + raise _("no such wordlist") end wordlist[rand(wordlist.size)] @@ -282,7 +283,7 @@ class HangmanPlugin < Plugin unless words.empty? words.first else - m.reply "suitable word not found in the set" + m.reply _("suitable word not found in the set") nil end else @@ -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 @@ -371,7 +372,7 @@ class HangmanPlugin < Plugin _("you've killed the poor guy :(") end - again = _("go #{Bold}again#{Bold}?") + again = _("go %{b}again%{b}?") % { :b => Bold } scores = [] game.scores.each do |user, score| @@ -389,12 +390,12 @@ class HangmanPlugin < Plugin end m.reply _("%{sentence} %{again} %{scores}") % { - :sentence => sentence, :again => again, :scores => scores + :sentence => sentence, :again => again, :scores => scores.join(' ') }, :nick => true if rand(5).zero? - m.reply _("wondering what that means? try ´%{prefix}define´") % { - :prefix => @bot.config['core.address_prefix'] + m.reply _("wondering what that means? try ´%{prefix}hangman define´") % { + :prefix => @bot.config['core.address_prefix'].first } 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 @@ -496,4 +502,4 @@ plugin.map "hangman stop", :action => 'stop' plugin.map "hangman score [:nick]", :action => 'score' plugin.map "hangman stats", :action => 'stats' -plugin.map "define", :action => 'define' +plugin.map "hangman define", :action => 'define'