mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-22 10:19:11 +02:00
Shower Thought Command
This commit is contained in:
@@ -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!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -28,14 +28,14 @@ module.exports = class RedditCommand extends Command {
|
|||||||
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
|
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
|
||||||
.query({ sort: 'new' });
|
.query({ sort: 'new' });
|
||||||
if (!body.data.children.length) return msg.say('Could not find any results.');
|
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;
|
const allowed = msg.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
|
||||||
if (!msg.channel.nsfw && post.over_18) return msg.say('This post is only viewable in NSFW channels.');
|
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()
|
const embed = new MessageEmbed()
|
||||||
.setColor(0xFF4500)
|
.setColor(0xFF4500)
|
||||||
.setAuthor('Reddit', 'https://i.imgur.com/DSBOK0P.png')
|
.setAuthor('Reddit', 'https://i.imgur.com/DSBOK0P.png')
|
||||||
.setURL(`https://www.reddit.com${post.permalink}`)
|
.setURL(`https://www.reddit.com${post.permalink}`)
|
||||||
.setTitle(post.title)
|
.setTitle(post.title)
|
||||||
.setDescription(`[View URL Here](${post.url})`)
|
|
||||||
.addField('❯ Upvotes',
|
.addField('❯ Upvotes',
|
||||||
post.ups, true)
|
post.ups, true)
|
||||||
.addField('❯ Downvotes',
|
.addField('❯ Downvotes',
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "48.0.0",
|
"version": "48.1.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user