From 5381f7b182474f6591e22ffe2c4f9f589b7c4945 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sun, 26 Apr 2015 13:27:51 +0200 Subject: [PATCH] new plugin e621 (does not work yet) --- .gitignore | 3 ++- plugins/e621.lua | 58 +++++++++++++++++++++++++++++++++++++++++ plugins/e621_mirror.lua | 23 ++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 plugins/e621.lua create mode 100644 plugins/e621_mirror.lua diff --git a/.gitignore b/.gitignore index f89d7ec..acb1acb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ plugins/test.lua plugins/twitch.lua plugins/create_sticker.lua plugins/derpibooru_nsfw.lua -plugins/derpibooru.lua \ No newline at end of file +plugins/derpibooru.lua +plugins/rss.lua \ No newline at end of file diff --git a/plugins/e621.lua b/plugins/e621.lua new file mode 100644 index 0000000..237f9e7 --- /dev/null +++ b/plugins/e621.lua @@ -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 + } \ No newline at end of file diff --git a/plugins/e621_mirror.lua b/plugins/e621_mirror.lua new file mode 100644 index 0000000..6ef468d --- /dev/null +++ b/plugins/e621_mirror.lua @@ -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 + } \ No newline at end of file