38 lines
1.0 KiB
Lua
38 lines
1.0 KiB
Lua
local figuya = {}
|
|
|
|
function figuya:init(config)
|
|
figuya.triggers = {'figuya.com/de/produkte/(.+)$'}
|
|
end
|
|
|
|
function figuya:get_figuya(figu)
|
|
local api_key = cred_data.iframely_api_key
|
|
local url = 'http://iframe.ly/api/oembed?url=https%3A%2F%2Ffiguya.com%2Fde%2Fprodukte%2F'..figu..'&api_key='..api_key
|
|
local b,c = https.request(url)
|
|
if c ~= 200 then return nil end
|
|
local data = json.decode(b)
|
|
|
|
local title = data.title
|
|
if string.len(data.description) > 500 then
|
|
desc = string.sub(unescape(data.description:gsub("%b<>", "")), 1, 500)..'..'
|
|
else
|
|
desc = unescape(data.description)..'.'
|
|
end
|
|
local pic = data.thumbnail_url
|
|
local text = '<b>'..title..'</b>\n<i>'..desc..'</i>'..'<a href="'..pic..'">.</a>'
|
|
|
|
return text
|
|
end
|
|
|
|
function figuya:action(msg, config, matches)
|
|
local figu = matches[1]
|
|
local text = figuya:get_figuya(figu)
|
|
if not text then
|
|
utilities.send_reply(msg, config.errors.results)
|
|
return
|
|
end
|
|
|
|
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
|
end
|
|
|
|
return figuya
|