Handle reddit better

This commit is contained in:
Daniel Odendahl Jr
2018-09-06 14:25:02 +00:00
parent 9c0f89b53e
commit 728a80db1e
4 changed files with 21 additions and 8 deletions
+4 -1
View File
@@ -25,7 +25,10 @@ module.exports = class RedditCommand extends Command {
try {
const { body } = await request
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
.query({ sort: 'new' });
.query({
sort: 'new',
limit: 100
});
const allowed = msg.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return msg.say('Could not find any results.');
const post = allowed[Math.floor(Math.random() * allowed.length)].data;