This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/sankakucomplex.lua
2016-06-22 13:59:06 +02:00

42 lines
1.3 KiB
Lua

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