From 6d470b6ad79cabcf0fcb2d88985eb773e7c4b912 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Sun, 24 Sep 2023 14:17:57 +0200 Subject: [PATCH 1/5] Add follow & unfollow user functions --- components/users.js | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/components/users.js b/components/users.js index df8a90f..89d5c47 100644 --- a/components/users.js +++ b/components/users.js @@ -296,6 +296,64 @@ 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) { + callback(null); + } else { + callback(new Error("Unknown error")); + } + }, "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) { + callback(null); + } else { + callback(new Error("Unknown error")); + } + }, "steamcommunity"); +}; + SteamCommunity.prototype.getUserAliases = function(userID, callback) { if (typeof userID === 'string') { userID = new SteamID(userID); From a88a8548fcde76c8fb9a7ada1c8538b78de9f540 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Sun, 24 Sep 2023 14:27:48 +0200 Subject: [PATCH 2/5] Add follow & unfollow to CSteamUser object methods --- classes/CSteamUser.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index f019b77..8b26516 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -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); }; From 2d76dcea6c7d78229eedd95e72031c654e373007 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:53:39 +0200 Subject: [PATCH 3/5] Add support for following & unfollowing curators --- components/groups.js | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/components/groups.js b/components/groups.js index 9f74f50..f31844c 100644 --- a/components/groups.js +++ b/components/groups.js @@ -730,3 +730,67 @@ 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) { + callback(null); + } else { + callback(new Error(EResult[body] || ("Error " + body))); + } + }, "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) { + callback(null); + } else { + callback(new Error(EResult[body] || ("Error " + body))); + } + }, "steamcommunity"); +}; \ No newline at end of file From 1b4ba3d172a1f0a96f9e7d89bc23f9f99b1ee50e Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:55:26 +0200 Subject: [PATCH 4/5] Correctly parse for eresult on error --- components/groups.js | 22 ++++++++++++++-------- components/users.js | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/components/groups.js b/components/groups.js index f31844c..8b7d797 100644 --- a/components/groups.js +++ b/components/groups.js @@ -755,11 +755,14 @@ SteamCommunity.prototype.followCurator = function(clanid, callback) { return; } - if (body.success) { - callback(null); - } else { - callback(new Error(EResult[body] || ("Error " + body))); + if (body.success && body.success.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success.success]); + err.eresult = err.code = body.success.success; + callback(err); + return; } + + callback(null); }, "steamcommunity"); }; @@ -787,10 +790,13 @@ SteamCommunity.prototype.unfollowCurator = function(clanid, callback) { return; } - if (body.success) { - callback(null); - } else { - callback(new Error(EResult[body] || ("Error " + body))); + if (body.success && body.success.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success.success]); + err.eresult = err.code = body.success.success; + callback(err); + return; } + + callback(null); }, "steamcommunity"); }; \ No newline at end of file diff --git a/components/users.js b/components/users.js index 89d5c47..bd4f362 100644 --- a/components/users.js +++ b/components/users.js @@ -317,11 +317,14 @@ SteamCommunity.prototype.followUser = function(userID, callback) { return; } - if (body.success) { - callback(null); - } else { - callback(new Error("Unknown error")); + if (body.success && body.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; } + + callback(null); }, "steamcommunity"); }; @@ -346,11 +349,14 @@ SteamCommunity.prototype.unfollowUser = function(userID, callback) { return; } - if (body.success) { - callback(null); - } else { - callback(new Error("Unknown error")); + if (body.success && body.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; } + + callback(null); }, "steamcommunity"); }; From cf0c07a1ad4153960acfa1430f3baee3dc38a538 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:07:08 +0200 Subject: [PATCH 5/5] Use eresultError() helper --- components/groups.js | 8 ++------ components/users.js | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/components/groups.js b/components/groups.js index 8b7d797..5ed64f6 100644 --- a/components/groups.js +++ b/components/groups.js @@ -756,9 +756,7 @@ SteamCommunity.prototype.followCurator = function(clanid, callback) { } if (body.success && body.success.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success.success]); - err.eresult = err.code = body.success.success; - callback(err); + callback(Helpers.eresultError(body.success.success)); return; } @@ -791,9 +789,7 @@ SteamCommunity.prototype.unfollowCurator = function(clanid, callback) { } if (body.success && body.success.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success.success]); - err.eresult = err.code = body.success.success; - callback(err); + callback(Helpers.eresultError(body.success.success)); return; } diff --git a/components/users.js b/components/users.js index bd4f362..48a1d8e 100644 --- a/components/users.js +++ b/components/users.js @@ -318,9 +318,7 @@ SteamCommunity.prototype.followUser = function(userID, callback) { } if (body.success && body.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; - callback(err); + callback(Helpers.eresultError(body.success)); return; } @@ -350,9 +348,7 @@ SteamCommunity.prototype.unfollowUser = function(userID, callback) { } if (body.success && body.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; - callback(err); + callback(Helpers.eresultError(body.success)); return; }