#
# TODO:: some sort of turn-basedness, maybe
-module RandomWord
- SITE = "http://coyotecult.com/tools/randomwordgenerator.php"
-
- def self.get(count=1)
- res = Net::HTTP.post_form(URI.parse(SITE), {'numwords' => count})
- words = res.body.scan(%r{<a.*?\?w=(.*?)\n}).flatten
-
- count == 1 ? words.first : words
- end
-end
+# https://www.wordgenerator.net/application/p.php?type=2&id=dictionary_words&spaceflag=false
-module Google
- URL = "http://www.google.com/wml/search?hl=en&q=define:"
- REGEX = %r{Web definitions for .*?<br/>(.*?)<br/>}
+module RandomWord
+ SITE = 'https://www.wordgenerator.net/random-word-generator.php'
+ BASE_URL = 'https://www.wordgenerator.net/application/p.php'
- def self.define(phrase)
- raw = Net::HTTP.get(URI.parse(URL+CGI.escape(phrase)))
- res = raw.scan(REGEX).flatten.map { |e| e.strip }
+ # we could allow to specify by word types: (defaults to all)
+ TYPES = {
+ all: 'dictionary_words',
+ noun: 'nouns',
+ adj: 'adjectives',
+ verb: 'action_verbs'
+ }
- res.empty? ? false : res.last
+ def self.get(bot, type)
+ bot.httputil.get("#{BASE_URL}?type=1&id=#{TYPES[type]}&spaceflag=false", cache: false).split(',')
end
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"
- when "define"
- return "define => seeks a definition for the previous answer using google"
+ return _("hangman stop => quits the current game")
+ else
+ return _("hangman game plugin - topics: play, stop")
end
end
params[:word].join(" ")
elsif params[:wordlist]
begin
- wordlist = Wordlist.get(params[:wordlist].join("/"), :spaces => true)
+ wordlist = Wordlist.get(@bot, params[:wordlist].join("/"), :spaces => true)
rescue
- raise "no such wordlist"
+ raise _("no such wordlist")
end
wordlist[rand(wordlist.size)]
else # getting a random word
- words = RandomWord::get(100)
+ words = RandomWord::get(@bot, :all)
if adj = params[:adj]
words = words.sort_by { |e| e.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
end
if game.over?
- str = if game.won?
+ sentence = if game.won?
_("you nailed it!")
elsif game.lost?
_("you've killed the poor guy :(")
end
- str << _(" go #{Bold}again#{Bold}?")
+ again = _("go %{b}again%{b}?") % { :b => Bold }
+ scores = []
game.scores.each do |user, score|
- str << " #{user.nick}: "
+ str = "#{user.nick}: "
str << if score > 0
Irc.color(:green)+'+'
elsif score < 0
str << score.round.to_s
str << Irc.color
+
+ scores << str
end
- m.reply str, :nick => true
+ m.reply _("%{sentence} %{again} %{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}oxford <word>´") % {
+ :prefix => @bot.config['core.address_prefix'].first
}
end
score(m, params)
end
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}"
- end
- end
end
plugin = HangmanPlugin.new
plugin.map "hangman score [:nick]", :action => 'score'
plugin.map "hangman stats", :action => 'stats'
-plugin.map "define", :action => 'define'