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/figuya.lua

38 lines
1.0 KiB
Lua
Raw Normal View History

2016-12-12 19:15:38 +01:00
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
2017-01-21 19:25:19 +01:00
if string.len(data.description) > 500 then
desc = string.sub(unescape(data.description:gsub("%b<>", "")), 1, 500)..'..'
else
desc = unescape(data.description)..'.'
end
2016-12-12 19:15:38 +01:00
local pic = data.thumbnail_url
local text = '<b>'..title..'</b>\n<i>'..desc..'</i>'..'<a href="'..pic..'">.</a>'
return text
2016-12-12 19:15:38 +01:00
end
function figuya:action(msg, config, matches)
local figu = matches[1]
local text = figuya:get_figuya(figu)
2016-12-12 19:15:38 +01:00
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')
2016-12-12 19:15:38 +01:00
end
return figuya