2018-09-27 19:04:42 +02:00
|
|
|
const { Command } = require('discord.js-commando');
|
|
|
|
const Discord = require('discord.js');
|
|
|
|
const snekfetch = require('snekfetch');
|
2018-09-27 19:06:41 +02:00
|
|
|
module.exports = class redditCommand extends Command {
|
2018-09-27 19:04:42 +02:00
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
|
|
name: 'reddit',
|
|
|
|
group: 'fun',
|
|
|
|
memberName: 'reddit',
|
|
|
|
description: `Show a random images from the subreddit you choose`,
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
key: 'sub',
|
|
|
|
prompt: 'Wich subreddit would you like to see?',
|
|
|
|
type: 'string',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, { sub }) {
|
2018-09-28 00:51:44 +02:00
|
|
|
const { body } = await snekfetch.get('https://www.reddit.com/r/' + sub + '.json?limit=100');
|
2018-09-27 19:04:42 +02:00
|
|
|
let /* the bodies hit the floor */ i = Math.floor((Math.random() * 10) + 1);
|
2018-09-28 13:08:53 +02:00
|
|
|
let a = 0
|
2018-09-28 16:16:50 +02:00
|
|
|
if (!body.data.children[1])
|
2018-09-27 20:27:34 +02:00
|
|
|
return message.say('Not a valid subreddit')
|
2018-09-28 16:16:50 +02:00
|
|
|
while (body.data.children[i].data.post_hint !== 'image') {
|
2018-09-27 23:10:46 +02:00
|
|
|
i = Math.floor((Math.random() * 100) + 1);
|
2018-09-28 13:08:53 +02:00
|
|
|
a++
|
2018-09-28 16:16:50 +02:00
|
|
|
if (a == 5)
|
|
|
|
return message.say("Could not find any images")
|
2018-09-27 19:04:42 +02:00
|
|
|
}
|
2018-09-28 16:16:50 +02:00
|
|
|
if (body.data.children[i].data.over_18 == true)
|
2018-09-27 22:49:48 +02:00
|
|
|
return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback <your feedback>\")")
|
2018-09-27 19:11:14 +02:00
|
|
|
const redditEmbed = new Discord.RichEmbed()
|
2018-09-27 19:04:42 +02:00
|
|
|
.setColor("#ff9900")
|
|
|
|
.setTitle(body.data.children[i].data.title)
|
2018-09-27 22:58:16 +02:00
|
|
|
.setImage(body.data.children[i].data.url)
|
|
|
|
.setURL('https://reddit.com' + body.data.children[i].data.permalink)
|
2018-09-27 22:53:06 +02:00
|
|
|
.setFooter(`⬆ ${body.data.children[i].data.ups} 💬 ${body.data.children[i].data.num_comments}`)
|
2018-09-27 19:04:42 +02:00
|
|
|
|
2018-09-27 19:11:14 +02:00
|
|
|
message.say(redditEmbed);
|
2018-09-27 19:04:42 +02:00
|
|
|
}
|
|
|
|
}
|