TextDynasty Posted January 28, 2019 Report Share Posted January 28, 2019 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 Quote Link to comment Share on other sites More sharing options...
SnaBe Posted January 28, 2019 Report Share Posted January 28, 2019 (edited) 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 January 28, 2019 by SnaBe Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 28, 2019 Report Share Posted January 28, 2019 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. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 28, 2019 Author Report Share Posted January 28, 2019 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 workinghttp://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=XXXXXXXXXXXXXXXXXXXXXX&steamid=76561198302774496&include_played_free_games=true Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 28, 2019 Report Share Posted January 28, 2019 =1, not =true. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 29, 2019 Author Report Share Posted January 29, 2019 (edited) =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 January 29, 2019 by TextDynasty Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 29, 2019 Author Report Share Posted January 29, 2019 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); } } } }); Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 29, 2019 Report Share Posted January 29, 2019 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.timecreated. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 30, 2019 Author Report Share Posted January 30, 2019 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.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? Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 30, 2019 Report Share Posted January 30, 2019 I'm sure there is. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 30, 2019 Author Report Share Posted January 30, 2019 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://steamcommunity.com/id/76561098044947296/). 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) Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 30, 2019 Report Share Posted January 30, 2019 https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key=xxx&steamid=76561098044947296&include_played_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). Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 30, 2019 Author Report Share Posted January 30, 2019 https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key=xxx&steamid=76561098044947296&include_played_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'); } }); } Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 30, 2019 Report Share Posted January 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 30, 2019 Author Report Share Posted January 30, 2019 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 Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 30, 2019 Report Share Posted January 30, 2019 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. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 30, 2019 Author Report Share Posted January 30, 2019 (edited) 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 January 31, 2019 by TextDynasty Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted January 31, 2019 Report Share Posted January 31, 2019 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. Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted January 31, 2019 Author Report Share Posted January 31, 2019 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; } Quote Link to comment Share on other sites More sharing options...
TextDynasty Posted February 1, 2019 Author Report Share Posted February 1, 2019 Is there any example of Promise? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.