- 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."
+ maxnum = rv.collect {|x| x[0]}.max || 0
+ return m.reply("#{Bold}#{word}#{Bold} not found") if rv.empty?
+
+ if notfound
+ suggestions = rv.map { |s| Underline + s[1] + Underline }.uniq.join ', '
+ m.reply "#{Bold}#{word}#{Bold} not found. maybe you mean #{suggestions}?"
+ return
+ end
+
+ answer = rv.find { |a| a[0] == n }
+ answer ||= (n > maxnum ? rv.last : rv.first)
+ m.reply format_definition((p == numpages ? maxnum : "#{(numpages-1)*7 + 1}+"), *answer)
+ end
+
+ def urban(m, params)
+ words = params[:words].to_s
+ if words.empty?
+ resp = @bot.httputil.head('http://www.urbandictionary.com/random.php',
+ :max_redir => -1,
+ :cache => false)
+ return m.reply "Couldn't get a random urban dictionary word" if resp.nil?
+ if resp.code == "302" && (loc = resp['location'])
+ words = URI.unescape(loc.match(/define.php\?term=(.*)$/)[1]) rescue nil