Possibly, it'll work now.
parent
b476ced1a3
commit
abff24f33f
|
@ -3,15 +3,49 @@ require 'digest/md5'
|
||||||
|
|
||||||
include EventMachine::IRC::Commands
|
include EventMachine::IRC::Commands
|
||||||
|
|
||||||
Client.register_trigger("PRIVMSG") do |msg|
|
DataMapper.setup(:default, Config[:scrape][:db])
|
||||||
msg[:params].each do |word|
|
|
||||||
if word =~ /4cdn[.]org/ then
|
module Scrape
|
||||||
|
def download(uri)
|
||||||
ext = "." + word.sub(/.*[.]([^.]*)/, '\1') if word.match(/[^.]+[.][^.]+/)
|
ext = "." + word.sub(/.*[.]([^.]*)/, '\1') if word.match(/[^.]+[.][^.]+/)
|
||||||
content = open(word).read
|
content = open(word).read
|
||||||
md5 = Digest::MD5.hexdigest(content)
|
md5 = Digest::MD5.hexdigest(content)
|
||||||
File.open(Config[:scrape][:basepath] + md5 + ext, 'w') do |file|
|
File.open(Config[:scrape][:basepath] + md5 + ext, 'w') do |file|
|
||||||
file.write(content)
|
file.write(content)
|
||||||
end
|
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 =~ /^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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue