Plugin für Sankaku Complex (NSFW)

This commit is contained in:
Akamaru 2016-06-01 20:45:23 +02:00
parent 9f3a41c316
commit 964170eb3e
2 changed files with 43 additions and 0 deletions

View File

@ -229,6 +229,8 @@ function create_cred()
owm_apikey = "", owm_apikey = "",
page2images_restkey = "", page2images_restkey = "",
plex_token = "", plex_token = "",
sankaku_username = "",
sankaku_pw = "",
soundcloud_client_id = "", soundcloud_client_id = "",
tumblr_api_key = "", tumblr_api_key = "",
tw_consumer_key = "", tw_consumer_key = "",

View File

@ -0,0 +1,41 @@
do
local user = cred_data.sankaku_username
local password = cred_data.sankaku_pw --Your SHA1 hashed password. (echo "choujin-steiner--YOUR-PASSWORD--" | sha1sum)
local function get_complex(tag)
local BASE_URL = 'https://chan.sankakucomplex.com'
local url = BASE_URL..'/post/index.json?login='..user..'&password_hash='..password..'&tags='..tag
local b,c = https.request(url)
if c ~= 200 then return nil end
local complex = json:decode(b)
-- truly randomize
math.randomseed(os.time())
-- random max json table size
local i = math.random(#complex)
local link_image = 'https:'..complex[i].file_url
return link_image
end
local function run(msg, matches)
local tag = matches[1]
local tag = string.gsub(tag, " ", '_' )
local tag = string.gsub(tag, ":", '%%3A' )
local receiver = get_receiver(msg)
local url = get_complex(tag)
if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then
send_document_from_url(receiver, url)
else
send_photo_from_url(receiver, url, send_title, {receiver, title})
end
return "Source: "..url
end
return {
description = "Sendet ein zufälliges Bild von Sankakucomplex.",
usage = {"/sankaku [Tags]","/sc [Tags]"},
patterns = {"^/sankaku (.*)$","^/sc (.*)$"},
run = run
}
end