2015-04-10 09:26:38 +02:00
|
|
|
-- See https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI
|
|
|
|
|
|
|
|
do
|
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local BASE_URL = 'http://store.steampowered.com/api/appdetails/'
|
2015-05-07 19:49:26 +02:00
|
|
|
local DESC_LENTH = 400
|
2015-04-10 09:26:38 +02:00
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local function unescape(str)
|
2015-04-10 09:26:38 +02:00
|
|
|
str = string.gsub( str, '<', '<' )
|
|
|
|
str = string.gsub( str, '>', '>' )
|
|
|
|
str = string.gsub( str, '"', '"' )
|
|
|
|
str = string.gsub( str, ''', "'" )
|
|
|
|
str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
|
|
|
|
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
|
|
|
|
str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others
|
|
|
|
return str
|
|
|
|
end
|
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local function get_steam_data (appid)
|
|
|
|
local url = BASE_URL
|
|
|
|
url = url..'?appids='..appid
|
2015-05-07 19:49:26 +02:00
|
|
|
url = url..'&l=german&cc=DE'
|
2015-04-10 09:26:38 +02:00
|
|
|
local res,code = http.request(url)
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
local data = json:decode(res)[appid].data
|
|
|
|
return data
|
|
|
|
end
|
|
|
|
|
2015-05-07 19:49:26 +02:00
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local function price_info (data)
|
|
|
|
local price = '' -- If no data is empty
|
2015-05-07 19:49:26 +02:00
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
if data then
|
|
|
|
local initial = data.initial
|
|
|
|
local final = data.final or data.initial
|
|
|
|
local min = math.min(data.initial, data.final)
|
|
|
|
price = tostring(min/100)
|
|
|
|
if data.discount_percent and initial ~= final then
|
|
|
|
price = price..data.currency..' ('..data.discount_percent..'% OFF)'
|
|
|
|
end
|
2015-05-07 19:49:26 +02:00
|
|
|
price = price..' €'
|
2015-04-26 19:16:44 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return price
|
|
|
|
end
|
|
|
|
|
2015-04-10 09:26:38 +02:00
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local function send_steam_data(data, receiver)
|
2015-04-10 09:26:38 +02:00
|
|
|
local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...'
|
|
|
|
local title = data.name
|
2015-04-26 19:16:44 +02:00
|
|
|
local price = price_info(data.price_overview)
|
2015-04-10 18:37:47 +02:00
|
|
|
|
2015-05-07 19:49:26 +02:00
|
|
|
local text = title..'\nPreis: '..price..'\n'..description
|
2015-04-11 01:12:19 +02:00
|
|
|
local image_url = data.header_image
|
2015-04-10 09:26:38 +02:00
|
|
|
local cb_extra = {
|
|
|
|
receiver = receiver,
|
|
|
|
url = image_url
|
|
|
|
}
|
|
|
|
send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-04-26 19:16:44 +02:00
|
|
|
local function run(msg, matches)
|
2015-04-10 09:26:38 +02:00
|
|
|
local appid = matches[1]
|
|
|
|
local data = get_steam_data(appid)
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
send_steam_data(data, receiver)
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-05-07 19:49:26 +02:00
|
|
|
description = "Steam-Info",
|
2015-05-12 20:15:15 +02:00
|
|
|
usage = {"store.steampowered.com/app Link","steamcommunity.com/app Link"},
|
2015-05-22 17:01:33 +02:00
|
|
|
patterns = {"store.steampowered.com/app/([0-9]+)","steamcommunity.com/app/([0-9]+)"},
|
2015-04-10 09:26:38 +02:00
|
|
|
run = run
|
|
|
|
}
|
|
|
|
|
2015-05-07 19:49:26 +02:00
|
|
|
end
|