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-2/miku/plugins/sankakucomplex.lua

52 lines
1.7 KiB
Lua
Raw Normal View History

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)
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)
return
end
2016-08-24 17:18:17 +02:00
utilities.send_typing(msg.chat.id, 'upload_photo')
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)
else
2016-08-24 17:18:17 +02:00
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, url)
end
return sankakucomplex