3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

get a random post from a given subreddit

This commit is contained in:
reality 2015-03-28 12:55:06 +00:00
parent e57b0107f4
commit a27f789a37

View File

@ -177,6 +177,27 @@ var reddit = function(dbot) {
});
},
'~r': function(event) {
var sr = event.params[1].trim();
this.api.getNewPosts(sr, 0, function(err, posts) {
if(!err) {
var qPost = posts[_.random(0, posts.length -1)];
event.reply(dbot.t('about_post', {
'title': _.unescape(qPost.title.trim()),
'poster': qPost.author,
'subreddit': qPost.subreddit,
'comments': qPost.num_comments,
'score': qPost.score,
'up': qPost.ups,
'down': qPost.downs,
'url': qPost.url
}));
} else {
event.reply('Could not find that subreddit');
}
});
},
'~addredditfeed': function(event) {
var channel = event.input[1],
subreddit = event.input[2].replace('r/', ''),