add bookmarks
This commit is contained in:
parent
612e3e22ed
commit
accb3c9008
1 changed files with 45 additions and 0 deletions
45
plugins/bookmarks.rb
Normal file
45
plugins/bookmarks.rb
Normal file
|
@ -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>/
|
||||||
|
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
|
Loading…
Reference in a new issue