Shower Thought Command

This commit is contained in:
Daniel Odendahl Jr
2017-10-19 22:47:37 +00:00
parent 9a65e88a30
commit ff6ffec639
3 changed files with 31 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
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-res',
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.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+3 -3
View File
@@ -28,14 +28,14 @@ module.exports = class RedditCommand extends Command {
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
.query({ sort: 'new' });
if (!body.data.children.length) return msg.say('Could not find any results.');
const post = body.data.children[Math.floor(Math.random() * body.data.children.length)].data;
if (!msg.channel.nsfw && post.over_18) return msg.say('This post is only viewable in NSFW channels.');
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;
const embed = new MessageEmbed()
.setColor(0xFF4500)
.setAuthor('Reddit', 'https://i.imgur.com/DSBOK0P.png')
.setURL(`https://www.reddit.com${post.permalink}`)
.setTitle(post.title)
.setDescription(`[View URL Here](${post.url})`)
.addField(' Upvotes',
post.ups, true)
.addField(' Downvotes',
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "48.0.0",
"version": "48.1.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {