From 39b35fcf1dbfcc8074f15c7e509cd81368dba38c Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Wed, 17 Aug 2016 18:29:52 +0200 Subject: [PATCH] justkitten & openingsmoe portiert --- miku/plugins/justkitten.lua | 26 ++++++++++++++++++++++++++ miku/plugins/openingsmoe.lua | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 miku/plugins/justkitten.lua create mode 100644 miku/plugins/openingsmoe.lua diff --git a/miku/plugins/justkitten.lua b/miku/plugins/justkitten.lua new file mode 100644 index 0000000..4c4a3f4 --- /dev/null +++ b/miku/plugins/justkitten.lua @@ -0,0 +1,26 @@ +local jk = {} + +function jk:init(config) + jk.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('jk', true).table + jk.doc = '\n*/jk*' +end + +jk.command = 'jk' + +function jk:action(msg, config) + local JK_URL = 'https://anditest.perseus.uberspace.de/plugins/jk' + local jk_pics = { + "/justkitten1.jpg", + "/justkitten2.jpg", + "/justkitten3.jpg", + "/justkitten4.jpg", + "/justkitten5.jpg", + "/justkitten6.jpg" + } + local random_pic = math.random(#jk_pics) + utilities.send_typing(self, msg.chat.id, 'upload_photo') + local file = download_to_file(JK_URL..jk_pics[random_pic]) + utilities.send_photo(self, msg.chat.id, file) +end + +return jk \ No newline at end of file diff --git a/miku/plugins/openingsmoe.lua b/miku/plugins/openingsmoe.lua new file mode 100644 index 0000000..b6c97ad --- /dev/null +++ b/miku/plugins/openingsmoe.lua @@ -0,0 +1,35 @@ +local openingsmoe = {} + +openingsmoe.triggers = { + "openings.moe/%?video=(.*).webm" +} + +function openingsmoe:get_opening(opening) + local url = 'http://openings.moe/api/details.php?file='..opening..'.webm' + local res,code = http.request(url) + local data = json.decode(res) + if code ~= 200 then return nil end + if not data.success then return nil end + + local number = data.title + local title = data.source + local song_title = data.song.title + local song_artist = data.song.artist + local url = 'http://openings.moe/video/'..data.filename + + local text = ''..number..' aus '..title..'\nSong: '..song_title..' von '..song_artist..'\nDirektlink' + + return text +end + +function openingsmoe:action(msg, config, matches) + local opening = matches[1] + local text = openingsmoe:get_opening(opening) + if not text then + utilities.send_reply(self, msg, config.errors.connection) + return + end + utilities.send_reply(self, msg, text, 'HTML') +end + +return openingsmoe \ No newline at end of file