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/play_store.lua
2016-11-29 18:28:21 +01:00

59 lines
1.6 KiB
Lua

local play_store = {}
function play_store:init(config)
if not cred_data.x_mashape_key then
print('Fehlender Key: x_mashape_key.')
print('play_store.lua wird nicht aktiviert.')
return
end
play_store.triggers = {
"play.google.com/store/apps/details%?id=(.*)"
}
end
local BASE_URL = 'https://apps.p.mashape.com/google/application'
function play_store:get_playstore_data (appid)
local apikey = cred_data.x_mashape_key
local url = BASE_URL..'/'..appid..'?mashape-key='..apikey
local res,code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).data
return data
end
function play_store:send_playstore_data(data)
local title = data.title
local developer = data.developer.id
local category = data.category.name
local rating = data.rating.average
local installs = data.performance.installs
local description = unescape(data.description)
if data.version == "Varies with device" then
appversion = "variiert je nach Gerät"
else
appversion = data.version
end
if data.price == 0 then
price = "Gratis"
else
price = data.price
end
local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion
return text
end
function play_store:action(msg, config, matches)
local appid = matches[1]
local data = play_store:get_playstore_data(appid)
if data == nil then
return
else
utilities.send_reply(msg, play_store:send_playstore_data(data), true)
return
end
end
return play_store