-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
53 lines (40 loc) · 1.9 KB
/
server.js
File metadata and controls
53 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const requestPromise = require('request-promise');
var request = require('request');
const { API_TOKEN, XIPH_STEAM_ID } = require('./config.json');
var friendListJSON_URL = `http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=${API_TOKEN}&steamid=${XIPH_STEAM_ID}&relationship=friend`;
var ownedGamesJSON_URL = `http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${API_TOKEN}&steamid=${XIPH_STEAM_ID}&include_played_free_games=true&format=json`;
getPlayerFriendID();
async function getPlayerFriendID() {
var friendList;
console.time('friendList2');
friendList = await JSON.parse(await getBody(friendListJSON_URL)).friendslist.friends;
console.timeEnd('friendList2');
//console.log(friendList);
var friendObjects = await getFriendObjectList(friendList); //THIS TAKES A WHILE
console.log("End");
}
async function getFriendObjectList(friendList) {
var playerSummariesJSON_URL = `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${API_TOKEN}&steamids=`;
var testURL = `https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${API_TOKEN}&steamid=`;
var arrayOfFriends = new Array();
console.time('friendList');
for (var num = 0; num < friendList.length; num++) {
//var friendObject = JSON.parse(await requestPromise(playerSummariesJSON_URL + friendList[num].steamid)).response.players[0];
var friendObject = await getBody(testURL + friendList[num].steamid);
arrayOfFriends.push(friendObject);
}
console.timeEnd('friendList');
return arrayOfFriends;
}
function getBody(URL) {
return new Promise((resolve, reject) => {
request.get(URL, (error, response, body) => {
if (error) {
reject(error);
} else {
resolve(body);
}
});
});
}
console.log('READY');