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

29 lines
904 B
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://www.googleapis.com/pagespeedonline/v2'
function get_pagespeed (test_url)
local apikey = cred_data.google_apikey
local url = BASE_URL..'/runPagespeed?url='..test_url..'&key='..apikey..'&fields=id,ruleGroups(SPEED(score))'
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json:decode(res)
return data.id..' hat einen PageSpeed-Score von '..data.ruleGroups.SPEED.score..' Punkten.'
end
function run(msg, matches)
local test_url = matches[1]
return get_pagespeed(test_url)
end
return {
description = "Sendet PageSpeed-Score.",
usage = "/speed [URL]: Sendet PageSpeed-Score dieser Seite",
patterns = {"^/speed (https?://[%w-_%.%?%.:/%+=&]+)"},
run = run
}
end