From 9967d64936c75b40322259301d112b54ce5a84f5 Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Sun, 16 Sep 2007 23:09:11 +0000 Subject: * (plugins/url) url logging should not depend on url info display --- data/rbot/plugins/url.rb | 51 ++++++++++++++++++++---------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'data/rbot/plugins/url.rb') diff --git a/data/rbot/plugins/url.rb b/data/rbot/plugins/url.rb index 296ece33..6e609130 100644 --- a/data/rbot/plugins/url.rb +++ b/data/rbot/plugins/url.rb @@ -152,35 +152,28 @@ class UrlPlugin < Plugin def handle_urls(m, urls, display_info=@bot.config['url.display_link_info']) return if urls.empty? debug "found urls #{urls.inspect}" - if m.public? - list = @registry[m.target] - else - list = nil - end + list = m.public? ? @registry[m.target] : nil + debug "display link info: #{display_info}" urls_displayed = 0 - urls.each { |urlstr| + urls.each do |urlstr| debug "working on #{urlstr}" next unless urlstr =~ /^https?:/ title = nil - debug "display link info: #{display_info}" + debug "Getting title for #{urlstr}..." + begin + title = get_title_for_url(urlstr, + :nick => m.source.nick, + :channel => m.channel, + :ircline => m.message) + debug "Title #{title ? '' : 'not '} found" + rescue => e + m.reply "Error #{e.message}" + end + if display_info > urls_displayed - urls_displayed += 1 - Thread.start do - debug "Getting title for #{urlstr}..." - begin - title = get_title_for_url(urlstr, - :nick => m.source.nick, - :channel => m.channel, - :ircline => m.message) - if title - m.reply "#{LINK_INFO} #{title}", :overlong => :truncate - debug "Title found!" - else - debug "Title not found!" - end - rescue => e - m.reply "Error #{e.message}" - end + if title + m.reply("#{LINK_INFO} #{title}", :overlong => :truncate) + urls_displayed += 1 end end @@ -191,20 +184,18 @@ class UrlPlugin < Plugin url = Url.new(m.target, m.sourcenick, Time.new, urlstr, title) debug "#{list.length} urls so far" - if list.length > @bot.config['url.max_urls'] - list.pop - end + list.pop if list.length > @bot.config['url.max_urls'] debug "storing url #{url.url}" list.unshift url debug "#{list.length} urls now" - } + end @registry[m.target] = list end def info(m, params) escaped = URI.escape(params[:urls].to_s, OUR_UNSAFE) urls = URI.extract(escaped) - handle_urls(m, urls, params[:urls].length) + Thread.new { handle_urls(m, urls, params[:urls].length) } end def listen(m) @@ -213,7 +204,7 @@ class UrlPlugin < Plugin escaped = URI.escape(m.message, OUR_UNSAFE) urls = URI.extract(escaped) - handle_urls(m, urls) + Thread.new { handle_urls(m, urls) } end def reply_urls(opts={}) -- cgit v1.2.3