From 648bbc741d2b18c0b77f2b5180390bc8af5dca61 Mon Sep 17 00:00:00 2001 From: Robert Gerus Date: Tue, 25 Mar 2014 10:13:25 +0100 Subject: [PATCH] small fixes for scrape. --- plugins/scrape.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/scrape.rb b/plugins/scrape.rb index d30e0fc..ff64661 100644 --- a/plugins/scrape.rb +++ b/plugins/scrape.rb @@ -33,6 +33,7 @@ end DataMapper.auto_upgrade! Client.register_trigger("PRIVMSG") do |msg| + titles = [] return 0 if msg[:params][1].nil? msg[:params][1].split.each do |word| return 0 if word =~ /notitle/ @@ -44,7 +45,7 @@ Client.register_trigger("PRIVMSG") do |msg| url = Digest::MD5.hexdigest(word) end - title = Nokogiri::HTML(open(word).read(10240)).title().split(/\n/)[0] + title = Nokogiri::HTML(open(word).read(10240)).title().delete!('\n') Scrape::Link.create( :url => url, @@ -53,8 +54,11 @@ Client.register_trigger("PRIVMSG") do |msg| :nick => msg[:prefix].split('!').first ) + titles << title + Client.privmsg(msg[:params][0], Config[:scrape][:title_prefix] + title) if not title.nil? - return 0 end end + + Client.privmsg(msg[:params][0], Config[:scrape][:title_prefix] + titles.join(' ')) if not titles.count < 1 end