Add user/workshop/curator follow & unfollow support (#320)

* Add follow & unfollow user functions

* Add follow & unfollow to CSteamUser object methods

* Add support for following & unfollowing curators

* Correctly parse for eresult on error

* Use eresultError() helper
This commit is contained in:
3urobeat 2023-10-02 03:22:44 +02:00 committed by GitHub
parent f69519f547
commit bf2b4601ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 134 additions and 0 deletions

View File

@ -166,6 +166,14 @@ CSteamUser.prototype.inviteToGroup = function(groupID, callback) {
this._community.inviteUserToGroup(this.steamID, groupID, callback);
};
CSteamUser.prototype.follow = function(callback) {
this._community.followUser(this.steamID, callback);
};
CSteamUser.prototype.unfollow = function(callback) {
this._community.unfollowUser(this.steamID, callback);
};
CSteamUser.prototype.getAliases = function(callback) {
this._community.getUserAliases(this.steamID, callback);
};

View File

@ -730,3 +730,69 @@ SteamCommunity.prototype.respondToAllGroupJoinRequests = function(gid, approve,
}
}, "steamcommunity");
};
/**
* Follows a curator page
* @param {string} clanid - ID of the curator
* @param {function} callback - Takes only an Error object/null as the first argument
*/
SteamCommunity.prototype.followCurator = function(clanid, callback) {
this.httpRequestPost({
"uri": "https://store.steampowered.com/curators/ajaxfollow",
"form": {
"clanid": clanid,
"sessionid": this.getSessionID(),
"follow": 1
},
"json": true
}, (err, res, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
if (body.success && body.success.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success.success));
return;
}
callback(null);
}, "steamcommunity");
};
/**
* Unfollows a curator page
* @param {string} clanid - ID of the curator
* @param {function} callback - Takes only an Error object/null as the first argument
*/
SteamCommunity.prototype.unfollowCurator = function(clanid, callback) {
this.httpRequestPost({
"uri": "https://store.steampowered.com/curators/ajaxfollow",
"form": {
"clanid": clanid,
"sessionid": this.getSessionID(),
"follow": 0
},
"json": true
}, (err, res, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
if (body.success && body.success.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success.success));
return;
}
callback(null);
}, "steamcommunity");
};

View File

@ -296,6 +296,66 @@ SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback)
}, "steamcommunity");
};
SteamCommunity.prototype.followUser = function(userID, callback) {
if(typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
"uri": `https://steamcommunity.com/profiles/${userID.toString()}/followuser/`,
"form": {
"sessionid": this.getSessionID(),
},
"json": true
}, function(err, response, body) {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
if (body.success && body.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success));
return;
}
callback(null);
}, "steamcommunity");
};
SteamCommunity.prototype.unfollowUser = function(userID, callback) {
if(typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
"uri": `https://steamcommunity.com/profiles/${userID.toString()}/unfollowuser/`,
"form": {
"sessionid": this.getSessionID(),
},
"json": true
}, function(err, response, body) {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
if (body.success && body.success != SteamCommunity.EResult.OK) {
callback(Helpers.eresultError(body.success));
return;
}
callback(null);
}, "steamcommunity");
};
SteamCommunity.prototype.getUserAliases = function(userID, callback) {
if (typeof userID === 'string') {
userID = new SteamID(userID);