Jump to content
McKay Development

Recommended Posts

Posted

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.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=XXXXXXXXXXXXXXXXXXXXXX&steamid=76561198302774496&include_played_free_games=true

Posted (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 by TextDynasty
Posted

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);
            }
        }
    }
});
Posted

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.

Posted

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?

Posted

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)
Posted

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');
    }
 });
}
Posted

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.

Posted (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 by TextDynasty
Posted

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;
}

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...