So I planned to write a script for the bot to have a background check. Is there a way using steam-user to find out specific user game time? (say like TF2). If so, what is the method? Thanks

Need some help about checking game time
#1
Posted 28 January 2019 - 12:01 AM
#2
Posted 28 January 2019 - 09:21 AM
I believe you can edit your own profile settings when it comes to play time, but I'm not sure there's a method that returns the play time for a specific game in any of McKay's modules.
You could however try to use the Steam Web API.
Edited by SnaBe, 28 January 2019 - 09:33 AM.
#3
Posted 28 January 2019 - 01:23 PM
SnaBe is right, you'll want to use the WebAPI. There's no way to get a player's game time from a CM (via node-steam-user), and scraping the web is futile if there's just an API for it.
#4
Posted 28 January 2019 - 06:43 PM
SnaBe is right, you'll want to use the WebAPI. There's no way to get a player's game time from a CM (via node-steam-user), and scraping the web is futile if there's just an API for it.
I believe you can edit your own profile settings when it comes to play time, but I'm not sure there's a method that returns the play time for a specific game in any of McKay's modules.
You could however try to use the Steam Web API.
I found something like this on the site GetOwnedGames (v0001)
Arguments //steamid //The SteamID of the account. //include_appinfo //Include game name and logo information in the output. The default is to return appids only. include_played_free_games By default, free games like Team Fortress 2 are excluded (as technically everyone owns them). If include_played_free_games is set, they will be returned if the player has played them at some point. This is the same behavior as the games list on the Steam Community. format //Output format. json (default), xml or vdf. //appids_filter //You can optionally filter the list to a set of appids. Note that these cannot be passed as a URL parameter, instead you must use the JSON format described in Steam_Web_API#Calling_Service_interfaces. The expected input is an array of integers (in JSON: "appids_filter: [ 440, 500, 550 ]" )
So I tried with steam api key on but I cannot see TF2 in the json. I guess it is because of the "include_played_free_games", but I don't know why isn't it working
http://api.steampowe...free_games=true
#5
Posted 28 January 2019 - 06:51 PM
=1, not =true.
#6
Posted 28 January 2019 - 09:10 PM
=1, not =true.
Thanks. I modified the code a little bit but still cannot get it working. Here is my code currently right now
var steamapi = ''; var steamid = ''; request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+steamapi+'&include_played_free_games=1&steamid='+steamid, function (error, response, body) { if(error){ console.log(error); }else { var obj = JSON.parse(body); var games = obj.response.games; console.log(games); for (var i = 0; i < games.length; i++) { if(games[i].appid === "440"){ console.log("HI"); }else{ console.log('NO'); //Here I got many NO. I assume it is where the problem starts } } } });
Edit: Fixed. This code is working now
request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+steamapi+'&include_played_free_games=1&steamid='+steamid, function (error, response, body) { if(error){ console.log(error); }else { var obj = JSON.parse(body); var games = obj.response.games; for (var i = 0; i < games.length; i++) { if(games[i].appid == "440"){ var hours = Math.trunc(games[i].playtime_forever/60); var minutes = games[i].playtime_forever % 60; console.log('User played TF2 for '+hours+' hours, '+minutes+' minutes.'); } } } });
Edited by TextDynasty, 28 January 2019 - 09:26 PM.
#7
Posted 28 January 2019 - 10:03 PM
Another thing I would like to check is account creation time. I code a few lines and I would like to find out the current time - creation time to get an estimated time the account history. The problem is I don't know which format is it and how to get the number I wanted.
Using this code, I am able to find the user creation time.
//Check Steam Account Created Time request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+steamapi+'&steamids='+id, function (error, response, body) { if(error){ console.log(error); //show errors }else { var obj = JSON.parse(body); var player = obj.response.players; for (var i = 0; i < player.length; i++) { if(player[i].steamid === id){ time = player[i].timecreated console.log(time); var d = new Date(0); // The 0 there is the key, which sets the date to the epoch d.setUTCSeconds(time); console.log(d); } } } });
#8
Posted 29 January 2019 - 01:36 AM
timecreated is Unix time, which is the number of seconds that have elapsed since January 1, 1970 00:00:00 (UTC). In JavaScript, Date.now()
gives you the current Unix time in milliseconds, so to get the current Unix time in seconds, you'll do Math.floor(Date.now() / 1000)
. So to get the seconds since the account was created, you'd do Math.floor(Date.now() / 1000) - player[i].timecreated
.
#9
Posted 29 January 2019 - 07:21 PM
timecreated is Unix time, which is the number of seconds that have elapsed since January 1, 1970 00:00:00 (UTC). In JavaScript,
Date.now()
gives you the current Unix time in milliseconds, so to get the current Unix time in seconds, you'll doMath.floor(Date.now() / 1000)
. So to get the seconds since the account was created, you'd doMath.floor(Date.now() / 1000) - player[i].timecreated
.
Thanks that solved it. However, I faced another problem. My code right now will show errors when checking private backpack or profile, is there a way to prevent these errors and check these as well?
#10
Posted 29 January 2019 - 10:53 PM
I'm sure there is.
#11
Posted 29 January 2019 - 11:40 PM
I'm sure there is.
const request = require('request'); const SteamUser = require('steam-user'); const SteamTotp = require('steam-totp'); const TradeOfferManager = require('steam-tradeoffer-manager'); const SteamCommunity = require('steamcommunity'); const config = require('./config'); const client = new SteamUser(); const community = new SteamCommunity(); const manager = new TradeOfferManager({ "steam": client, // Polling every 30 seconds is fine since we get notifications from Steam "domain": "example.com", // Our domain is example.com "language": "en" // We want English item descriptions }); var id = '76561098044947296'; var steamapi = ''; const logOnOptions = { accountName: config.accountName, password: config.password, twoFactorCode: SteamTotp.generateAuthCode(config.shared_secret) }; client.logOn(logOnOptions); client.on('loggedOn', () => { client.setPersona(1); console.log('LogOn'); //check id client.getSteamLevels([id], function(requests){ var level = requests[id]; console.log('Steam Level: '+level); }) }); //Check TF2 hours request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+steamapi+'&include_played_free_games=1&steamid='+id, function (error, response, body) { if(error){ console.log(error); //show errors }else { var obj = JSON.parse(body); if(isNaN(obj.response.games) || obj.response.games == null){ console.log('User has private game hour.'); return; }else{ var games = obj.response.games; for (var i = 0; i < games.length; i++) { if(games[i].appid == "440"){ var hours = Math.trunc(games[i].playtime_forever/60); var minutes = games[i].playtime_forever % 60; console.log('TF2 time: '+hours+' hours, '+minutes+' minutes.'); } } } } }); //Check Steam Account Created Time (In months) request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+steamapi+'&steamids='+id, function (error, response, body) { if(error){ console.log(error); //show errors }else{ var obj = JSON.parse(body); var player = obj.response.players; for (var i = 0; i < player.length; i++) { if(player[i].steamid === id){ time = player[i].timecreated let second = Math.floor(Date.now() / 1000) - player[i].timecreated; let day = second/86400; let month = (day/30).toFixed(); if (isNaN(month) || player == null){ console.log('User has private profile.') }else{ console.log('Account created '+month+' months ago.'); } } } } });
It works fine with many profiles except this one (https://steamcommuni...61098044947296/). There's an error said
undefined:1 <html> ^ SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at Request._callback (C:\Users\lokin\OneDrive\桌面\New folder\checker.js:44:24) at Request.self.callback (C:\Users\lokin\OneDrive\桌面\New folder\node_modules\request\request.js:185:22) at Request.emit (events.js:182:13) at Request.<anonymous> (C:\Users\lokin\OneDrive\桌面\New folder\node_modules\request\request.js:1161:10) at Request.emit (events.js:182:13) at IncomingMessage.<anonymous> (C:\Users\lokin\OneDrive\桌面\New folder\node_modules\request\request.js:1083:12) at Object.onceWrapper (events.js:273:13) at IncomingMessage.emit (events.js:187:15) at endReadableNT (_stream_readable.js:1094:12)
#12
Posted 29 January 2019 - 11:45 PM
https://api.steampow...ed_free_games=1
Something is making Steam choke on this profile, so Steam is returning a 500 response. You should either check the status code (response.statusCode == 200
), or wrap your JSON.parse call in a try/catch block (or ideally, both).
#13
Posted 30 January 2019 - 07:11 AM
https://api.steampow...ed_free_games=1
Something is making Steam choke on this profile, so Steam is returning a 500 response. You should either check the status code (
response.statusCode == 200
), or wrap your JSON.parse call in a try/catch block (or ideally, both).
I added the check status code and it works.
So here's my code right now and I am adding a scoring system for background checking, I don't understand why the scores won't add up tho.
const requestReview = (offer) => { var user = offer.partner.getSteamID64(); var score = 0 client.chatMessage(config.bossSteamID, "--------------------------------"); client.chatMessage(config.bossSteamID, "User "+user+" sent an offer above 14 keys in value. Requesting manual review..."); client.chatMessage(config.bossSteamID, "Offer ID"); client.chatMessage(config.bossSteamID, offer.id); client.chatMessage(config.bossSteamID, "--------------------------------"); client.getSteamLevels([user], function(requests){ var level = requests[user]; client.chatMessage(config.bossSteamID, 'Steam Level: '+level); if(level > 10){ score+=1; } console.log(score); }); checkProfile(offer, score); checkHours(offer, score); console.log(score); } function checkProfile(offer, score) { request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+config.steamapi+'&steamids='+offer.partner.getSteamID64(), function (error, response, body) { if(error){ console.log(error); //show errors }else if (response.statusCode == 200){ var obj = JSON.parse(body); var player = obj.response.players; for (var i = 0; i < player.length; i++) { if(player[i].steamid === offer.partner.getSteamID64()){ time = player[i].timecreated; let second = Math.floor(Date.now() / 1000) - player[i].timecreated; let day = second/86400; let month = (day/30).toFixed(); if (isNaN(month) || player == null){ client.chatMessage(config.bossSteamID, 'Cannot find player creation date on Steam.'); }else{ client.chatMessage(config.bossSteamID, 'Created: '+month+' months ago.'); if(month > 6){ score+=1; } } profile = player[i].communityvisibilitystate; if(profile == 1 || profile == 2){ client.chatMessage(config.bossSteamID, 'PRIVATE PROFILE. DO NOT TRADE.'); }else if(profile == 3){ client.chatMessage(config.bossSteamID, 'Profile: Public'); score+=1; } } } }else{ console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }); } function checkHours(offer, score) { request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+config.steamapi+'&include_played_free_games=1&steamid='+offer.partner.getSteamID64(), function (error, response, body) { if(error){ console.log(error); //show errors }else if (response.statusCode == 200){ var obj = JSON.parse(body); if(obj.response.games == null){ console.log('User has private game hour.'); return; }else { var games = obj.response.games; for (var i = 0; i < games.length; i++) { if(games[i].appid == "440"){ var hours = Math.trunc(games[i].playtime_forever/60); var minutes = games[i].playtime_forever % 60; client.chatMessage(config.bossSteamID, 'TF2 time: '+hours+' hours, '+minutes+' minutes.'); if(hours > 500){ score+=1 } } } } }else{ console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }); }
#14
Posted 30 January 2019 - 03:37 PM
When you pass a primitive (number, string, etc.) variable to a function like that, changing it inside the function only changes it inside the function. It doesn't change everywhere.
#15
Posted 30 January 2019 - 05:54 PM
May I know is there a way to make the variable global so each function can change that, instead of making a long function with everything in it? I think it would be better and cleaner this way
#16
Posted 30 January 2019 - 05:57 PM
With the way your code is currently set up, I would recommend doing it sequentially instead of in parallel. That is, when checkProfile finishes, call checkHours with that score. And when that finishes, do whatever you need to with the score.
#17
Posted 30 January 2019 - 06:32 PM
I still cannot get the scoring system working. I put the commands in sequent though.
const requestReview = (offer) => { var user = offer.partner.getSteamID64(); client.chatMessage(config.bossSteamID, "--------------------------------"); client.chatMessage(config.bossSteamID, "User " + user + " sent an offer above 14 keys in value. Requesting manual review..."); client.chatMessage(config.bossSteamID, "Offer ID"); client.chatMessage(config.bossSteamID, offer.id); client.chatMessage(config.bossSteamID, "--------------------------------"); backgroundCheck(offer, score); } function checkProfile(offer, score) { request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + config.steamapi + '&steamids=' + offer.partner.getSteamID64(), function(error, response, body) { if (error) { console.log(error); //show errors } else if (response.statusCode == 200) { var obj = JSON.parse(body); var player = obj.response.players; for (var i = 0; i < player.length; i++) { if (player[i].steamid === offer.partner.getSteamID64()) { time = player[i].timecreated; let second = Math.floor(Date.now() / 1000) - player[i].timecreated; let day = second / 86400; let month = (day / 30).toFixed(); if (isNaN(month) || player == null) { client.chatMessage(config.bossSteamID, 'Cannot find player creation date on Steam.'); } else { client.chatMessage(config.bossSteamID, 'Created: ' + month + ' months ago.'); if (month > 6) { score += 1; } } profile = player[i].communityvisibilitystate; if (profile == 1 || profile == 2) { client.chatMessage(config.bossSteamID, 'PRIVATE PROFILE. DO NOT TRADE.'); } else if (profile == 3) { client.chatMessage(config.bossSteamID, 'Profile: Public'); score += 1; } } } } else { console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }); } function checkHours(offer, score) { request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=' + config.steamapi + '&include_played_free_games=1&steamid=' + offer.partner.getSteamID64(), function(error, response, body) { if (error) { console.log(error); //show errors } else if (response.statusCode == 200) { var obj = JSON.parse(body); if (obj.response.games == null) { console.log('User has private game hour.'); return; } else { var games = obj.response.games; for (var i = 0; i < games.length; i++) { if (games[i].appid == "440") { var hours = Math.trunc(games[i].playtime_forever / 60); var minutes = games[i].playtime_forever % 60; client.chatMessage(config.bossSteamID, 'TF2 time: ' + hours + ' hours, ' + minutes + ' minutes.'); if (hours > 500) { score += 1 } } } } } else { console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }); } function checkLevel(offer, score) { var user = offer.partner.getSteamID64(); client.getSteamLevels([user], function(requests) { var level = requests[user]; client.chatMessage(config.bossSteamID, 'Steam Level: ' + level); if (level > 10) { score += 1; } }) } async function backgroundCheck(offer, score) { let score = 0; let score1 = await checkHours(offer, score); let score2 = await checkLevel(offer, score); let score3 = await checkProfile(offer, score); let score = score1 + score2 + score3; console.log(score); return score; }
Edited by TextDynasty, 30 January 2019 - 08:08 PM.
#18
Posted 30 January 2019 - 11:39 PM
You can't use await
like that. In order for it to do anything, you need to return a Promise in the functions you're awaiting, and resolve that Promise with your score once they're complete.
#19
Posted 31 January 2019 - 12:14 AM
I put the return promise to the function I am waiting but cannot resolve the issue
const requestReview = (offer) => { var user = offer.partner.getSteamID64(); var score = 0; client.chatMessage(config.bossSteamID, "--------------------------------"); client.chatMessage(config.bossSteamID, "User "+user+" sent an offer above 14 keys in value. Requesting manual review..."); client.chatMessage(config.bossSteamID, "Offer ID"); client.chatMessage(config.bossSteamID, offer.id); client.chatMessage(config.bossSteamID, "--------------------------------"); backgroundCheck(offer,score); } function checkProfile(offer, score) { return new Promise((resolve, reject) => { request('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+config.steamapi+'&steamids='+offer.partner.getSteamID64(), function (error, response, body) { if (response.statusCode == 200){ var obj = JSON.parse(body); var player = obj.response.players; for (var i = 0; i < player.length; i++) { if(player[i].steamid === offer.partner.getSteamID64()){ time = player[i].timecreated; let second = Math.floor(Date.now() / 1000) - player[i].timecreated; let day = second/86400; let month = (day/30).toFixed(); if (isNaN(month) || player == null){ client.chatMessage(config.bossSteamID, 'Cannot find player creation date on Steam.'); }else{ client.chatMessage(config.bossSteamID, 'Created: '+month+' months ago.'); if(month > 6){ score+=1; resolve(score); } } profile = player[i].communityvisibilitystate; if(profile == 1 || profile == 2){ client.chatMessage(config.bossSteamID, 'PRIVATE PROFILE. DO NOT TRADE.'); }else if(profile == 3){ client.chatMessage(config.bossSteamID, 'Profile: Public'); score+=1; resolve(score); } } } }else{ console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }) }); } function checkHours(offer, score) { return new Promise((resolve, reject)=>{ request('https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key='+config.steamapi+'&include_played_free_games=1&steamid='+offer.partner.getSteamID64(), function (error, response, body) { if(error){ console.log(error); //show errors }else if (response.statusCode == 200){ var obj = JSON.parse(body); if(obj.response.games == null){ console.log('User has private game hour.'); return; }else { var games = obj.response.games; for (var i = 0; i < games.length; i++) { if(games[i].appid == "440"){ var hours = Math.trunc(games[i].playtime_forever/60); var minutes = games[i].playtime_forever % 60; client.chatMessage(config.bossSteamID, 'TF2 time: '+hours+' hours, '+minutes+' minutes.'); if(hours > 500){ score+=1 resolve(score); } } } } }else{ console.log(response.statusCode); client.chatMessage(config.bossSteamID, 'Steam cannot load his profile. Require manual check'); } }); }) } function checkLevel(offer, score) { return new Promise((resolve, reject)=>{ var user = offer.partner.getSteamID64(); client.getSteamLevels([user], function(requests){ var level = requests[user]; client.chatMessage(config.bossSteamID, 'Steam Level: '+level); if(level > 10){ score+=1; resolve(score); } }); }); } async function backgroundCheck(score){ let score = 0; let score1 = checkHours.resolve(score); let score2 = checkLevel.resolve(score); let score3 = checkProfile.resolve(score); let score = score1+score2+score3; console.log(score); return score; }
#20
Posted 01 February 2019 - 09:18 AM
Is there any example of Promise?
Also tagged with one or more of these keywords: node.js, node-steam-user
node-steam-user
News & Announcements →
Releases & Updates →
v4.4.3Started by System , Yesterday, 09:01 PM |
|
![]()
|
||
![]() [v4] Access purchaseResultDetails on key redeeming errorStarted by Catzilla , Yesterday, 03:18 PM ![]() |
|
![]()
|
||
node-steam-user
News & Announcements →
Releases & Updates →
v4.4.2Started by System , 20 Feb 2019 |
|
![]()
|
||
node-steam-user
News & Announcements →
Releases & Updates →
v4.4.0Started by System , 19 Feb 2019 |
|
![]()
|
||
node-steam-user
News & Announcements →
Releases & Updates →
v4.4.1Started by System , 19 Feb 2019 |
|
![]()
|
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users