From d54dd2c892fd60ba548950f810bf7c13538c69e7 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 4 Jun 2021 04:08:07 +0200 Subject: [PATCH] Added getFriendsList --- index.js | 32 ++++++++++++++++++++++++++++++++ resources/EFriendRelationship.js | 23 +++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 resources/EFriendRelationship.js diff --git a/index.js b/index.js index 05303e3..e060162 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ module.exports = SteamCommunity; SteamCommunity.SteamID = SteamID; SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js'); SteamCommunity.EResult = require('./resources/EResult.js'); +SteamCommunity.FriendRelationship = require('./resources/EFriendRelationship.js'); function SteamCommunity(options) { @@ -535,6 +536,37 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { } }; +/** + * Returns an object whose keys are 64-bit SteamIDs, and whose values are values from the EFriendRelationship enum. + * Therefore, you can deduce your friends or blocked list from this object. + * @param {function} callback + */ + SteamCommunity.prototype.getFriendsList = function(callback) { + this.httpRequestGet({ + "uri": "https://steamcommunity.com/textfilter/ajaxgetfriendslist", + "json": true + }, (err, res, body) => { + if (err) { + callback(err ? err : new Error('HTTP error ' + res.statusCode)); + return; + } + + if (body.success != 1) { + callback(Helpers.eresultError(body.success)); + return; + } + + if (!body.friendslist || !body.friendslist.friends) { + callback(new Error('Malformed response')); + return; + } + + const friends = {}; + body.friendslist.friends.forEach(friend => (friends[friend.ulfriendid] = friend.efriendrelationship)); + callback(null, friends); + }); +}; + require('./components/http.js'); require('./components/chat.js'); require('./components/profile.js'); diff --git a/resources/EFriendRelationship.js b/resources/EFriendRelationship.js new file mode 100644 index 0000000..ed9ef7a --- /dev/null +++ b/resources/EFriendRelationship.js @@ -0,0 +1,23 @@ +/** + * @enum EFriendRelationship + */ + module.exports = { + "None": 0, + "Blocked": 1, + "RequestRecipient": 2, + "Friend": 3, + "RequestInitiator": 4, + "Ignored": 5, + "IgnoredFriend": 6, + "SuggestedFriend": 7, // removed "was used by the original implementation of the facebook linking feature; but now unused." + + // Value-to-name mapping for convenience + "0": "None", + "1": "Blocked", + "2": "RequestRecipient", + "3": "Friend", + "4": "RequestInitiator", + "5": "Ignored", + "6": "IgnoredFriend", + "7": "SuggestedFriend", +};