diff options
Diffstat (limited to 'server/src/commands/nsfw/Rule34.ts')
| -rw-r--r-- | server/src/commands/nsfw/Rule34.ts | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/server/src/commands/nsfw/Rule34.ts b/server/src/commands/nsfw/Rule34.ts new file mode 100644 index 0000000..bea3af1 --- /dev/null +++ b/server/src/commands/nsfw/Rule34.ts @@ -0,0 +1,68 @@ +import { Command } from 'discord-akairo'; +import { Message } from 'discord.js'; +import Axios from 'axios'; +import { colour } from '../../Config'; + +export default class Rule34NSFW extends Command { + public constructor() { + super('rule34', { + aliases: ['rule34', 'r34'], + category: 'nsfw', + description: { + content: 'If it exists, theres porn of it. If there isn\'t, there will be.', + 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<Message> { + //@ts-ignore + if (!msg.channel.nsfw) return msg.reply('This is not an NSFW marked channel!'); + + const 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(`http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags=${tags}+-rating:safe&json=1`) + .catch(error => { + console.error(error); + return msg.reply('Woops, there was an error regarding the (https://rule34.xxx) 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! ⛔'); + } + + const embed = this.client.util.embed() + .setColor(colour) + .setTitle(`Rule34 - ${!tags ? 'Random Image' : tags}`) + //@ts-ignore + .setDescription(`[Source](https://rule34.xxx/index.php?page=post&s=view&id=${response.data[randomInt].id})`) + //@ts-ignore + .setImage(`https://rule34.xxx/images/${response.data[randomInt].directory}/${response.data[randomInt].image}`) + .setTimestamp() + //@ts-ignore + .setFooter(`Score: ${response.data[randomInt].score} | Rating: ${getRating(response.data[randomInt].rating)}`, msg.author.avatarURL()); + return msg.channel.send(embed); + } +}
\ No newline at end of file |