From f2be027a63359b4ae8656ea8c2b14e86da846f19 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 4 Apr 2019 23:30:28 +0200 Subject: [PATCH 1/9] Updated postUserComment and added deleteUserComment https://github.com/DoctorMcKay/node-steamcommunity/issues/219 --- components/users.js | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/components/users.js b/components/users.js index 946ecd7..d322cc6 100644 --- a/components/users.js +++ b/components/users.js @@ -134,7 +134,7 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) { "uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1", "form": { "comment": message, - "count": 6, + "count": 1, "sessionid": this.getSessionID() }, "json": true @@ -149,9 +149,50 @@ SteamCommunity.prototype.postUserComment = function(userID, message, callback) { } if(body.success) { + const $ = Cheerio.load(body.comments_html); + const commentID = $('.commentthread_comment').attr('id').split('_')[1]; + + callback(null, commentID); + } else if(body.error) { + callback(new Error(body.error)); + } else { + callback(new Error("Unknown error")); + } + }, "steamcommunity"); +}; + +SteamCommunity.prototype.deleteUserComment = function(userID, commentID, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + + var self = this; + this.httpRequestPost({ + "uri": "https://steamcommunity.com/comment/Profile/delete/" + userID.toString() + "/-1", + "form": { + "gidcomment": commentID, + "start": 0, + "count": 1, + "sessionid": this.getSessionID(), + "feature2": -1 + }, + "json": true + }, function(err, response, body) { + if(!callback) { + return; + } + + if (err) { + callback(err); + return; + } + + if(body.success && !body.comments_html.includes(commentID)) { callback(null); } else if(body.error) { callback(new Error(body.error)); + } else if(body.comments_html.includes(commentID)) { + callback(new Error("Failed to delete comment")); } else { callback(new Error("Unknown error")); } From 8edc5020e14d678ed4a1596044bc214d2342595f Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 5 Apr 2019 00:06:48 +0200 Subject: [PATCH 2/9] Added getUserComments(userID, options, callback) https://github.com/DoctorMcKay/node-steamcommunity/issues/208 --- components/users.js | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/components/users.js b/components/users.js index d322cc6..d34c86c 100644 --- a/components/users.js +++ b/components/users.js @@ -199,6 +199,61 @@ SteamCommunity.prototype.deleteUserComment = function(userID, commentID, callbac }, "steamcommunity"); }; +SteamCommunity.prototype.getUserComments = function(userID, options, callback) { + if(typeof userID === 'string') { + userID = new SteamID(userID); + } + + if (typeof options === 'function') { + callback = options; + options = {}; + } + + var self = this; + this.httpRequestPost({ + "uri": "https://steamcommunity.com/comment/Profile/render/" + userID.toString() + "/-1", + "form": { + "start": 0, + "count": 0, + "feature2": -1, + "sessionid": this.getSessionID(), + ...options + }, + "json": true + }, function(err, response, body) { + if(!callback) { + return; + } + + if (err) { + callback(err); + return; + } + + if(body.success) { + const $ = Cheerio.load(body.comments_html); + const comments = $(".commentthread_comment.responsive_body_text[id]").map((i, elem) => ({ + id: $(elem).attr("id").split("_")[1], + author: { + id: new SteamID("[U:1:" + $(elem).find("[data-miniprofile]").data("miniprofile") + "]"), + name: $(elem).find("bdi").text(), + avatar: $(elem).find(".playerAvatar img[src]").attr("src"), + state: $(elem).find(".playerAvatar").attr("class").split(" ").pop() + }, + date: new Date($(elem).find(".commentthread_comment_timestamp").data("timestamp") * 1000), + text: $(elem).find(".commentthread_comment_text").text(), + html: $(elem).find(".commentthread_comment_text").html() + })).get(); + + callback(null, comments, body.total_count); + } else if(body.error) { + callback(new Error(body.error)); + } else { + callback(new Error("Unknown error")); + } + }, "steamcommunity"); +}; + SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback) { if(typeof userID === 'string') { userID = new SteamID(userID); From 868ce9cdb4b8f2a88acac7c06545ffc9a7cf8504 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 5 Apr 2019 00:10:00 +0200 Subject: [PATCH 3/9] Added missing functions --- classes/CSteamUser.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 9ca4564..c70f741 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -148,6 +148,14 @@ CSteamUser.prototype.comment = function(message, callback) { this._community.postUserComment(this.steamID, message, callback); }; +CSteamUser.prototype.deleteComment = function(commentID, callback) { + this._community.deleteUserComment(this.steamID, commentID, callback); +}; + +CSteamUser.prototype.getUserComments = function(options, callback) { + this._community.postUserComment(this.steamID, options, callback); +}; + CSteamUser.prototype.inviteToGroup = function(groupID, callback) { this._community.inviteUserToGroup(this.steamID, groupID, callback); }; From 9ed377e843fc367b080640991f4d91dcf52c63c0 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 5 Apr 2019 00:13:02 +0200 Subject: [PATCH 4/9] Oopsy --- classes/CSteamUser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index c70f741..37b521e 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -152,8 +152,8 @@ CSteamUser.prototype.deleteComment = function(commentID, callback) { this._community.deleteUserComment(this.steamID, commentID, callback); }; -CSteamUser.prototype.getUserComments = function(options, callback) { - this._community.postUserComment(this.steamID, options, callback); +CSteamUser.prototype.getComments = function(options, callback) { + this._community.getUserComments(this.steamID, options, callback); }; CSteamUser.prototype.inviteToGroup = function(groupID, callback) { From e6995e337ef5c7242b875de5e45df6a8881faef3 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 19 Mar 2021 15:22:41 +0100 Subject: [PATCH 5/9] Added restorePackage & removePackage --- index.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/index.js b/index.js index 05303e3..70209b4 100644 --- a/index.js +++ b/index.js @@ -535,6 +535,70 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { } }; +/** + * Restore a previously removed steam package from your steam account. + * @param {int|string} packageID + * @param {function} callback + */ + SteamCommunity.prototype.restorePackage = function(packageID, callback) { + this.httpRequestPost({ + "uri": "https://help.steampowered.com/wizard/AjaxDoPackageRestore", + "form": { + "packageid": packageID, + "sessionid": this.getSessionID(), + "wizard_ajax": 1 + }, + "json": true + }, (err, res, body) => { + if (err) { + callback(err); + return; + } + + if (body.success && body.success != SteamCommunity.EResult.OK) { + + let err = new Error(body.errorMsg || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; + } + + callback(null); + }); +}; + +/** + * Remove a steam package from your steam account. + * @param {int|string} packageID + * @param {function} callback + */ + SteamCommunity.prototype.removePackage = function(packageID, callback) { + this.httpRequestPost({ + "uri": "https://help.steampowered.com/wizard/AjaxDoPackageRemove", + "form": { + "packageid": packageID, + "sessionid": this.getSessionID(), + "wizard_ajax": 1 + }, + "json": true + }, (err, res, body) => { + if (err) { + callback(err); + return; + } + + if (body.success && body.success != SteamCommunity.EResult.OK) { + + let err = new Error(body.errorMsg || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; + } + + callback(null); + }); +}; + require('./components/http.js'); require('./components/chat.js'); require('./components/profile.js'); From d8eb07f0467a7d70ab7c270c47f609617f532275 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 13 May 2021 01:14:52 +0200 Subject: [PATCH 6/9] re-use variable Co-authored-by: Mr-VIT --- components/users.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/components/users.js b/components/users.js index d34c86c..e40a8a7 100644 --- a/components/users.js +++ b/components/users.js @@ -232,18 +232,22 @@ SteamCommunity.prototype.getUserComments = function(userID, options, callback) { if(body.success) { const $ = Cheerio.load(body.comments_html); - const comments = $(".commentthread_comment.responsive_body_text[id]").map((i, elem) => ({ - id: $(elem).attr("id").split("_")[1], - author: { - id: new SteamID("[U:1:" + $(elem).find("[data-miniprofile]").data("miniprofile") + "]"), - name: $(elem).find("bdi").text(), - avatar: $(elem).find(".playerAvatar img[src]").attr("src"), - state: $(elem).find(".playerAvatar").attr("class").split(" ").pop() - }, - date: new Date($(elem).find(".commentthread_comment_timestamp").data("timestamp") * 1000), - text: $(elem).find(".commentthread_comment_text").text(), - html: $(elem).find(".commentthread_comment_text").html() - })).get(); + const comments = $(".commentthread_comment.responsive_body_text[id]").map((i, elem) => { + var $elem = $(elem), + $commentContent = $elem.find(".commentthread_comment_text"); + return { + id: $elem.attr("id").split("_")[1], + author: { + id: new SteamID("[U:1:" + $elem.find("[data-miniprofile]").data("miniprofile") + "]"), + name: $elem.find("bdi").text(), + avatar: $elem.find(".playerAvatar img[src]").attr("src"), + state: $elem.find(".playerAvatar").attr("class").split(" ").pop() + }, + date: new Date($elem.find(".commentthread_comment_timestamp").data("timestamp") * 1000), + text: $commentContent.text(), + html: $commentContent.html() + } + }).get(); callback(null, comments, body.total_count); } else if(body.error) { From b4818d6d67049c340e58005683a5bd1e308a1917 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 4 Jun 2021 03:26:24 +0200 Subject: [PATCH 7/9] Bugfix --- index.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 70209b4..dcbfcb8 100644 --- a/index.js +++ b/index.js @@ -303,8 +303,8 @@ SteamCommunity.prototype.setCookies = function(cookies) { }); }; -SteamCommunity.prototype.getSessionID = function() { - var cookies = this._jar.getCookieString("http://steamcommunity.com").split(';'); +SteamCommunity.prototype.getSessionID = function(host = "http://steamcommunity.com") { + var cookies = this._jar.getCookieString(host).split(';'); for(var i = 0; i < cookies.length; i++) { var match = cookies[i].trim().match(/([^=]+)=(.+)/); if(match[1] == 'sessionid') { @@ -545,7 +545,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { "uri": "https://help.steampowered.com/wizard/AjaxDoPackageRestore", "form": { "packageid": packageID, - "sessionid": this.getSessionID(), + "sessionid": this.getSessionID('https://help.steampowered.com'), "wizard_ajax": 1 }, "json": true @@ -555,10 +555,8 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { return; } - if (body.success && body.success != SteamCommunity.EResult.OK) { - + if (!body.success) { let err = new Error(body.errorMsg || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; callback(err); return; } @@ -577,7 +575,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { "uri": "https://help.steampowered.com/wizard/AjaxDoPackageRemove", "form": { "packageid": packageID, - "sessionid": this.getSessionID(), + "sessionid": this.getSessionID('https://help.steampowered.com'), "wizard_ajax": 1 }, "json": true @@ -587,10 +585,8 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { return; } - if (body.success && body.success != SteamCommunity.EResult.OK) { - + if (!body.success) { let err = new Error(body.errorMsg || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; callback(err); return; } From e0687f8828b23afc565fa6e52ede883a90f867d4 Mon Sep 17 00:00:00 2001 From: Revadike Date: Fri, 4 Jun 2021 04:24:11 +0200 Subject: [PATCH 8/9] Updated Enums --- resources/EPersonaState.js | 4 ++-- resources/EPersonaStateFlag.js | 7 ++++++- resources/EResult.js | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/resources/EPersonaState.js b/resources/EPersonaState.js index 2bb811a..d09c90d 100644 --- a/resources/EPersonaState.js +++ b/resources/EPersonaState.js @@ -9,7 +9,7 @@ module.exports = { "Snooze": 4, "LookingToTrade": 5, "LookingToPlay": 6, - "Max": 7, + "Invisible": 7, // Value-to-name mapping for convenience "0": "Offline", @@ -19,5 +19,5 @@ module.exports = { "4": "Snooze", "5": "LookingToTrade", "6": "LookingToPlay", - "7": "Max", + "7": "Invisible", }; diff --git a/resources/EPersonaStateFlag.js b/resources/EPersonaStateFlag.js index dfb7b81..eb1f5b1 100644 --- a/resources/EPersonaStateFlag.js +++ b/resources/EPersonaStateFlag.js @@ -4,7 +4,8 @@ module.exports = { "HasRichPresence": 1, "InJoinableGame": 2, - "Golden": 4, // removed "no longer has any effect" + "Golden": 4, + "RemotePlayTogether": 8, "OnlineUsingWeb": 256, // removed "renamed to ClientTypeWeb" "ClientTypeWeb": 256, "OnlineUsingMobile": 512, // removed "renamed to ClientTypeMobile" @@ -14,14 +15,18 @@ module.exports = { "OnlineUsingVR": 2048, // removed "renamed to ClientTypeVR" "ClientTypeVR": 2048, "LaunchTypeGamepad": 4096, + "LaunchTypeCompatTool": 8192, // Value-to-name mapping for convenience "1": "HasRichPresence", "2": "InJoinableGame", "4": "Golden", + "8": "RemotePlayTogether", "256": "ClientTypeWeb", "512": "ClientTypeMobile", "1024": "ClientTypeTenfoot", "2048": "ClientTypeVR", "4096": "LaunchTypeGamepad", + "8192": "LaunchTypeCompatTool", }; + diff --git a/resources/EResult.js b/resources/EResult.js index 14c39f9..6513772 100644 --- a/resources/EResult.js +++ b/resources/EResult.js @@ -123,6 +123,13 @@ module.exports = { "WGNetworkSendExceeded": 110, "AccountNotFriends": 111, "LimitedUserAccount": 112, + "CantRemoveItem": 113, + "AccountHasBeenDeleted": 114, + "AccountHasAnExistingUserCancelledLicense": 115, + "DeniedDueToCommunityCooldown": 116, + "NoLauncherSpecified": 117, + "MustAgreeToSSA": 118, + "ClientNoLongerSupported": 119, // Value-to-name mapping for convenience "0": "Invalid", @@ -237,4 +244,11 @@ module.exports = { "110": "WGNetworkSendExceeded", "111": "AccountNotFriends", "112": "LimitedUserAccount", + "113": "CantRemoveItem", + "114": "AccountHasBeenDeleted", + "115": "AccountHasAnExistingUserCancelledLicense", + "116": "DeniedDueToCommunityCooldown", + "117": "NoLauncherSpecified", + "118": "MustAgreeToSSA", + "119": "ClientNoLongerSupported", }; From 81877f4bb74ce0a0cc7fb35632ed84630c1c23d9 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 22 Jul 2021 07:48:46 +0200 Subject: [PATCH 9/9] Use object.assign instead --- components/users.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/users.js b/components/users.js index e40a8a7..fcdb85c 100644 --- a/components/users.js +++ b/components/users.js @@ -209,16 +209,16 @@ SteamCommunity.prototype.getUserComments = function(userID, options, callback) { options = {}; } - var self = this; + var form = Object.assign({ + "start": 0, + "count": 0, + "feature2": -1, + "sessionid": this.getSessionID() + }, options); + this.httpRequestPost({ "uri": "https://steamcommunity.com/comment/Profile/render/" + userID.toString() + "/-1", - "form": { - "start": 0, - "count": 0, - "feature2": -1, - "sessionid": this.getSessionID(), - ...options - }, + "form": form, "json": true }, function(err, response, body) { if(!callback) {