justkitten & openingsmoe portiert

This commit is contained in:
Andreas Bielawski 2016-08-17 18:29:52 +02:00
parent 557405af2f
commit 39b35fcf1d
2 changed files with 61 additions and 0 deletions

View File

@ -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

View File

@ -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 = '<b>'..number..'</b> aus <b>'..title..'</b>\n<b>Song:</b> '..song_title..' von '..song_artist..'\n<a href="'..url..'">Direktlink</a>'
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