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

36 lines
949 B
Lua

-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
-- DO NOT USE WITHOUT PERMISSION
-- Modified by Akamaru [https://ponywave.de]
do
local function get_e621(tag)
local BASE_URL = 'https://e621.net'
local url = BASE_URL..'/post/index.json?tags='..tag
local b,c = https.request(url)
if c ~= 200 then return nil end
local e621 = json:decode(b)
-- truly randomize
math.randomseed(os.time())
-- random max json table size
local i = math.random(#e621)
local link_image = e621[i].file_url
return link_image
end
local function run(msg, matches)
local tag = matches[1]
local receiver = get_receiver(msg)
local url = get_e621(tag)
send_photo_from_url(receiver, url, send_title, {receiver, title})
return "Source: "..url
end
return {
description = "Sendet zufälliges Bild von e621.",
usage = {"#e621 [Tags]"},
patterns = {"^#e621 (.*)$"},
run = run
}
end