Jump to content
McKay Development

Recommended Posts

Posted

why vac_friends list is empty when I print at last ?
 

function checkVacID(){
    friend_list = friends;
    vac_friends = []
    friend_list.forEach(function(key, index){ 
        
        axios.get(`https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=&steamids=${key}`)

        .then(function (response) {
            vac_response = response.data;
            if(vac_response.players[0]['VACBanned'] == true){
               vac_friends.push(vac_response.players[0])
               console.log(vac_friends)
            }
          })
          .catch(function (error) {
            console.log(error);
          })
    });

    console.log(vac_friends)
}

 

Posted

Because you're mixing up async and sync. forEach returns before your requests complete.

Also, rather than looping through the friend list, you should split it into chunks of 100 and make one request per chunk, to avoid getting rate limited by the API.

  • 2 weeks later...
Posted
On 1/16/2022 at 4:05 AM, Dr. McKay said:

Because you're mixing up async and sync. forEach returns before your requests complete.

Also, rather than looping through the friend list, you should split it into chunks of 100 and make one request per chunk, to avoid getting rate limited by the API.

can you give an example of 100 steamids passing in api

like i have 256 friends

  • 2 weeks later...
Posted
let friendsList = [array of steamids];

let chunks = [];
for (let i = 0; i < friendsList.length; i += 100) {
	chunks.push(friendsList.slice(i, i + 100));
}

let chunkResults = await Promise.all(chunks.map(ck => new Promise((resolve, reject) => {
	try {
		let result = await axios.get(`https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=&steamids=${ck.join(',')}`);
		if (result && result.data && result.data.players) {
			return resolve(result.data.players);
		}
		
		reject(new Error('Malformed API response'));
	} catch (ex) {
		reject(ex);
	}
})));

let vacFriends = [];
chunkResults.forEach((chunkPlayers) => {
	chunkPlayers.filter(player => player.VACBanned).forEach((bannedPlayer) => {
		vacFriends.push(bannedPlayer);
	});
});

Untested and might have bugs

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...