import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; import Axios from 'axios'; import { colour } from '../../Config'; export default class DanbooruNSFW extends Command { public constructor() { super('danbooru', { aliases: ['danbooru'], category: 'nsfw', description: { content: 'Danbooru.', usage: '[tag]', examples: [ '', 'minecraft' ] }, ratelimit: 3, args: [ { id: 'tag', type: 'string', prompt: { start: 'What tag would you like? (Only one is supported at this time because I have no idea how this API works...)', optional: true } } ] }); } public async exec(msg: Message, { tag }): Promise { //@ts-ignore if (!msg.channel.nsfw) return msg.reply('This is not an NSFW marked channel!'); let tags; if (tag) tags = await tag.trim().toLowerCase(); const denylist = ['loli', 'shota', 'cub', 'young', 'child', 'baby', 'guro', 'gore', 'vote', 'scat', 'poop', 'kid', 'kiddie', 'kiddy', 'cp', 'shit', 'turd', 'feces', 'excrement', 'excrete']; if (tags && denylist.includes(tags)) return msg.reply('A denylisted word was used! ⛔'); const response = await Axios.get(`https://danbooru.donmai.us/posts.json?limit=200&tags=${tags}+-rating:safe`) .catch(error => { console.error(error); return msg.reply('Woops, there was an error regarding the (https://danbooru.donmai.us) API.'); }); //@ts-ignore const randomInt = Math.floor(Math.random() * response.data.length); //@ts-ignore if (denylist.includes(response.data[randomInt].tags)) { return msg.reply('Sorry! This image had a tag that was denylisted! ⛔'); } let getRating = (rating: string) => { switch (rating) { case 's': return 'Safe'; break; case 'q': return 'Questionable'; break; case 'e': return 'Explicit'; break; case 'u': return 'Unrated'; break; } } const embed = this.client.util.embed() .setColor(colour) .setTitle(`Danbooru - ${!tags ? 'Random Image' : tags}`) //@ts-ignore .setDescription(`[Source](https://danbooru.donmai.us/posts/${response.data[randomInt].id})`) //@ts-ignore .setImage(response.data[randomInt].file_url) .setTimestamp() //@ts-ignore .setFooter(`Score: ${response.data[randomInt].score} | Rating: ${getRating(response.data[randomInt].rating)}`, msg.author.avatarURL()); return msg.channel.send(embed); } }