From accb3c9008ac5dd29643ac2388f4efb29ebe20dd Mon Sep 17 00:00:00 2001 From: encrypt Date: Tue, 10 May 2016 13:52:12 +0000 Subject: [PATCH] add bookmarks --- plugins/bookmarks.rb | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 plugins/bookmarks.rb diff --git a/plugins/bookmarks.rb b/plugins/bookmarks.rb new file mode 100644 index 0000000..3edae23 --- /dev/null +++ b/plugins/bookmarks.rb @@ -0,0 +1,45 @@ +require 'net/https' +require 'cgi' +require 'uri' + +class Bookmarks + include Cinch::Plugin + + match /b help$/, :method => :on_help + match /b (.*)$/ + + def execute(m, link) + unless link =~ URI.regexp + return + end + title = link + if open(link).read =~ /(.*?)<\/title>/ + title = CGI.unescapeHTML($1) + end + base_uri = "https://link.autistici.org/" + uri = URI.parse(base_uri) + client = Net::HTTP.new(uri.host, uri.port) + client.use_ssl = uri.scheme == 'https' + login_request = Net::HTTP::Post.new(uri.request_uri+"/login.php") + login_request.set_form_data({"username" => ENV["LINK_USER"], "password" => ENV["LINK_PASS"], "keeppass" => "yes", "query" => "", "submitted" => "Log+in"}) + cookie = client.request(login_request).response['set-cookie'].split('; ')[0] + bookmark_request = Net::HTTP::Post.new(uri.request_uri+"/bookmarks.php/tubiabot", { + 'Cookie' => cookie + }) + bookmark_request.set_form_data({"title" => title, + "address" => link, + "status" => "0", + "tags" => "", + "description" => "", + "submitted" => "Add+Bookmark"}) + client.request(bookmark_request) + if title != link + m.reply "Bookmark add \""+title+"\"" + end + end + + def on_help(m) + m.reply "usage: !b https://www.youtube.com/watch?v=dQw4w9WgXcQ" + m.reply "i link stanno su https://link.autistici.org/bookmarks.php/tubiabot" + end +end