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

32 lines
810 B
Lua

do
local function get_kc(tag)
local url = 'http://konachan.net/post.json?tags='..tag..' -rating:explicit'
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_kc(tag)
send_photo_from_url(receiver, url, send_title, {receiver, title})
return "Source: "..url
end
return {
description = "Sendet ein Bild von Konachan.net [SFW]",
usage = {"#konachan [Tags]","#kc"},
patterns = {"^#konachan (.*)$","^#kc (.*)$"},
run = run
}
end