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-2/miku/plugins/e621.lua
Andreas Bielawski 345e33dcb0 Portiere EINEN HAUFEN an Imageboard-Plugins, NSFW-Plugins, etc. Im Folgenden:
- boobs
- danbooru
- derpibooru(_nsfw)
- e621
- gifeye
- konachan(_nsfw)
- riko & yagyuu >> moe
- porndoge
- pornhub_gif
- pr0gramm
- random_pic(_nsfw)
- rule34
- sankakucomplex
- yandere
- z0r
2016-08-18 17:23:55 +02:00

40 lines
1.1 KiB
Lua

local e621 = {}
function e621:init(config)
e621.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('e621', true).table
e621.doc = [[*
]]..config.cmd_pat..[[e621* _<Tags>_: Sucht auf e621 mit diesen Tags]]
end
e621.command = 'e621 <Tags>'
function e621:get_e621(tag)
local BASE_URL = 'https://e621.net'
local url = BASE_URL..'/post/index.json?tags='..tag
local res, code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
if not data[1] then return nil end
local i = math.random(#data)
local link_image = data[i].file_url
return link_image
end
function e621:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then
utilities.send_reply(self, msg, e621.doc, true)
return
end
local url = e621:get_e621(input)
if not url then
utilities.send_reply(self, msg, config.errors.results)
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(url)
utilities.send_photo(self, msg.chat.id, file, url)
end
return e621