2016-08-24 22:17:56 +02:00
|
|
|
|
local playstation_store = {}
|
|
|
|
|
|
|
|
|
|
playstation_store.triggers = {
|
|
|
|
|
'store.playstation.com/#!/([A-Za-z]+)%-([A-Za-z]+)/.*/cid=(.+)',
|
2017-11-09 14:45:15 +01:00
|
|
|
|
'store.playstation.com/([A-Za-z]+)%-([A-Za-z]+)/product/(.+)',
|
2016-08-24 22:17:56 +02:00
|
|
|
|
'store.sonyentertainmentnetwork.com/#!/([A-Za-z]+)%-([A-Za-z]+)/.*/cid=(.+)'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local makeOurDate = function(dateString)
|
|
|
|
|
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
|
|
|
|
local year, month, day = dateString:match(pattern)
|
|
|
|
|
return day..'.'..month..'.'..year
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function playstation_store:get_info(country_code, game_id)
|
|
|
|
|
local url = 'https://store.playstation.com/store/api/chihiro/00_09_000/container/'..country_code..'/999/'..game_id
|
|
|
|
|
local res, code = https.request(url)
|
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
|
local data = json.decode(res)
|
|
|
|
|
if not data then return nil end
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local title = '<b>'..data.name..'</b>'
|
2016-08-24 22:17:56 +02:00
|
|
|
|
if data.provider_name then
|
2017-11-09 14:45:15 +01:00
|
|
|
|
publish = ' von <b>'..data.provider_name..'</b>'
|
2016-08-24 22:17:56 +02:00
|
|
|
|
else
|
|
|
|
|
publish = ''
|
|
|
|
|
end
|
2016-09-05 19:18:01 +02:00
|
|
|
|
if data.playable_platform then
|
2017-11-09 14:45:15 +01:00
|
|
|
|
system = ' für <b>'..data.playable_platform[1]..'</b>'
|
2016-09-05 19:18:01 +02:00
|
|
|
|
else
|
|
|
|
|
system = ''
|
|
|
|
|
end
|
|
|
|
|
if data.gameContentTypesList then
|
|
|
|
|
types = ' ['..data.gameContentTypesList[1].name..']'
|
|
|
|
|
else
|
|
|
|
|
types = ''
|
|
|
|
|
end
|
2017-05-10 13:35:21 +02:00
|
|
|
|
if data.skus then
|
2016-08-24 22:17:56 +02:00
|
|
|
|
if data.skus[1].rewards[1] then
|
|
|
|
|
|
|
|
|
|
--[[
|
|
|
|
|
if data.skus[1].rewards[1].isPlus ~= true then
|
|
|
|
|
psplus = ''
|
|
|
|
|
else
|
|
|
|
|
psplus = ' PS+ Exklusiv!'
|
|
|
|
|
end
|
|
|
|
|
]]
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
price = '\n<b>Preis:</b> '..data.skus[1].rewards[1].display_price..' statt '..data.default_sku.display_price..' (Spare '..data.skus[1].rewards[1].discount..'%)'--..psplus
|
2016-08-24 22:17:56 +02:00
|
|
|
|
else
|
2017-11-09 14:45:15 +01:00
|
|
|
|
price = '\n<b>Preis:</b> '..data.default_sku.display_price --..psplus
|
2016-08-24 22:17:56 +02:00
|
|
|
|
end
|
2017-05-10 13:35:21 +02:00
|
|
|
|
else
|
2017-11-09 14:45:15 +01:00
|
|
|
|
price = ''
|
2017-05-10 13:35:21 +02:00
|
|
|
|
end
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local fsk = '\n<b>Freigegeben ab:</b> '..data.age_limit
|
|
|
|
|
local description = '\n\n<i>'..string.sub(unescape(data.long_desc:gsub("%b<>", "")), 1, 300)..'...</i>'
|
|
|
|
|
local release = '\n<b>Release:</b> '..makeOurDate(data.release_date)
|
2016-08-24 22:17:56 +02:00
|
|
|
|
if data.images[4].type ~= 10 then
|
2017-11-09 14:45:15 +01:00
|
|
|
|
image_url = '<a href="'..data.images[4].url..'"> </a>'
|
2016-08-24 22:17:56 +02:00
|
|
|
|
else
|
2017-11-09 14:45:15 +01:00
|
|
|
|
image_url = '<a href="'..data.images[1].url..'"> </a>'
|
2016-08-24 22:17:56 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local text = title..publish..system..types..image_url..price..fsk..release..description
|
2016-08-24 22:17:56 +02:00
|
|
|
|
|
2017-11-09 14:45:15 +01:00
|
|
|
|
return text
|
2016-08-24 22:17:56 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function playstation_store:action(msg, config, matches)
|
|
|
|
|
local country_code = string.upper(matches[2])..'/'..matches[1]
|
|
|
|
|
local game_id = matches[3]
|
2017-11-09 14:45:15 +01:00
|
|
|
|
local text = playstation_store:get_info(country_code, game_id)
|
2016-08-24 22:17:56 +02:00
|
|
|
|
if not text then
|
2017-11-09 14:45:15 +01:00
|
|
|
|
utilities.send_reply(msg, config.errors.results)
|
2016-08-24 22:17:56 +02:00
|
|
|
|
return
|
|
|
|
|
end
|
2017-11-09 14:45:15 +01:00
|
|
|
|
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
2016-08-24 22:17:56 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return playstation_store
|