diff --git a/modules/reddit/reddit.js b/modules/reddit/reddit.js index 1cc9919..47f2482 100644 --- a/modules/reddit/reddit.js +++ b/modules/reddit/reddit.js @@ -36,13 +36,43 @@ var reddit = function(dbot) { callback(body[0].data.children[0].data); } }); + }, + + 'getCommentInfo': function(post, name, callback) { + request.get({ + 'url': this.ApiRoot + 'comments/' + post + '.json', + 'qs': { + 'comment': name + }, + 'json': true, + 'headers': { + 'User-Agent': this.UserAgent + } + }, function(err, response, body) { + if(body[1] && _.has(body[1], 'data')) { + callback(body[1].data.children[0].data); + } + }); } }; this.onLoad = function() { var rHandler = function(event, matches, name) { if(matches[6]) { // It's a comment - + this.api.getCommentInfo(matches[4], matches[6], function(info) { + if(info) { + var infoString = dbot.t('about_comment', { + 'poster': info.author, + 'subreddit': info.subreddit, + 'comments': info.num_comments, + 'score': info.ups - info.downs, + 'up': info.ups, + 'down': info.downs + }); + if(info.over_18) infoString += ' [NSFW]'; + event.reply(infoString); + } + }); } else if(matches[4]) { // It's a post this.api.getPostInfo(matches[4], function(info) { if(info) { @@ -54,7 +84,7 @@ var reddit = function(dbot) { 'up': info.ups, 'down': info.downs }); - if(info.over18) infoString += ' [NSFW]'; + if(info.over_18) infoString += ' [NSFW]'; event.reply(infoString); } }); diff --git a/modules/reddit/strings.json b/modules/reddit/strings.json index 87a23e5..2a93967 100644 --- a/modules/reddit/strings.json +++ b/modules/reddit/strings.json @@ -3,6 +3,9 @@ "en": "[{display_name} has {subscribers} subscribers ({active} active)]" }, "about_post": { - "en": "[Post by {poster} in {subreddit}. Comments: {comments}. Score: {score} ({up}|{down})]" + "en": "[Post by {poster} in {subreddit} - Comments: {comments}, Score: {score} ({up}|{down})]" + }, + "about_comment": { + "en": "[Comment by {poster} in {subreddit} - Score: {score} ({up}|{down})]" } }