From 9f54bf22f94099ae2dc20aad852966c5b4f4e151 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Mon, 15 Aug 2016 23:39:27 +0200 Subject: [PATCH] =?UTF-8?q?-=20Plugin=20f=C3=BCr=20img.ponywave.de=20&=20i?= =?UTF-8?q?mg.akamaru.de=20(unterst=C3=BCtzt=20auch=20Inline)=20-=20/me=20?= =?UTF-8?q?Plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miku/plugins/cf_image_hosting.lua | 55 +++++++++++++++++++++++++++++++ miku/plugins/me.lua | 19 +++++++++++ 2 files changed, 74 insertions(+) create mode 100644 miku/plugins/cf_image_hosting.lua create mode 100644 miku/plugins/me.lua diff --git a/miku/plugins/cf_image_hosting.lua b/miku/plugins/cf_image_hosting.lua new file mode 100644 index 0000000..b6aedd6 --- /dev/null +++ b/miku/plugins/cf_image_hosting.lua @@ -0,0 +1,55 @@ +local cf_img = {} + +cf_img.triggers = { + '(https?://img.ponywave.de)/(.*).html', + '(https?://img.akamaru.de)/(.*).html' +} +cf_img.inline_triggers = cf_img.triggers + +function cf_img:get_full_url(site, pic) + local url = site..'/'..pic..'.html' + local doer = http + if url:match('^https') then + doer = https + end + local res, code = doer.request(url) + if code ~= 200 then return nil end + local full_url = string.match(res, "id=\"codedirect\" value%=\"(.-)\" onclick") + return full_url +end + +function cf_img:inline_callback(inline_query, config, matches) + local site = matches[1] + local pic = matches[2] + local full_url = cf_img:get_full_url(site, pic) + if not full_url then utilities.answer_inline_query(self, inline_query) return end + + local results + + if string.ends(full_url, '.gif') then + results = '[{"type":"gif","id":"7778","gif_url":"'..full_url..'","thumb_url":"'..full_url..'"}]' + else + results = '[{"type":"photo","id":"7777","photo_url":"'..full_url..'","thumb_url":"'..full_url..'"}]' + end + utilities.answer_inline_query(self, inline_query, results, 3600, true) +end + +function cf_img:action(msg, config, matches) + local site = matches[1] + local pic = matches[2] + local full_url = cf_img:get_full_url(site, pic) + if not full_url then + utilities.send_reply(self, msg, config.errors.connection) + return + end + + utilities.send_typing(self, msg.chat.id, 'upload_photo') + local file = download_to_file(full_url) + if string.ends(full_url, '.gif') then + utilities.send_document(self, msg.chat.id, file, nil, msg.message_id) + else + utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) + end +end + +return cf_img diff --git a/miku/plugins/me.lua b/miku/plugins/me.lua new file mode 100644 index 0000000..6f6885f --- /dev/null +++ b/miku/plugins/me.lua @@ -0,0 +1,19 @@ +local me = {} + +function me:init(config) + me.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('me', true).table + me.doc = '*/me* __' +end + +me.command = 'me' + +function me:action(msg, config) + local input = utilities.input_from_msg(msg) + if not input then + return + end + + utilities.send_message(self, msg.chat.id, msg.from.first_name..' '..input) +end + +return me