5 warning "could not load rubyful_soup, urban dictionary disabled"
6 warning "please get it from http://www.crummy.com/software/RubyfulSoup/"
7 warning "or install it via gem"
12 class UrbanPlugin < Plugin
14 def help( plugin, topic="")
15 "urban [word] [n]. Give the [n]th definition of [word] from urbandictionary.com."
22 paramArray = m.params.split(' ')
23 if paramArray.last.to_i != 0
24 definitionN = paramArray.last.to_i - 1
25 query = m.params.chomp( paramArray.last )
30 uri = URI.parse( "http://www.urbandictionary.com/define.php?term=#{ URI.escape query}" )
32 uri = URI.parse( "http://www.urbandictionary.com/random.php" )
35 soup = BeautifulSoup.new( @bot.httputil.get_cached( uri ) )
36 if titleNavi = soup.find_all( 'td', :attrs => { 'class' => 'def_word' } )[0] then
37 title = titleNavi.contents
38 results = soup.find_all( 'div', :attrs => { 'class' => 'def_p' } )
39 # debug PP.pp(results,'')
41 if results[definitionN] then
42 results[definitionN].p.contents.each { |s| output.push( strip_tags( s.to_s ) ) }
43 m.reply "\002#{title}\002 - #{output} (#{definitionN+1}/#{results.length})"
45 m.reply "#{query} does not have #{definitionN + 1} definitions."
48 m.reply "#{m.params} not found."
53 html.gsub(/<.+?>/,'').
58 gsub(/&ellip;/,'...').
64 plugin = UrbanPlugin.new
65 plugin.register( "urban" )