summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kim <dmitry point kim at gmail point com>2007-09-16 23:09:11 +0000
committerDmitry Kim <dmitry point kim at gmail point com>2007-09-16 23:09:11 +0000
commit9967d64936c75b40322259301d112b54ce5a84f5 (patch)
tree58e3a9a164cf8721d0dd6feba27f02a2dbd539fc
parent87e7db2b40eb31b33f27e7c3bb7eeb256724718a (diff)
* (plugins/url) url logging should not depend on url info display
-rw-r--r--data/rbot/plugins/url.rb51
1 files changed, 21 insertions, 30 deletions
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={})