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

36 lines
1016 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_yan(tag)
local BASE_URL = 'https://yande.re'
local url = BASE_URL..'/post.json?tags='..tag
local b,c = https.request(url)
if c ~= 200 then return nil end
local yan = json:decode(b)
-- truly randomize
math.randomseed(os.time())
-- random max json table size
local i = math.random(#yan)
local link_image = yan[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_yan(tag)
send_photo_from_url(receiver, url, send_title, {receiver, title})
return "Source: "..url
end
return {
description = "Sendet zufälliges Bild von Yandere.",
usage = {"#yandere [Tags]","#yan [Tags]"},
patterns = {"^#yandere (.*)$","^#yan (.*)$"},
run = run
}
end