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."
20 unless(m.params && m.params.length > 0)
21 m.reply "incorrect usage: " + help(m.plugin)
25 paramArray = m.params.split(' ')
27 if m.params == 'random' then
28 uri = URI.parse( "http://www.urbandictionary.com/random.php" )
30 if( paramArray.last.to_i != 0 ) then
31 definitionN = paramArray.last.to_i - 1
32 query = m.params.chomp( paramArray.last )
37 uri = URI.parse( "http://www.urbandictionary.com/define.php?term=#{ URI.escape query}" )
40 soup = BeautifulSoup.new( @bot.httputil.get_cached( uri ) )
41 if titleNavi = soup.find_all( 'td', :attrs => { 'class' => 'def_word' } )[0] then
42 title = titleNavi.contents
43 results = soup.find_all( 'div', :attrs => { 'class' => 'def_p' } )
44 # debug PP.pp(results,'')
46 if results[definitionN] then
47 results[definitionN].p.contents.each { |s| output.push( strip_tags( s.to_s ) ) }
48 m.reply "\002#{title}\002 - #{output}"
50 m.reply "#{query} does not have #{definitionN + 1} definitions."
53 m.reply "#{m.params} not found."
59 html.gsub(/<.+?>/,'').
64 gsub(/&ellip;/,'...').
70 plugin = UrbanPlugin.new
71 plugin.register( "urban" )