2015-11-12 17:42:03 +01:00
|
|
|
|
-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
|
|
|
|
|
-- DO NOT USE WITHOUT PERMISSION
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
local function get_dp2(tag)
|
|
|
|
|
local BASE_URL = 'https://derpiboo.ru/'
|
|
|
|
|
local apikey = cred_data.derpibooru_apikey
|
|
|
|
|
|
|
|
|
|
-- Ohne API-Key: Safe for work - mit API-Key: Not safe for work
|
|
|
|
|
if apikey == nil then
|
|
|
|
|
url = BASE_URL..'/search.json?q='..tag
|
|
|
|
|
else
|
|
|
|
|
url = BASE_URL..'/search.json?key='..apikey..'&q='..tag
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local b,c = https.request(url)
|
|
|
|
|
if c ~= 200 then return nil end
|
|
|
|
|
local dp = json:decode(b).search
|
|
|
|
|
-- truly randomize
|
|
|
|
|
math.randomseed(os.time())
|
|
|
|
|
-- random max json table size
|
|
|
|
|
local i = math.random(#dp)
|
|
|
|
|
local link_image = 'https:'..dp[i].image
|
|
|
|
|
source = 'https://derpiboo.ru/'..dp[i].id_number
|
|
|
|
|
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_dp2(tag)
|
|
|
|
|
send_photo_from_url(receiver, url, send_title, {receiver, title})
|
|
|
|
|
return "Source: "..source
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
description = "Sendet zuf<75>lliges Bild von Derpibooru.",
|
2016-06-22 13:59:06 +02:00
|
|
|
|
usage = {"#derpibooru2 [Tags]","#dp2 [Tags]"},
|
|
|
|
|
patterns = {"^#derpibooru2 (.*)$","^#dp2 (.*)$"},
|
2015-11-12 17:42:03 +01:00
|
|
|
|
run = run
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end
|