bookmarks.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require 'net/https'
  2. require 'cgi'
  3. require 'uri'
  4. class Bookmarks
  5. include Cinch::Plugin
  6. match /b help$/, :method => :on_help
  7. match /b (.*)$/
  8. def execute(m, link)
  9. unless link =~ URI.regexp
  10. return
  11. end
  12. title = link
  13. if open(link).read =~ /<title>(.*?)<\/title>/
  14. title = CGI.unescapeHTML($1)
  15. end
  16. base_uri = "https://link.autistici.org/"
  17. uri = URI.parse(base_uri)
  18. client = Net::HTTP.new(uri.host, uri.port)
  19. client.use_ssl = uri.scheme == 'https'
  20. login_request = Net::HTTP::Post.new(uri.request_uri+"/login.php")
  21. login_request.set_form_data({"username" => ENV["LINK_USER"], "password" => ENV["LINK_PASS"], "keeppass" => "yes", "query" => "", "submitted" => "Log+in"})
  22. cookie = client.request(login_request).response['set-cookie'].split('; ')[0]
  23. bookmark_request = Net::HTTP::Post.new(uri.request_uri+"/bookmarks.php/tubiabot", {
  24. 'Cookie' => cookie
  25. })
  26. bookmark_request.set_form_data({"title" => title,
  27. "address" => link,
  28. "status" => "0",
  29. "tags" => "",
  30. "description" => "",
  31. "submitted" => "Add+Bookmark"})
  32. client.request(bookmark_request)
  33. if title != link
  34. m.reply "Bookmark add \""+title+"\""
  35. end
  36. end
  37. def on_help(m)
  38. m.reply "usage: !b https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  39. m.reply "i link stanno su https://link.autistici.org/bookmarks.php/tubiabot"
  40. end
  41. end