3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 04:32:37 +01:00

handle reddit short link whatsits

This commit is contained in:
reality 2013-11-20 10:25:05 +00:00
parent 61c4afd8aa
commit 05ebfd1dfd

View File

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