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_create.lua

44 lines
1.3 KiB
Lua
Raw Normal View History

2015-11-12 17:42:03 +01:00
-- 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/shorten'
local access_token = cred_data.bitly_access_token
function create_bitlink (long_url, domain)
local url = BASE_URL..'?access_token='..access_token..'&domain='..domain..'&longUrl='..long_url..'&format=txt'
local text,code = https.request(url)
if code ~= 200 then return 'FEHLER: '..text end
return text
end
function run(msg, matches)
if matches[2] == nil then
long_url = url_encode(matches[1])
domain = 'bit.ly'
else
long_url = url_encode(matches[2])
domain = matches[1]
end
return create_bitlink(long_url, domain)
end
return {
description = "K<EFBFBD>rzt einen Link",
usage = {
2016-07-07 21:34:32 +02:00
"#short [Link]: K<>rzt einen Link mit Bitly",
"#
short [j.mp|bit.ly|bitly.com|andib.tk] [Link]: K<EFBFBD>rzt einen Link mit der ausgew<EFBFBD>hlten Kurz-URL"
2015-11-12 17:42:03 +01:00
},
patterns = {
2016-07-07 21:34:32 +02:00
"^#[Ss][Hh][Oo][Rr][Tt] (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^#[Ss][Hh][Oo][Rr][Tt] (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^#[Ss][Hh][Oo][Rr][Tt] (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^#[Ss][Hh][Oo][Rr][Tt] (andib.tk) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^#[Ss][Hh][Oo][Rr][Tt] (https?://[%w-_%.%?%.:/%+=&]+)$"
2015-11-12 17:42:03 +01:00
},
run = run
}
end