From f2be027a63359b4ae8656ea8c2b14e86da846f19 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 4 Apr 2019 23:30:28 +0200 Subject: [PATCH 1/6] 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/6] 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/6] 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/6] 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 d8eb07f0467a7d70ab7c270c47f609617f532275 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 13 May 2021 01:14:52 +0200 Subject: [PATCH 5/6] 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 81877f4bb74ce0a0cc7fb35632ed84630c1c23d9 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 22 Jul 2021 07:48:46 +0200 Subject: [PATCH 6/6] 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) {