-
- soup = BeautifulSoup.new( @bot.httputil.get_cached( uri ) )
- if titleNavi = soup.find_all( 'td', :attrs => { 'class' => 'def_word' } )[0] then
- title = titleNavi.contents
- results = soup.find_all( 'div', :attrs => { 'class' => 'def_p' } )
- # debug PP.pp(results,'')
- output = Array.new
- if results[definitionN] then
- results[definitionN].p.contents.each { |s| output.push( strip_tags( s.to_s ) ) }
- m.reply "\002#{title}\002 - #{output} (#{definitionN+1}/#{results.length})"
- else
- m.reply "#{query} does not have #{definitionN + 1} definitions."
- end
+ # we give a very high 'skip' because this will allow us to get the number of definitions by retrieving the previous definition
+ uri = URI.parse("http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=65536")
+ page = @bot.httputil.get(uri)
+ if page.nil?
+ m.reply "Couldn't retrieve an urban dictionary definition of #{words}"
+ return
+ end
+ if page =~ / is undefined<\/card><\/wml>/
+ m.reply "There is no urban dictionary definition of #{words}"
+ return
+ end
+ if page =~ /&skip=(\d+)">prev<\/a>/
+ numdefs = $1.to_i + 1