mirror of
https://github.com/reality/dbot.git
synced 2025-01-12 21:22:39 +01:00
~question
This commit is contained in:
parent
610a8cfabf
commit
0697f0b5a0
@ -144,10 +144,36 @@ var reddit = function(dbot) {
|
|||||||
callback(true, null);
|
callback(true, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
'getTopPosts': function(sr, callback) {
|
||||||
|
request.get({
|
||||||
|
'url': this.ApiRoot + 'r/' + sr + '/top.json',
|
||||||
|
'json': true,
|
||||||
|
'headers': {
|
||||||
|
'User-Agent': this.UserAgent
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if(!err && body && body.kind === 'Listing') {
|
||||||
|
var posts = _.pluck(body.data.children, 'data');
|
||||||
|
callback(null, posts);
|
||||||
|
} else {
|
||||||
|
callback(true, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
|
'~question': function(event) {
|
||||||
|
this.api.getTopPosts('askreddit', function(err, posts) {
|
||||||
|
if(!err) {
|
||||||
|
var qPost = _.random(0, posts.length - 1);
|
||||||
|
event.reply('Question: ' + qPost.title.trim());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
'~addredditfeed': function(event) {
|
'~addredditfeed': function(event) {
|
||||||
var channel = event.input[1],
|
var channel = event.input[1],
|
||||||
subreddit = event.input[2].replace('r/', ''),
|
subreddit = event.input[2].replace('r/', ''),
|
||||||
|
Loading…
Reference in New Issue
Block a user