Files
xiao/commands/random/shower-thought.js
T
Daniel Odendahl Jr b6afded306 Updates
2017-11-09 00:02:59 +00:00

28 lines
981 B
JavaScript

const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
module.exports = class ShowerThoughtCommand extends Command {
constructor(client) {
super(client, {
name: 'shower-thought',
aliases: ['shower-thoughts'],
group: 'random',
memberName: 'shower-thought',
description: 'Responds with a random shower thought, directly from r/Showerthoughts.'
});
}
async run(msg) {
try {
const { body } = await snekfetch
.get('https://www.reddit.com/r/Showerthoughts.json')
.query({ limit: 1000 });
const allowed = msg.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
if (!allowed.length) return msg.say('Hmm... It seems the thoughts are all gone right now. Try again later!');
return msg.say(allowed[Math.floor(Math.random() * allowed.length)].data.title);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};