X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Furban.rb;h=a24ac072091f7ed3d4d75031da89460060d94829;hb=26d2e36ff08de4e3bbf510616d4c8dac6da9d6d0;hp=95210b252460980d7918c9067327ce929685189e;hpb=1d7ab28b2162db5c3a7b332a2f268d496b7c3c60;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/urban.rb b/data/rbot/plugins/urban.rb index 95210b25..a24ac072 100644 --- a/data/rbot/plugins/urban.rb +++ b/data/rbot/plugins/urban.rb @@ -1,96 +1,77 @@ -require 'uri' - class UrbanPlugin < Plugin + URBAN = 'http://www.urbandictionary.com/define.php?term=' def help( plugin, topic="") "urban [word] [n]: give the [n]th definition of [word] from urbandictionary.com. urbanday: give the word-of-the-day at urban" end - def urban(m, params) - words = params[:words].to_s - n = params[:n].nil? ? 1 : params[:n].to_i rescue 1 + def format_definition(total, num, word, desc, ex) + "#{Bold}#{word} (#{num}/#{total})#{Bold}: " + + desc.ircify_html(:limit => 300) + " " + + "#{ex}".ircify_html(:limit => 100) + end - if words.empty? - uri = URI.parse( "http://www.urbandictionary.com/random.php" ) - @bot.httputil.head(uri) { |redir| - words = URI.unescape(redir.match(/define.php\?term=(.*)$/)[1]) rescue nil - } + def get_def(m, word, n = nil) + n = n ? n.to_i : 1 + u = URBAN + URI.escape(word) + u += '&skip=' + n.to_s if n + s = @bot.httputil.get(u) + + notfound = s.match %r{