5 class UrbanPlugin < Plugin
7 def help( plugin, topic="")
8 "~urban [word] [n]. Give the [n]th definition of [word] from urbandictionary.com."
13 unless(m.params && m.params.length > 0)
14 m.reply "incorrect usage: " + help(m.plugin)
18 paramArray = m.params.split(' ')
20 if m.params == 'random' then
21 uri = URI.parse( "http://www.urbandictionary.com/random.php" )
23 if( paramArray.last.to_i != 0 ) then
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}" )
33 soup = BeautifulSoup.new( @bot.httputil.get( uri ) )
34 if titleNavi = soup.find_all( 'td', :attrs => { 'class' => 'def_word' } )[0] then
35 title = titleNavi.contents
36 results = soup.find_all( 'div', :attrs => { 'class' => 'def_p' } )
37 debug PP.pp(results,'')
39 if results[definitionN] then
40 results[definitionN].p.contents.each { |s| output.push( strip_tags( s.to_s ) ) }
41 m.reply "\002#{title}\002 - #{output}"
43 m.reply "#{query} does not have #{definitionN + 1} definitions."
46 m.reply "#{m.params} not found."
52 html.gsub(/<.+?>/,'').
57 gsub(/&ellip;/,'...').
63 plugin = UrbanPlugin.new
64 plugin.register( "urban" )