Adding .getAllComments()

This commit is contained in:
Jarzon 2017-01-31 05:45:36 -05:00
parent b9ec1ccfb5
commit 444649ee8c
2 changed files with 45 additions and 0 deletions

View File

@ -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);
};

View File

@ -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");
};