From a10c409b416f6f6eeba937ca6d94917eddc552a8 Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Sat, 24 Nov 2007 16:09:04 +0000 Subject: * (plugins/urban) only return 1 answer; other minor improvements --- data/rbot/plugins/urban.rb | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/urban.rb b/data/rbot/plugins/urban.rb index 21eb374c..6cb166a8 100644 --- a/data/rbot/plugins/urban.rb +++ b/data/rbot/plugins/urban.rb @@ -5,42 +5,44 @@ class UrbanPlugin < Plugin "urban [word] [n]: give the [n]th definition of [word] from urbandictionary.com. urbanday: give the word-of-the-day at urban" end + def format_definition(total, num, word, desc, ex) + "#{Bold}#{word} (#{num}/#{total})#{Bold}: " + + desc.ircify_html(:limit => 300) + " " + + "#{ex}".ircify_html(:limit => 100) + end + def get_def(m, word, n = nil) - n = n.to_i if n + n = n ? n.to_i : 1 u = URBAN + CGI.escape(word) u += '&skip=' + n.to_s if n 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 - else - total = 1 end - n = total if n && n > total - rv = Array.new - s.scan(%r{]*>(\d+)\..*?(?:)?([^>]+)(?:)?.*?
.*?

(.+?)

.*?

300) + " " + - "#{a4}".ircify_html(:limit => 100) - ) unless (n && n != a1.to_i) || rv.size >= 3 + s.scan(%r{]*>(\d+)\..*?(?:)?([^>]+)(?:)?.*?

.*?

(.+?)

.*?

total ? rv.last : rv.first) + m.reply format_definition(total, *answer) end def urban(m, params) -- cgit v1.2.3