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

81 lines
2.5 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local playstation_store = {}
playstation_store.triggers = {
'store.playstation.com/#!/([A-Za-z]+)%-([A-Za-z]+)/.*/cid=(.+)',
'store.playstation.com/([A-Za-z]+)%-([A-Za-z]+)/product/(.+)',
'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
local title = '<b>'..data.name..'</b>'
if data.provider_name then
publish = ' von <b>'..data.provider_name..'</b>'
else
publish = ''
end
if data.playable_platform then
system = ' für <b>'..data.playable_platform[1]..'</b>'
else
system = ''
end
if data.gameContentTypesList then
types = ' ['..data.gameContentTypesList[1].name..']'
else
types = ''
end
if data.skus then
if data.skus[1].rewards[1] then
--[[
if data.skus[1].rewards[1].isPlus ~= true then
psplus = ''
else
psplus = ' PS+ Exklusiv!'
end
]]
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
else
price = '\n<b>Preis:</b> '..data.default_sku.display_price --..psplus
end
else
price = ''
end
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)
if data.images[4].type ~= 10 then
image_url = '<a href="'..data.images[4].url..'"> </a>'
else
image_url = '<a href="'..data.images[1].url..'"> </a>'
end
local text = title..publish..system..types..image_url..price..fsk..release..description
return text
end
function playstation_store:action(msg, config, matches)
local country_code = string.upper(matches[2])..'/'..matches[1]
local game_id = matches[3]
local text = playstation_store:get_info(country_code, game_id)
if not text then
utilities.send_reply(msg, config.errors.results)
return
end
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
end
return playstation_store