mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-27 17:00:06 +08:00
Added getFriendsList
This commit is contained in:
parent
2bbdbf36ad
commit
d54dd2c892
32
index.js
32
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');
|
||||
|
23
resources/EFriendRelationship.js
Normal file
23
resources/EFriendRelationship.js
Normal file
@ -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",
|
||||
};
|
Loading…
Reference in New Issue
Block a user