mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 22:34:46 +02:00
SubredditCommand structure
This commit is contained in:
@@ -1,31 +1,18 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const SubredditCommand = require('../../structures/commands/Subreddit');
|
||||
|
||||
module.exports = class ShowerThoughtCommand extends Command {
|
||||
module.exports = class ShowerThoughtCommand extends SubredditCommand {
|
||||
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.'
|
||||
description: 'Responds with a random shower thought, directly from r/Showerthoughts.',
|
||||
subreddit: 'Showerthoughts'
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('https://www.reddit.com/r/Showerthoughts/top.json')
|
||||
.query({
|
||||
sort: 'top',
|
||||
t: 'day',
|
||||
limit: 100
|
||||
});
|
||||
const posts = body.data.children.filter(post => post.data && (msg.channel.nsfw ? true : !post.data.over_18));
|
||||
if (!posts.length) return msg.say('Hmm... It seems the thoughts are all gone right now. Try again later!');
|
||||
return msg.say(posts[Math.floor(Math.random() * posts.length)].data.title);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
generateText(post) {
|
||||
return post.title;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user