From 444649ee8ce7945b30106751c2a630ebff5a32f4 Mon Sep 17 00:00:00 2001 From: Jarzon Date: Tue, 31 Jan 2017 05:45:36 -0500 Subject: [PATCH] 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"); +};