2016-08-18 17:23:55 +02:00
|
|
|
local sankakucomplex = {}
|
|
|
|
|
|
|
|
function sankakucomplex:init(config)
|
|
|
|
sankakucomplex.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sc', true):t('sankaku', true).table
|
|
|
|
sankakucomplex.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[sc* _<Tags>_: Sucht auf Sankaku mit diesen Tags]]
|
|
|
|
end
|
|
|
|
|
|
|
|
sankakucomplex.command = 'sc <Tags>'
|
|
|
|
|
|
|
|
function sankakucomplex:get_post(tag)
|
|
|
|
local user = cred_data.sankaku_username
|
|
|
|
local password = cred_data.sankaku_pw --Your SHA1 hashed password. (echo "choujin-steiner--YOUR-PASSWORD--" | sha1sum)
|
|
|
|
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)
|
|
|
|
if not complex[1] then return nil end
|
|
|
|
|
|
|
|
local i = math.random(#complex)
|
|
|
|
local link_image = 'https:'..complex[i].file_url
|
|
|
|
return link_image
|
|
|
|
end
|
|
|
|
|
|
|
|
function sankakucomplex:action(msg, config)
|
|
|
|
local input = utilities.input_from_msg(msg)
|
|
|
|
if not input then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, sankakucomplex.doc, true)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local tag = string.gsub(input, " ", '_' )
|
|
|
|
local tag = string.gsub(tag, ":", '%%3A' )
|
|
|
|
|
|
|
|
local url = sankakucomplex:get_post(tag)
|
|
|
|
if not url then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, config.errors.results)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_typing(msg.chat.id, 'upload_photo')
|
2016-08-18 17:23:55 +02:00
|
|
|
local file = download_to_file(url)
|
|
|
|
if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_document(msg.chat.id, file, nil, msg.message_id)
|
2016-08-18 17:23:55 +02:00
|
|
|
else
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
|
2016-08-18 17:23:55 +02:00
|
|
|
end
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, url)
|
2016-08-18 17:23:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return sankakucomplex
|