repost/plugins/scrape.rb

18 lines
508 B
Ruby
Raw Normal View History

2014-03-09 18:40:32 +00:00
require 'open-uri'
require 'digest/md5'
2014-03-09 18:00:52 +00:00
include EventMachine::IRC::Commands
Client.register_trigger("PRIVMSG") { |msg|
2014-03-09 18:40:32 +00:00
msg[:params].each { |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') { |file|
file.write(content)
}
end
2014-03-09 18:00:52 +00:00
}
}