d9a6836dd5
- Ergänze Antworten da, wo ich es vergessen habe...
41 lines
1.2 KiB
Lua
41 lines
1.2 KiB
Lua
local konachan_nsfw = {}
|
|
|
|
function konachan_nsfw:init(config)
|
|
konachan_nsfw.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('kcn', true):t('konachan_nsfw', true).table
|
|
konachan_nsfw.doc = [[*
|
|
]]..config.cmd_pat..[[kcn* _<Tags>_: Sucht auf Konachan mit diesen Tags (NSFW)]]
|
|
end
|
|
|
|
konachan_nsfw.command = 'kcn <Tags>'
|
|
|
|
function konachan_nsfw:get_kc(tag)
|
|
local url = 'http://konachan.net/post.json?tags='..tag
|
|
local res, code = http.request(url)
|
|
if code ~= 200 then return nil end
|
|
local data = json.decode(res)
|
|
if not data[1] then return nil end
|
|
|
|
local i = math.random(#data)
|
|
local link_image = data[i].file_url
|
|
return link_image
|
|
end
|
|
|
|
function konachan_nsfw:action(msg, config)
|
|
local input = utilities.input_from_msg(msg)
|
|
if not input then
|
|
utilities.send_reply(self, msg, konachan_nsfw.doc, true)
|
|
return
|
|
end
|
|
local tag = string.gsub(input, " ", '+' )
|
|
local url = konachan_nsfw:get_kc(tag)
|
|
if not url then
|
|
utilities.send_reply(self, msg, config.errors.results)
|
|
return
|
|
end
|
|
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
|
local file = download_to_file(url)
|
|
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
|
|
utilities.send_reply(self, msg, url)
|
|
end
|
|
|
|
return konachan_nsfw |