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/konachan_nsfw.lua
2016-06-22 13:59:06 +02:00

32 lines
801 B
Lua

do
local function get_kc2(tag)
local url = 'http://konachan.com/post.json?tags='..tag..''
local b,c = http.request(url)
if c ~= 200 then return nil end
local kc = json:decode(b)
-- truly randomize
math.randomseed(os.time())
-- random max json table size
local i = math.random(#kc)
local link_image = kc[i].file_url
return link_image
end
local function run(msg, matches)
local tag = matches[1]
local tag = string.gsub(tag, " ", '_' )
local receiver = get_receiver(msg)
local url = get_kc2(tag)
send_photo_from_url(receiver, url, send_title, {receiver, title})
return "Source: "..url
end
return {
description = "Sendet Bild von Konachan.com [NSFW]",
usage = {"#konansfw [Tags]","#kcn [Tags]"},
patterns = {"^#konansfw (.*)$","^#kcn (.*)$"},
run = run
}
end