Possibly, it'll work now.

master
Robert Gerus 2014-03-10 08:40:39 +01:00
parent b476ced1a3
commit abff24f33f
1 changed files with 40 additions and 6 deletions

View File

@ -3,15 +3,49 @@ require 'digest/md5'
include EventMachine::IRC::Commands
DataMapper.setup(:default, Config[:scrape][:db])
module Scrape
def download(uri)
ext = "." + word.sub(/.*[.]([^.]*)/, '\1') if word.match(/[^.]+[.][^.]+/)
content = open(word).read
md5 = Digest::MD5.hexdigest(content)
File.open(Config[:scrape][:basepath] + md5 + ext, 'w') do |file|
file.write(content)
end
return md5 + ext
end
class Link
include DataMapper::Resource
property :id, Serial
property :url, String
property :original_url, String
property :created_at, DateTime
property :nick, String
end
end
DataMapper.auto_upgrade!
Client.register_trigger("PRIVMSG") do |msg|
msg[:params].each do |word|
if word =~ /4cdn[.]org/ then
ext = "." + word.sub(/.*[.]([^.]*)/, '\1') if word.match(/[^.]+[.][^.]+/)
content = open(word).read
md5 = Digest::MD5.hexdigest(content)
File.open(Config[:scrape][:basepath] + md5 + ext, 'w') do |file|
file.write(content)
if word =~ /^https?:\/\// then
original_url = word
if word =~ /4cdn[.]org/ then
url = download(word)
else
url = Digest::MD5.hexdigest(word)
end
Scrape::Link.create(
:url => url,
:original_url => original_url,
:created_at => Time.now,
:nick => msg[:prefix].split('!').first
)
end
end
end