new plugin e621 (does not work yet)

This commit is contained in:
Akamaru 2015-04-26 13:27:51 +02:00
parent e31c706579
commit 5381f7b182
3 changed files with 83 additions and 1 deletions

3
.gitignore vendored
View File

@ -23,4 +23,5 @@ plugins/test.lua
plugins/twitch.lua
plugins/create_sticker.lua
plugins/derpibooru_nsfw.lua
plugins/derpibooru.lua
plugins/derpibooru.lua
plugins/rss.lua

58
plugins/e621.lua Normal file
View File

@ -0,0 +1,58 @@
local https = require 'ssl.https'
function send_title(cb_extra, success, result)
send_msg(cb_extra[1], string.format('https://e621.net/post/show/%s\nScore: %s, rating: %s\n%s', cb_extra[2][1].id, cb_extra[2][1].score, cb_extra[2][1].rating, cb_extra[2][1].tags), ok_cb, false)
end
function filter_rating(msg)
local chan_rating = get_db_key('chan:' .. msg.to.id, 'e621')
if chan_rating == "explicit" then
return ''
elseif chan_rating == "mature" then
return '-rating:explicit'
else
return 'rating:safe'
end
end
function run(msg, matches)
local reciever = get_receiver(msg)
local request = ''
local extra = filter_rating(msg)
extra = extra .. ' -animation'
if matches[1] == 'latest' then
request = 'https://e621.net:443/post/index.json?limit=1&tags=' .. extra
elseif matches[1] == 'search' then
request = 'https://e621.net:443/post/index.json?tags=' .. matches[2] .. ' ' .. extra
else
return nil
end
body, code, headers, status = https.request(request)
local yiff = json:decode(body)
if yiff.success ~= nil and not yiff.success then
return yiff.reason
end
local link = yiff[1].sample_url
local file_path = download_to_file(link:gsub('https', 'http'))
print(file_path)
send_photo(reciever, file_path, send_title, { reciever, yiff })
return nil
end
return {
description = 'e621 commands [latest, search]',
usage = '/e621 search [term], /e621 latest',
patterns = {'^/e621 (latest)', '^/e621 (search) (.+) ?$'},
run = run
}

23
plugins/e621_mirror.lua Normal file
View File

@ -0,0 +1,23 @@
local https = require 'ssl.https'
function run(msg, matches)
local reciever = get_receiver(msg)
body, code, headers, status = https.request('https://e621.net:443/post/show.json?id=' .. matches[1])
local yiff = json:decode(body)
local link = yiff.sample_url
local file_path = download_to_file(link:gsub('https', 'http'))
send_photo(reciever, file_path, ok_cb, false)
return nil
end
return {
description = 'Mirrors e621 posts',
usage = 'e621.net/post/show/12345',
patterns = {'e621.net/post/show/([0-9]+)'},
run = run
}