mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Handle reddit better
This commit is contained in:
@@ -17,7 +17,13 @@ module.exports = class MemeCommand extends Command {
|
||||
async run(msg) {
|
||||
const subreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
|
||||
try {
|
||||
const { body } = await request.get(`https://www.reddit.com/r/${subreddit}/hot.json`);
|
||||
const { body } = await request
|
||||
.get(`https://www.reddit.com/r/${subreddit}/top.json`)
|
||||
.query({
|
||||
sort: 'top',
|
||||
t: 'day',
|
||||
limit: 100
|
||||
});
|
||||
const posts = body.data.children.filter(post => post.data && post.data.post_hint === 'image' && post.data.url);
|
||||
if (!posts.length) return msg.reply(`I couldn't fetch any images from r/${subreddit}...`);
|
||||
const post = posts[Math.floor(Math.random() * posts.length)];
|
||||
|
||||
@@ -25,7 +25,10 @@ module.exports = class RedditCommand extends Command {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
|
||||
.query({ sort: 'new' });
|
||||
.query({
|
||||
sort: 'new',
|
||||
limit: 100
|
||||
});
|
||||
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;
|
||||
|
||||
@@ -15,11 +15,15 @@ module.exports = class ShowerThoughtCommand extends Command {
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.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);
|
||||
.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!`);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "90.2.0",
|
||||
"version": "90.2.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user