From 4f288360e43704d8a04262e310aa1c53ebf6f29a Mon Sep 17 00:00:00 2001 From: Vincent Castellano Date: Fri, 10 Apr 2015 00:26:38 -0700 Subject: [PATCH 1/3] Add new plugin for printing Steam data for store URLs. --- plugins/steam.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 plugins/steam.lua diff --git a/plugins/steam.lua b/plugins/steam.lua new file mode 100644 index 0000000..682cfde --- /dev/null +++ b/plugins/steam.lua @@ -0,0 +1,63 @@ +-- See https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI + +do + +local BASE_URL = 'http://store.steampowered.com/api/appdetails/?appids=' +local DESC_LENTH = 200 + +function unescape(str) + 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 + +function get_steam_data (appid) + local url = BASE_URL..appid + local res,code = http.request(url) + if code ~= 200 then return nil end + local data = json:decode(res)[appid].data + return data +end + + +function send_steam_data(data, receiver) +-- local title = data.name + local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' + local title = data.name + local price = "$"..data.package_groups[1].subs[1].price_in_cents_with_discount/100 + local percent_savings = data.package_groups[1].subs[1].percent_savings_text + if percent_savings == "" then + percent_savings = "0%" + end + local text = title..' '..price..' ('..percent_savings..')\n'..description + local image_url = data.screenshots[1].path_full + local cb_extra = { + receiver = receiver, + url = image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) +end + + +function run(msg, matches) + local appid = matches[1] + local data = get_steam_data(appid) + local receiver = get_receiver(msg) + send_steam_data(data, receiver) +end + +return { + description = "Grabs Steam info for Steam links.", + usage = "", + patterns = { + "http://store.steampowered.com/app/([0-9]+)", + }, + run = run +} + +end From ba6fba21d0da08a9d7c2d7ab4ff06662bb1cb294 Mon Sep 17 00:00:00 2001 From: Vincent Castellano Date: Fri, 10 Apr 2015 09:37:47 -0700 Subject: [PATCH 2/3] Improve the pricing display --- plugins/steam.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/steam.lua b/plugins/steam.lua index 682cfde..954e209 100644 --- a/plugins/steam.lua +++ b/plugins/steam.lua @@ -29,12 +29,16 @@ function send_steam_data(data, receiver) -- local title = data.name local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' local title = data.name - local price = "$"..data.package_groups[1].subs[1].price_in_cents_with_discount/100 - local percent_savings = data.package_groups[1].subs[1].percent_savings_text - if percent_savings == "" then - percent_savings = "0%" + local price = "$"..(data.price_overview.initial/100) + local sale_price = "$"..(data.price_overview.final/100) + local percent_savings = data.price_overview.discount_percent + local price_display = price + + if percent_savings ~= 0 then + price_display = price.." -> "..sale_price.." ("..percent_savings.."%)" end - local text = title..' '..price..' ('..percent_savings..')\n'..description + + local text = title..' '..price_display..'\n'..description local image_url = data.screenshots[1].path_full local cb_extra = { receiver = receiver, From ff42a0f32c8d708c10e77b791c6600b71ab5998a Mon Sep 17 00:00:00 2001 From: Vincent Castellano Date: Fri, 10 Apr 2015 12:59:36 -0700 Subject: [PATCH 3/3] Adding readme information for steam plugin --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index bfe550f..cf8f1f6 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,14 @@ Bot Commands !stats: Returns a list of Username [telegram_id]: msg_num + + + steam.lua + + + Displays preview of store infomration/pricing/screenshot. + + time.lua