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/plugins/bitly.lua
2015-11-12 17:42:03 +01:00

34 lines
938 B
Lua

-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
-- DO NOT USE WITHOUT PERMISSION
do
local BASE_URL = 'https://api-ssl.bitly.com/v3/expand'
local function expand_bitly_link (shorturl)
local access_token = cred_data.bitly_access_token
local url = BASE_URL..'?access_token='..access_token..'&shortUrl=https://bit.ly/'..shorturl
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json:decode(res).data
return data.expand[1].long_url
end
local function run(msg, matches)
local shorturl = matches[1]
return expand_bitly_link(shorturl)
end
return {
description = "Verlängert Bitly-Links",
usage = "Verlängert bit.ly, bitly.com, j.mp und andib.tk Links",
patterns = {
"bit.ly/([A-Za-z0-9-_-]+)",
"bitly.com/([A-Za-z0-9-_-]+)",
"j.mp/([A-Za-z0-9-_-]+)",
"andib.tk/([A-Za-z0-9-_-]+)"
},
run = run
}
end