X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fgames%2Fhangman.rb;h=890f821acfe1b123a71df7423bf42a2b66dca522;hb=ff6d7e5d043da99b2da36f628d52b7b5df47119d;hp=c5d7656fe3f5f31a5555525246bcd8f5ba3e33d0;hpb=74c14cc87ed58fd88acd4898372e017ebe1bbaa3;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/games/hangman.rb b/data/rbot/plugins/games/hangman.rb index c5d7656f..890f821a 100644 --- a/data/rbot/plugins/games/hangman.rb +++ b/data/rbot/plugins/games/hangman.rb @@ -11,26 +11,22 @@ # # 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{(.*?)
} +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 @@ -63,7 +59,7 @@ class Hangman 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 @@ -241,16 +237,14 @@ 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 %{site}\n"), - _("hangman play with wordlist => hangman with random word from ")].join + _("hangman play with wordlist => hangman with random word from ")].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") + else + return _("hangman game plugin - topics: play, stop") end end @@ -259,14 +253,14 @@ class HangmanPlugin < Plugin 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") 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 } @@ -303,11 +297,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 @@ -389,12 +383,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}oxford ´") % { + :prefix => @bot.config['core.address_prefix'].first } end @@ -476,13 +470,6 @@ class HangmanPlugin < Plugin 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 @@ -496,4 +483,3 @@ plugin.map "hangman stop", :action => 'stop' plugin.map "hangman score [:nick]", :action => 'score' plugin.map "hangman stats", :action => 'stats' -plugin.map "define", :action => 'define'