- if page =~ /&skip=(\d+)">prev<\/a>/
- numdefs = $1.to_i + 1
- else
- numdefs = 1
- end
- n = numdefs + n + 1 if n < 0
- if n > numdefs
- m.reply "Urban dictionary only has #{numdefs} definitions for '#{words}'"
- n = numdefs
- end
- if n < numdefs
- uri = URI.parse("http://www.urbanwap.com/search.php?term=#{URI.escape words}&skip=#{n-1}")
- page = @bot.httputil.get_cached(uri)
- if page.nil?
- case n % 10
- when 1
- ord = 'st'
- when 2
- ord = 'nd'
- when 3
- ord = 'rd'
- else
- ord = 'th'
- end
- m.reply "Couldn't retrieve the #{n}#{ord} urban dictionary definition of #{words}"
- return
- end
- end
- m.reply "#{get_def(page)} (#{n}/#{numdefs})"
- end