diff --git a/Gemfile b/Gemfile index c791fe4..af38b76 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,5 @@ gem "eventmachine" gem "em-irc" gem "logger" gem "nokogiri" +gem "datamapper" +gem "dm-postgres-adapter" diff --git a/plugins/scrape.rb b/plugins/scrape.rb index 9790e21..26fa03f 100644 --- a/plugins/scrape.rb +++ b/plugins/scrape.rb @@ -1,9 +1,17 @@ +require 'open-uri' +require 'digest/md5' + include EventMachine::IRC::Commands Client.register_trigger("PRIVMSG") { |msg| - message = msg[:params][1] - - message.split { |word| - puts word if word ~ /4cdn[.]org/ + 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 } }