Permalink
Browse files

Add support for several URL titles in one message

Bloody buggering hell! It pisses me off every time when I see a sentence
containing a couple of URLs and pookie prints only one title. It prints
the title of the very first frigging URL, completely ignoring the other
ones. With help of this commit no-one will hide from us his evil links
anymore.

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
  • Loading branch information...
1 parent 32eaaab commit 894ee4212c31cabf7dcd991f35785314fd308d0c @kyrylo kyrylo committed Aug 25, 2012
Showing with 6 additions and 9 deletions.
  1. +6 −9 handlers/url_handler.rb
@@ -327,8 +327,6 @@ class UrlHandler < Marvin::CommandHandler
503 => "Service unavailable",
}
- URL_MATCHER_RE = %r{((f|ht)tps?://.*?)(?:\s|$)}i
-
IGNORE_NICKS = [
/^CIA-\d+$/,
/^travis-ci/,
@@ -345,22 +343,21 @@ def handle_incoming_message(args)
p args
- if args[:message] =~ URL_MATCHER_RE
- urlstr = $1.gsub(/([\)}\],.;!?]|\.{2,3})$/, '')
+ url_list = URI.extract(args[:message])
- logger.info "Getting info for #{urlstr}..."
+ url_list.each do |url|
+ logger.info "Getting info for #{url}..."
- #title = get_title_for_url urlstr
- page = agent.get(urlstr)
- #title = get_title urlstr
+ #title = get_title_for_url url
+ page = agent.get(url)
+ #title = get_title url
if page.respond_to? :link_info and title = page.link_info
say title, args[:target]
logger.info title
else
logger.info "Link info not found!"
end
-
end
rescue Mechanize::ResponseCodeError, SocketError => e

0 comments on commit 894ee42

Please sign in to comment.