From 05ebfd1dfd4fe41dd487423b43dd44a6256a2060 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 20 Nov 2013 10:25:05 +0000 Subject: [PATCH] handle reddit short link whatsits --- modules/reddit/reddit.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/reddit/reddit.js b/modules/reddit/reddit.js index dc5cde6..0598592 100644 --- a/modules/reddit/reddit.js +++ b/modules/reddit/reddit.js @@ -107,6 +107,25 @@ var reddit = function(dbot) { dbot.api.link.addHandler(this.name, // I'm so sorry, Jesus. /https?:\/\/(www\.)?reddit\.com\/r\/([a-zA-Z0-9]+)(\/comments\/([a-zA-Z0-9]+)?\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)?)?/, rHandler); + dbot.api.link.addHandler(this.name + 'short', + /https?:\/\/(www\.)?redd.it\/([a-zA-Z0-9]+)/, + function(match, name, callback) { + this.api.getPostInfo(match[2], function(info) { + if(info) { + var infoString = dbot.t('about_post', { + 'poster': info.author, + 'subreddit': info.subreddit, + 'comments': info.num_comments, + 'score': info.score, + 'up': info.ups, + 'down': info.downs, + 'url': this.ApiRoot + match[2] + }); + if(info.over_18) infoString += " " + dbot.t("nsfw"); + callback(infoString); + } + }.bind(this)); + }.bind(this)); }.bind(this); };