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
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
end
class Hangman
- attr_reader :misses, :guesses, :word, :letters, :scores
+ attr_reader :misses, :guesses, :word, :scores
STAGES = [' (x_x) ', ' (;_;) ', ' (>_<) ', ' (-_-) ', ' (o_~) ', ' (^_^) ', '\(^o^)/']
HEALTH = STAGES.size-1
def help(plugin, topic="")
case topic
- when ""
- return "hangman game plugin - topics: play, stop"
when "play"
- return "hangman play on <channel> with word <word> => use in private chat with the bot to start a game with custom word\n"+
- "hangman play random [with [max|min] length [<|>|== <length>]] => hangman with a random word from #{RandomWord::SITE}\n"+
- "hangman play with wordlist <wordlist> => hangman with random word from <wordlist>"
+ return [_("hangman play on <channel> with word <word> => use in private chat with the bot to start a game with custom word\n"),
+ _("hangman play random [with [max|min] length [<|>|== <length>]] => hangman with a random word from %{site}\n"),
+ _("hangman play with wordlist <wordlist> => hangman with random word from <wordlist>")].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
begin
wordlist = Wordlist.get(params[:wordlist].join("/"), :spaces => true)
rescue
- raise "no such wordlist"
+ raise _("no such wordlist")
end
wordlist[rand(wordlist.size)]
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
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
_("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|
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
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
plugin.map "hangman score [:nick]", :action => 'score'
plugin.map "hangman stats", :action => 'stats'
-plugin.map "define", :action => 'define'
+plugin.map "hangman define", :action => 'define'