Allow Sakugabooru in non-NSFW channels

This commit is contained in:
Dragon Fire
2021-03-14 13:57:42 -04:00
parent 5d48516a26
commit 8d4c5f1a43
+11 -7
View File
@@ -9,11 +9,10 @@ module.exports = class SakugabooruCommand extends Command {
group: 'search', group: 'search',
memberName: 'sakugabooru', memberName: 'sakugabooru',
description: 'Responds with an image from Sakugabooru, with optional query.', description: 'Responds with an image from Sakugabooru, with optional query.',
nsfw: true,
credit: [ credit: [
{ {
name: 'Danbooru', name: 'Sakugabooru',
url: 'https://danbooru.donmai.us/', url: 'https://www.sakugabooru.com/',
reason: 'API' reason: 'API'
} }
], ],
@@ -33,11 +32,16 @@ module.exports = class SakugabooruCommand extends Command {
const { body } = await request const { body } = await request
.get('https://www.sakugabooru.com/post.json') .get('https://www.sakugabooru.com/post.json')
.query({ .query({
tags: `${query} order:random`, tags: query,
limit: 1 limit: 100
}); });
if (!body.length || !body[0].file_url) return msg.say('Could not find any results.'); if (!body.length) return msg.say('Could not find any results.');
return msg.say(body[0].file_url); const posts = body.filter(post => {
if (!msg.channel.nsfw && (post.rating === 'e' || post.rating === 'q')) return false;
return post.file_url;
});
if (!posts.length) return msg.say('Could not find any results.');
return msg.say(posts[Math.floor(Math.random() * posts.length)].file_url);
} catch (err) { } catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
} }