mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 22:34:46 +02:00
Allow Sakugabooru in non-NSFW channels
This commit is contained in:
@@ -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!`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user