X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Furban.rb;h=d4aaef6296ac077d90253de350d15f8c534d9b88;hb=1c6b09968776c94b812317dfc4f91f09b5f0817c;hp=6cb166a80cbe436114d980cf5582d10d6cfa01f7;hpb=a10c409b416f6f6eeba937ca6d94917eddc552a8;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/urban.rb b/data/rbot/plugins/urban.rb index 6cb166a8..d4aaef62 100644 --- a/data/rbot/plugins/urban.rb +++ b/data/rbot/plugins/urban.rb @@ -13,36 +13,32 @@ class UrbanPlugin < Plugin def get_def(m, word, n = nil) n = n ? n.to_i : 1 - u = URBAN + CGI.escape(word) - u += '&skip=' + n.to_s if n + p = (n-1)/7 + 1 + u = URBAN + URI.escape(word) + u += '&page=' + p.to_s if p > 1 s = @bot.httputil.get(u) notfound = s.match %r{
.*? isn't defined} - total = nil - if s.sub!(%r{
(\d+)\s*definition.*$}m, '') - total = $1.to_i - end + numpages = s[%r{
.*?
}m].scan(/\d+/).collect {|x| x.to_i}.max || 1 rv = Array.new - - s.scan(%r{]*>(\d+)\..*?(?:)?([^>]+)(?:)?.*?
.*?

(.+?)

.*?

total ? rv.last : rv.first) - m.reply format_definition(total, *answer) + answer ||= (n > maxnum ? rv.last : rv.first) + m.reply format_definition((p == numpages ? maxnum : "#{(numpages-1)*7 + 1}+"), *answer) end def urban(m, params)