This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/dailymotion.lua

32 lines
885 B
Lua
Raw Normal View History

local dailymotion = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
dailymotion.triggers = {
"dailymotion.com/video/([A-Za-z0-9-_-]+)"
}
local BASE_URL = 'https://api.dailymotion.com'
function dailymotion:send_dailymotion_info (dm_code)
local url = BASE_URL..'/video/'..dm_code
local res,code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
local title = data.title
local channel = data.channel
local text = '*'..title..'*\nHochgeladen in die Kategorie *'..channel..'*'
return text
end
function dailymotion:action(msg, config, matches)
local text = dailymotion:send_dailymotion_info(matches[1])
if not text then utilities.send_reply(self, msg, config.errors.connection) return end
utilities.send_reply(self, msg, text, true)
end
return dailymotion