merge upstream
Colors on Non valids. Check msg.to.id and msg.from.id function load_from_file(file) vardump uses serpent tabs on scandir Failed on Free games (no price info) Google with unescaped URLs
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
function googlethat(query)
|
||||
local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
|
||||
local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=active&hl=de&"
|
||||
local parameters = "q=".. (URL.escape(query) or "")
|
||||
|
||||
-- Do the request
|
||||
local res, code = https.request(api..parameters)
|
||||
if code ~=200 then return nil end
|
||||
local data = json:decode(res)
|
||||
|
||||
local results={}
|
||||
for key,result in ipairs(data.responseData.results) do
|
||||
table.insert(results,{result.titleNoFormatting, result.url})
|
||||
table.insert(results, {
|
||||
result.titleNoFormatting,
|
||||
result.unescapedUrl or result.url
|
||||
})
|
||||
end
|
||||
return results
|
||||
end
|
||||
@@ -22,9 +26,8 @@ function stringlinks(results)
|
||||
end
|
||||
|
||||
function run(msg, matches)
|
||||
vardump(matches)
|
||||
local results = googlethat(matches[1])
|
||||
return stringlinks(results)
|
||||
local results = googlethat(matches[1])
|
||||
return stringlinks(results)
|
||||
end
|
||||
|
||||
return {
|
||||
|
@@ -1,12 +1,11 @@
|
||||
|
||||
-- See https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI
|
||||
|
||||
do
|
||||
|
||||
local BASE_URL = 'http://store.steampowered.com/api/appdetails/?appids='
|
||||
local BASE_URL = 'http://store.steampowered.com/api/appdetails/'
|
||||
local DESC_LENTH = 200
|
||||
|
||||
function unescape(str)
|
||||
local function unescape(str)
|
||||
str = string.gsub( str, '<', '<' )
|
||||
str = string.gsub( str, '>', '>' )
|
||||
str = string.gsub( str, '"', '"' )
|
||||
@@ -17,28 +16,40 @@ function unescape(str)
|
||||
return str
|
||||
end
|
||||
|
||||
function get_steam_data (appid)
|
||||
local url = BASE_URL..appid
|
||||
local function get_steam_data (appid)
|
||||
local url = BASE_URL
|
||||
url = url..'?appids='..appid
|
||||
url = url..'&cc=DE'
|
||||
local res,code = http.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
local data = json:decode(res)[appid].data
|
||||
return data
|
||||
end
|
||||
|
||||
local function price_info (data)
|
||||
local price = '' -- If no data is empty
|
||||
|
||||
function send_steam_data(data, receiver)
|
||||
local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...'
|
||||
local title = data.name
|
||||
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.."%)"
|
||||
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
|
||||
price = price..' (US)'
|
||||
end
|
||||
|
||||
local text = title..' '..price_display..'\n'..description
|
||||
return price
|
||||
end
|
||||
|
||||
|
||||
local function send_steam_data(data, receiver)
|
||||
local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...'
|
||||
local title = data.name
|
||||
local price = price_info(data.price_overview)
|
||||
|
||||
local text = title..' '..price..'\n'..description
|
||||
local image_url = data.header_image
|
||||
local cb_extra = {
|
||||
receiver = receiver,
|
||||
@@ -48,7 +59,7 @@ function send_steam_data(data, receiver)
|
||||
end
|
||||
|
||||
|
||||
function run(msg, matches)
|
||||
local function run(msg, matches)
|
||||
local appid = matches[1]
|
||||
local data = get_steam_data(appid)
|
||||
local receiver = get_receiver(msg)
|
||||
|
Reference in New Issue
Block a user