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/rule34.lua

49 lines
1.7 KiB
Lua
Raw Normal View History

2015-11-18 17:08:15 +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_r34_info(tag)
2015-11-20 23:23:11 +01:00
local limit = 100 -- number of posts to return (higher = more choices for random, but longer load times, hard limit of 100 posts)
2015-11-18 17:08:15 +01:00
local BASE_URL = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Frule34.xxx%2Findex.php%3Fpage%3Ddapi%26s%3Dpost%26q%3Dindex%26limit%3D'..limit..'%26tags%3D'
local END_URL = '%27&format=json'
local url = BASE_URL..tag..END_URL
local res,code = https.request(url)
local r34 = json:decode(res).query.results.posts.post
if code ~= 200 then return "HTTP-Fehler" end
-- truly randomize
math.randomseed(os.time())
-- random max json table size
local i = math.random(#r34)
local url = r34[i].file_url
local source_url = 'Source: http://rule34.xxx/index.php?page=post&s=view&id='..r34[i].id
return url, source_url
end
local function run(msg, matches)
local tag = matches[1]
local tag = string.gsub(tag, " ", '_')
local tag = string.gsub(tag, ":", '%%3A')
2015-11-26 18:11:26 +01:00
local tag = string.gsub(tag, "+", '%%2B')
2015-11-18 17:08:15 +01:00
local receiver = get_receiver(msg)
local url, id = get_r34_info(tag)
local cb_extra = {
receiver=receiver,
url=url
}
2015-11-22 23:10:13 +01:00
if string.ends(url, ".gif") then
2015-11-26 15:19:21 +01:00
send_msg(receiver, id, send_document_from_url_callback, cb_extra)
2015-11-22 23:10:13 +01:00
else
send_msg(receiver, id, send_photo_from_url_callback, cb_extra)
end
2015-11-18 17:08:15 +01:00
end
return {
description = "Sendet zuf<75>lliges Bild von rule34.xxx",
usage = "#r34 [Tag]: Sendet zuf<75>lliges Bild von rule34.xxx",
patterns = {"^#r34 (.*)"},
2015-11-18 17:08:15 +01:00
run = run
}
end