From 444649ee8ce7945b30106751c2a630ebff5a32f4 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Tue, 31 Jan 2017 05:45:36 -0500 Subject: [PATCH 01/12] Adding .getAllComments() --- classes/CSteamGroup.js | 4 ++++ components/groups.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/classes/CSteamGroup.js b/classes/CSteamGroup.js index ef130fc..69828f7 100644 --- a/classes/CSteamGroup.js +++ b/classes/CSteamGroup.js @@ -113,3 +113,7 @@ CSteamGroup.prototype.kick = function(steamID, callback) { CSteamGroup.prototype.getHistory = function(page, callback) { this._community.getGroupHistory(this.steamID, page, callback); }; + +CSteamGroup.prototype.getAllComments = function(from, count, callback) { + this._community.getAllGroupComments(this.steamID, from, count, callback); +}; diff --git a/components/groups.js b/components/groups.js index 64da890..2ecdaaa 100644 --- a/components/groups.js +++ b/components/groups.js @@ -517,3 +517,44 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { callback(null, output); }, "steamcommunity"); }; + +SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callback) { + var options = {}; + options.uri = "http://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/"; + options.method = "POST"; + options.body = "start=" + from + "&count=" + count; + + var self = this; + this.httpRequest(options, function(err, response, body) { + if (err) { + callback(err); + return; + } + + var comments = []; + + body = JSON.parse(body); + body = body.comments_html; + + $ = Cheerio.load(body); + + $(".commentthread_comment_content").each(function () { + var comment = {}; + var cachedSelector; + + cachedSelector = $(this).find(".commentthread_author_link"); + comment.authorName = $(cachedSelector).find("bdi").text(); + comment.authorId = $(cachedSelector).attr('href').replace("http://steamcommunity.com/id/", ""); + comment.date = $(this).find(".commentthread_comment_timestamp").text().trim(); + + cachedSelector = $(this).find(".commentthread_comment_text"); + + comment.commentId = $(cachedSelector).attr('id').replace("comment_content_", ""); + comment.text = $(cachedSelector).text().trim(); + + comments.push(comment); + }); + + callback(null, comments); + }, "steamcommunity"); +}; From f1b742dff4cb3175f1c726aeab43fd7581e7e27a Mon Sep 17 00:00:00 2001 From: Jarzon Date: Tue, 31 Jan 2017 06:26:11 -0500 Subject: [PATCH 02/12] Adding Chrono to parse relative date --- components/groups.js | 3 ++- package.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/groups.js b/components/groups.js index 2ecdaaa..884b53d 100644 --- a/components/groups.js +++ b/components/groups.js @@ -2,6 +2,7 @@ var SteamCommunity = require('../index.js'); var SteamID = require('steamid'); var xml2js = require('xml2js'); var Cheerio = require('cheerio'); +var chrono = require('chrono-node'); SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link, addresses, addressIdx) { members = members || []; @@ -545,7 +546,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba cachedSelector = $(this).find(".commentthread_author_link"); comment.authorName = $(cachedSelector).find("bdi").text(); comment.authorId = $(cachedSelector).attr('href').replace("http://steamcommunity.com/id/", ""); - comment.date = $(this).find(".commentthread_comment_timestamp").text().trim(); + comment.date = chrono.parseDate($(this).find(".commentthread_comment_timestamp").text().trim()); cachedSelector = $(this).find(".commentthread_comment_text"); diff --git a/package.json b/package.json index de07d9d..1e85f29 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "xml2js": "^0.4.11", "cheerio": "0.22.0", "async": "^2.1.4", - "steam-totp": "^1.3.0" + "steam-totp": "^1.3.0", + "chrono-node": "^1.2.5" }, "engines": { "node": ">=4.0.0" From db3aa4ace8cd45404f628d829badbb3645ca136b Mon Sep 17 00:00:00 2001 From: Jarzon Date: Tue, 31 Jan 2017 08:48:38 -0500 Subject: [PATCH 03/12] Catch the community id and the custom url of the author --- components/groups.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/components/groups.js b/components/groups.js index 884b53d..d5d6a70 100644 --- a/components/groups.js +++ b/components/groups.js @@ -534,10 +534,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba var comments = []; - body = JSON.parse(body); - body = body.comments_html; - - $ = Cheerio.load(body); + $ = Cheerio.load(JSON.parse(body).comments_html); $(".commentthread_comment_content").each(function () { var comment = {}; @@ -545,11 +542,10 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba cachedSelector = $(this).find(".commentthread_author_link"); comment.authorName = $(cachedSelector).find("bdi").text(); - comment.authorId = $(cachedSelector).attr('href').replace("http://steamcommunity.com/id/", ""); + comment.authorId = $(cachedSelector).attr('href').replace(/http:\/\/steamcommunity.com\/(id|profiles)\//, ""); comment.date = chrono.parseDate($(this).find(".commentthread_comment_timestamp").text().trim()); cachedSelector = $(this).find(".commentthread_comment_text"); - comment.commentId = $(cachedSelector).attr('id').replace("comment_content_", ""); comment.text = $(cachedSelector).text().trim(); From 12f1ddf6a0776d6a93c8256effa20c95a54c3f61 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 1 Feb 2017 11:27:58 -0500 Subject: [PATCH 04/12] Missing header Content-Type --- components/groups.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/components/groups.js b/components/groups.js index d5d6a70..ca38863 100644 --- a/components/groups.js +++ b/components/groups.js @@ -522,6 +522,9 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callback) { var options = {}; options.uri = "http://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/"; + options.headers = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + }; options.method = "POST"; options.body = "start=" + from + "&count=" + count; @@ -540,14 +543,14 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba var comment = {}; var cachedSelector; - cachedSelector = $(this).find(".commentthread_author_link"); - comment.authorName = $(cachedSelector).find("bdi").text(); - comment.authorId = $(cachedSelector).attr('href').replace(/http:\/\/steamcommunity.com\/(id|profiles)\//, ""); + var $selector = $(this).find(".commentthread_author_link"); + comment.authorName = $($selector).find("bdi").text(); + comment.authorId = $($selector).attr("href").replace(/http:\/\/steamcommunity.com\/(id|profiles)\//, ""); comment.date = chrono.parseDate($(this).find(".commentthread_comment_timestamp").text().trim()); - cachedSelector = $(this).find(".commentthread_comment_text"); - comment.commentId = $(cachedSelector).attr('id').replace("comment_content_", ""); - comment.text = $(cachedSelector).text().trim(); + $selector = $(this).find(".commentthread_comment_text"); + comment.commentId = $($selector).attr("id").replace("comment_content_", ""); + comment.text = $($selector).text().trim(); comments.push(comment); }); From b3174b9f0bae3f385040a47ebdd597ee4c440e03 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 1 Feb 2017 12:03:34 -0500 Subject: [PATCH 05/12] Revert using chrono to parse the date --- components/groups.js | 3 +-- package.json | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/groups.js b/components/groups.js index ca38863..89e1391 100644 --- a/components/groups.js +++ b/components/groups.js @@ -2,7 +2,6 @@ var SteamCommunity = require('../index.js'); var SteamID = require('steamid'); var xml2js = require('xml2js'); var Cheerio = require('cheerio'); -var chrono = require('chrono-node'); SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link, addresses, addressIdx) { members = members || []; @@ -546,7 +545,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba var $selector = $(this).find(".commentthread_author_link"); comment.authorName = $($selector).find("bdi").text(); comment.authorId = $($selector).attr("href").replace(/http:\/\/steamcommunity.com\/(id|profiles)\//, ""); - comment.date = chrono.parseDate($(this).find(".commentthread_comment_timestamp").text().trim()); + comment.date = $(this).find(".commentthread_comment_timestamp").text().trim(); $selector = $(this).find(".commentthread_comment_text"); comment.commentId = $($selector).attr("id").replace("comment_content_", ""); diff --git a/package.json b/package.json index 1e85f29..de07d9d 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,7 @@ "xml2js": "^0.4.11", "cheerio": "0.22.0", "async": "^2.1.4", - "steam-totp": "^1.3.0", - "chrono-node": "^1.2.5" + "steam-totp": "^1.3.0" }, "engines": { "node": ">=4.0.0" From c180557f523fcda0070872d7dd11daeffc6e939a Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 1 Feb 2017 13:30:38 -0500 Subject: [PATCH 06/12] Using decodeSteamTime() to parse date Adding to .decodeSteamTime() the ability to parse steam relative time --- components/groups.js | 3 ++- components/helpers.js | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/components/groups.js b/components/groups.js index 89e1391..845a000 100644 --- a/components/groups.js +++ b/components/groups.js @@ -2,6 +2,7 @@ var SteamCommunity = require('../index.js'); var SteamID = require('steamid'); var xml2js = require('xml2js'); var Cheerio = require('cheerio'); +var Helpers = require('./helpers.js'); SteamCommunity.prototype.getGroupMembers = function(gid, callback, members, link, addresses, addressIdx) { members = members || []; @@ -545,7 +546,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba var $selector = $(this).find(".commentthread_author_link"); comment.authorName = $($selector).find("bdi").text(); comment.authorId = $($selector).attr("href").replace(/http:\/\/steamcommunity.com\/(id|profiles)\//, ""); - comment.date = $(this).find(".commentthread_comment_timestamp").text().trim(); + comment.date = Helpers.decodeSteamTime($(this).find(".commentthread_comment_timestamp").text().trim()); $selector = $(this).find(".commentthread_comment_text"); comment.commentId = $($selector).attr("id").replace("comment_content_", ""); diff --git a/components/helpers.js b/components/helpers.js index ec71ea3..d33d391 100644 --- a/components/helpers.js +++ b/components/helpers.js @@ -13,11 +13,26 @@ exports.isSteamID = function(input) { }; exports.decodeSteamTime = function(time) { - var parts = time.split('@'); - if (!parts[0].match(/,/)) { - // no year, assume current year - parts[0] += ", " + (new Date()).getFullYear(); + var date = new Date(); + + if (time.includes("@")) { + var parts = time.split('@'); + if (!parts[0].includes(",")) { + // no year, assume current year + parts[0] += ", " + date.getFullYear(); + } + + date = new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it + } else { + // Relative date + var amount = time.replace(/(\d) (minutes|hour|hours) ago/, "$1"); + + if(time.includes("minutes")) { + date.setMinutes(date.getMinutes() - amount); + } else if(time.match(/hour|hours/)) { + date.setHours(date.getHours() - amount); + } } - return new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it + return date; }; From bbd80d4154f8d6d3af2e38d9d0a7520e791d3d4a Mon Sep 17 00:00:00 2001 From: Jarzon Date: Thu, 2 Feb 2017 07:53:18 -0500 Subject: [PATCH 07/12] Fixing not getting the html in the comment --- components/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/groups.js b/components/groups.js index 845a000..d0e5c7b 100644 --- a/components/groups.js +++ b/components/groups.js @@ -550,7 +550,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba $selector = $(this).find(".commentthread_comment_text"); comment.commentId = $($selector).attr("id").replace("comment_content_", ""); - comment.text = $($selector).text().trim(); + comment.text = $($selector).html().trim(); comments.push(comment); }); From e2dae00af299872e4a223b496bd592978014b842 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Tue, 7 Feb 2017 15:35:29 -0500 Subject: [PATCH 08/12] Simplifying the request's options --- components/groups.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/components/groups.js b/components/groups.js index d0e5c7b..86ba37c 100644 --- a/components/groups.js +++ b/components/groups.js @@ -520,13 +520,14 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { }; SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callback) { - var options = {}; - options.uri = "http://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/"; - options.headers = { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" + var options = { + uri: "http://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/", + method: "POST", + form: { + start: from, + count: count + } }; - options.method = "POST"; - options.body = "start=" + from + "&count=" + count; var self = this; this.httpRequest(options, function(err, response, body) { @@ -557,4 +558,4 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba callback(null, comments); }, "steamcommunity"); -}; +}; \ No newline at end of file From f7ebe68bd83c14f06e9719f34abfa6329dcd0024 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 8 Feb 2017 12:30:47 -0500 Subject: [PATCH 09/12] Adding .deleteComment() --- classes/CSteamGroup.js | 4 ++++ components/groups.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/classes/CSteamGroup.js b/classes/CSteamGroup.js index 69828f7..680ed4c 100644 --- a/classes/CSteamGroup.js +++ b/classes/CSteamGroup.js @@ -117,3 +117,7 @@ CSteamGroup.prototype.getHistory = function(page, callback) { CSteamGroup.prototype.getAllComments = function(from, count, callback) { this._community.getAllGroupComments(this.steamID, from, count, callback); }; + +CSteamGroup.prototype.deleteComment = function(cid, callback) { + this._community.deleteGroupComment(this.steamID, cid, callback); +}; diff --git a/components/groups.js b/components/groups.js index 86ba37c..ffe7fea 100644 --- a/components/groups.js +++ b/components/groups.js @@ -558,4 +558,27 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba callback(null, comments); }, "steamcommunity"); +}; + +SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { + if(Number.isInteger(cid)) { + callback("Pass the comment id as a string"); + } + + var options = { + uri: "http://steamcommunity.com/comment/Clan/delete/" + gid.getSteamID64() + "/-1/", + form: { + sessionid: this.getSessionID(), + gidcomment: cid + } + }; + + var self = this; + this.httpRequestPost(options, function(err, response, body) { + if(!callback) { + return; + } + + callback(err || null); + }, "steamcommunity"); }; \ No newline at end of file From 530bbcb9eb0fd9d6bc50327c49c00410e6da0056 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 8 Feb 2017 15:22:50 -0500 Subject: [PATCH 10/12] Pass a Error obj to the callback --- components/groups.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/groups.js b/components/groups.js index ffe7fea..f4a56b2 100644 --- a/components/groups.js +++ b/components/groups.js @@ -562,7 +562,8 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { if(Number.isInteger(cid)) { - callback("Pass the comment id as a string"); + callback(new Error("Pass the comment id as a string")); + return; } var options = { From e2f94cb1e751aa3fc483a503d02990be7f968f28 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 15 Mar 2017 12:55:48 -0400 Subject: [PATCH 11/12] Convert the number to a string --- components/groups.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/groups.js b/components/groups.js index f4a56b2..1137c6f 100644 --- a/components/groups.js +++ b/components/groups.js @@ -562,8 +562,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { if(Number.isInteger(cid)) { - callback(new Error("Pass the comment id as a string")); - return; + cid = cid.toString(); } var options = { From 3bba7025d40a465d36fc4ecb03062d5854e564ab Mon Sep 17 00:00:00 2001 From: Jarzon Date: Wed, 15 Mar 2017 13:08:22 -0400 Subject: [PATCH 12/12] Changes for code consistency --- components/groups.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/groups.js b/components/groups.js index 1137c6f..3405416 100644 --- a/components/groups.js +++ b/components/groups.js @@ -522,7 +522,6 @@ SteamCommunity.prototype.getGroupHistory = function(gid, page, callback) { SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callback) { var options = { uri: "http://steamcommunity.com/comment/Clan/render/" + gid.getSteamID64() + "/-1/", - method: "POST", form: { start: from, count: count @@ -530,7 +529,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba }; var self = this; - this.httpRequest(options, function(err, response, body) { + this.httpRequestPost(options, function(err, response, body) { if (err) { callback(err); return; @@ -538,7 +537,7 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba var comments = []; - $ = Cheerio.load(JSON.parse(body).comments_html); + var $ = Cheerio.load(JSON.parse(body).comments_html); $(".commentthread_comment_content").each(function () { var comment = {}; @@ -561,7 +560,8 @@ SteamCommunity.prototype.getAllGroupComments = function(gid, from, count, callba }; SteamCommunity.prototype.deleteGroupComment = function(gid, cid, callback) { - if(Number.isInteger(cid)) { + + if(typeof cid !== 'string') { cid = cid.toString(); }