small fixes for scrape.

master
Robert Gerus 2014-03-25 10:13:25 +01:00
parent 694de5fdb7
commit 648bbc741d
1 changed files with 6 additions and 2 deletions

View File

@ -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