repost/plugins/scrape.rb

18 lines
517 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
2014-03-09 18:59:42 +00:00
Client.register_trigger("PRIVMSG") do |msg|
msg[:params].each do |word|
2014-03-09 18:40:32 +00:00
if word =~ /4cdn[.]org/ then
ext = "." + word.sub(/.*[.]([^.]*)/, '\1') if word.match(/[^.]+[.][^.]+/)
content = open(word).read
md5 = Digest::MD5.hexdigest(content)
2014-03-09 18:59:42 +00:00
File.open(Config[:scrape][:basepath] + md5 + ext, 'w') do |file|
2014-03-09 18:40:32 +00:00
file.write(content)
2014-03-09 18:59:42 +00:00
end
2014-03-09 18:40:32 +00:00
end
2014-03-09 18:59:42 +00:00
end
end