From 964170eb3e739448f5e5c9cf26b2a5e8032fa309 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Wed, 1 Jun 2016 20:45:23 +0200 Subject: [PATCH] =?UTF-8?q?Plugin=20f=C3=BCr=20Sankaku=20Complex=20(NSFW)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/bot.lua | 2 ++ plugins/sankakucomplex.lua | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 plugins/sankakucomplex.lua diff --git a/bot/bot.lua b/bot/bot.lua index c1a0468..9b7a9ab 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -229,6 +229,8 @@ function create_cred() owm_apikey = "", page2images_restkey = "", plex_token = "", + sankaku_username = "", + sankaku_pw = "", soundcloud_client_id = "", tumblr_api_key = "", tw_consumer_key = "", diff --git a/plugins/sankakucomplex.lua b/plugins/sankakucomplex.lua new file mode 100644 index 0000000..533b5a3 --- /dev/null +++ b/plugins/sankakucomplex.lua @@ -0,0 +1,41 @@ +do + +local user = cred_data.sankaku_username +local password = cred_data.sankaku_pw --Your SHA1 hashed password. (echo "choujin-steiner--YOUR-PASSWORD--" | sha1sum) + +local function get_complex(tag) + local BASE_URL = 'https://chan.sankakucomplex.com' + local url = BASE_URL..'/post/index.json?login='..user..'&password_hash='..password..'&tags='..tag + local b,c = https.request(url) + if c ~= 200 then return nil end + local complex = json:decode(b) + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#complex) + local link_image = 'https:'..complex[i].file_url + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '_' ) + local tag = string.gsub(tag, ":", '%%3A' ) + local receiver = get_receiver(msg) + local url = get_complex(tag) + if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then + send_document_from_url(receiver, url) + else + send_photo_from_url(receiver, url, send_title, {receiver, title}) + end + return "Source: "..url +end + +return { + description = "Sendet ein zufälliges Bild von Sankakucomplex.", + usage = {"/sankaku [Tags]","/sc [Tags]"}, + patterns = {"^/sankaku (.*)$","^/sc (.*)$"}, + run = run +} + +end