From f2be027a63359b4ae8656ea8c2b14e86da846f19 Mon Sep 17 00:00:00 2001 From: Revadike Date: Thu, 4 Apr 2019 23:30:28 +0200 Subject: [PATCH] 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")); }