Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Steam API
- -- Version 1.0
- -- By JPiolho
- -- Feel free to copy and edit as long you credit the original author
- local function trim (s)
- return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
- end
- local function IsPrivate(html)
- local s,e = string.find(html,"<p class=\"errorPrivate\">")
- if s == nil or e == nil then return false end
- return true
- end
- function getGameList(userid)
- if http == nil then return nil end
- local tbl = {}
- local html = http.get("http://steamcommunity.com/" .. userid .. "/games?tab=all")
- if html == nil then return nil end
- html = html:readAll()
- if IsPrivate(html) then return nil end
- local s = 0
- local e = 0
- while true do
- s,e = string.find(html,"<div class=\"gameListRowItem\"",e+1)
- if s == nil or e == nil then break end
- local s2,e2 = string.find(html,"<h4>",e)
- local s3,e3 = string.find(html,"</h4>",e2)
- local gamename = string.sub(html,e2+1,s3-1)
- local s4,e4 = string.find(html,"<h5>",e3)
- if s4 ~= nil and e4 ~= nil then
- local s5,e5 = string.find(html,"hrs on record</h5>",e4)
- if s5 ~= nil and e5 ~= nil then
- local hours = trim(string.sub(html,e4+1,s5-1))
- tbl[gamename] = tonumber(hours)
- end
- else
- tbl[gamename] = 0
- end
- end
- return tbl
- end
- function getStatus(userid)
- if http == nil then return nil end
- local tbl = {}
- local html = http.get("http://steamcommunity.com/" .. userid)
- if html == nil then return nil end
- html = html:readAll()
- if IsPrivate(html) then return nil end
- local s,e = string.find(html,"<div id=\"OnlineStatus\">")
- local s2,e2 = string.find(html,"<p id=\"statusOfflineText\">",e)
- if s2 ~= nil and e2 ~= nil then return "Offline" end
- s2,e2 = string.find(html,"<p id=\"statusOnlineHeader\">",e)
- if s2 ~= nil and e2 ~= nil then return "Online" end
- s2,e2 = string.find(html,"<p id=\"statusInGameText\">",e)
- if s2 ~= nil and e2 ~= nil then
- local s3,e3 = string.find(html,"<br />",e2)
- return trim(string.sub(html,e2+1,s3-1))
- end
- return nil
- end
- function userID(method,id)
- return method .. "/" .. id
- end
- function getFriends(userid)
- if http == nil then return nil end
- local tbl = {}
- local html = http.get("http://steamcommunity.com/" .. userid .. "/friends")
- if html == nil then return nil end
- html = html:readAll()
- if IsPrivate(html) then return nil end
- local s,e = string.find(html,"<div id=\"memberList\">")
- if s == nil or e == nil then return nil end
- local tbl = {}
- local es,ee = string.find(html,"footer",e)
- local s = 0
- local e = 0
- while true do
- s,e = string.find(html,"<p>",e+1)
- if s == nil or s >= es or e >= ee then break end
- local s2,e2 = string.find(html,"</p>",e)
- local s3,e3 = string.find(html,"<a class=\"linkFriend_in-game\" href=\"http://steamcommunity.com/",e)
- if s3 == nil or s3 > s2 or e3 > s2 then s3,e3 = string.find(html,"<a class=\"linkFriend_online\" href=\"http://steamcommunity.com/",e) end
- if s3 == nil or s3 > s2 or e3 > s2 then s3,e3 = string.find(html,"<a class=\"linkFriend_offline\" href=\"http://steamcommunity.com/",e) end
- if s3 ~= nil and s3 < s2 and e3 < s2 then
- local s4,e4 = string.find(html,"\">",e3)
- local userid = string.sub(html,e3+1,s4-1)
- local s5,e5 = string.find(html,"</a>",e4)
- local username = string.sub(html,e4+1,s5-1)
- tbl[userid] = username
- end
- end
- return tbl
- end
- function isGoldenPotato(userid)
- if http == nil then return nil end
- local tbl = {}
- local html = http.get("http://steamcommunity.com/" .. userid)
- if html == nil then return nil end
- html = html:readAll()
- if IsPrivate(html) then return nil end
- local s,e = string.find(html,"title=\"Golden Potato\">")
- if s == nil or e == nil then return false end
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment