summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/url.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-22 22:21:37 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-22 22:21:37 +0000
commitd8a037db9d9e00a599874b699f7ba1100df17b22 (patch)
tree8d8e62a11e7e9a84b71780ce5de59815e075652f /data/rbot/plugins/url.rb
parentd432b9e11936eebb379c6f589879dd8d40ac7163 (diff)
url plugin: use URI.extract to get urls in a message. Ensures links are properly grabbed, and grabs multiple urls in a line
Diffstat (limited to 'data/rbot/plugins/url.rb')
-rw-r--r--data/rbot/plugins/url.rb63
1 files changed, 31 insertions, 32 deletions
diff --git a/data/rbot/plugins/url.rb b/data/rbot/plugins/url.rb
index 92853481..bc96341d 100644
--- a/data/rbot/plugins/url.rb
+++ b/data/rbot/plugins/url.rb
@@ -127,44 +127,43 @@ class UrlPlugin < Plugin
def listen(m)
return unless m.kind_of?(PrivMessage)
return if m.address?
- # TODO support multiple urls in one line
- if m.message =~ /(f|ht)tps?:\/\//
- if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/
- urlstr = URI.escape $1
- list = @registry[m.target]
-
- title = nil
- if @bot.config['url.display_link_info']
- Thread.start do
- debug "Getting title for #{urlstr}..."
- begin
- title = get_title_for_url urlstr, m.source.nick, m.channel
- 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}"
+ urls = URI.extract(m.message)
+ return if urls.empty?
+ debug "found urls #{urls.inspect}"
+ list = @registry[m.target]
+ urls.each { |urlstr|
+ debug "working on #{urlstr}"
+ title = nil
+ if @bot.config['url.display_link_info']
+ Thread.start do
+ debug "Getting title for #{urlstr}..."
+ begin
+ title = get_title_for_url urlstr, m.source.nick, m.channel
+ 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
end
+ end
- # check to see if this url is already listed
- return if list.find {|u| u.url == urlstr }
+ # check to see if this url is already listed
+ next if list.find {|u| u.url == urlstr }
- 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
- debug "storing url #{url.url}"
- list.unshift url
- debug "#{list.length} urls now"
- @registry[m.target] = list
+ 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
- end
+ debug "storing url #{url.url}"
+ list.unshift url
+ debug "#{list.length} urls now"
+ }
+ @registry[m.target] = list
end
def reply_urls(opts={})