summaryrefslogtreecommitdiff
path: root/src/commands/nsfw/rule34.ts
blob: 568b07ab01fe310754af191d8d5578187c4bf02e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando';
import { MessageEmbed } from 'discord.js';
import axios from 'axios'

export default class Rule34NSFW extends Command {
    constructor(client: CommandoClient) {
        super(client, {
            name: 'rule34',
            aliases: ['r34'],
            group: 'nsfw',
            memberName: 'rule34',
            description: 'Rule34.',
            throttling: {
                usages: 5,
                duration: 30
            },
            examples: [
                'uwu!rule34',
                'uwu!rule34 minecraft'
            ],
            userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            args: [
                {
                    key: 'tTags',
                    prompt: 'What tag(s) would you like?',
                    type: 'string',
                    default: ''
                }
            ],
            nsfw: true
        });
    }
    async run(msg: CommandoMessage, { tTags }: any) {
        const tags = await tTags.trim()
        const blacklist = ['loli', 'shota', 'cub', 'young', 'child', 'baby', 'guro', 'gore', 'vore', 'scat', 'poop', 'kid', 'shit', 'turd', 'feces', 'excrement', 'excrete'];

        if (tags) {
            if (blacklist.includes(tags.toLowerCase())) {
                return msg.reply('Blacklisted word was used! ⛔')
            }
        }
        
        const res = 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.log(error))

        //@ts-ignore yes data exists
        const randomInt = Math.floor(Math.random() * res.data.length)

        //@ts-ignore yes data exists
        if (blacklist.includes(res.data[randomInt].tags.toLowerCase())) {
            return msg.reply('Sorry! This image had a tag that was blacklisted! ⛔')
        }

        let emb = new MessageEmbed()
            .setColor(0xFFCC4D)
            .setTitle(`Rule34 - ${!tags ? 'Random Image' : tags}`)
            //@ts-ignore yes data exists
            .setDescription(`[Source](https://rule34.xxx/index.php?page=post&s=view&id=${res.data[randomInt].id})\n\nFixed bug where responses were being evaluated out of 100 instead of data length!`)
            //@ts-ignore yes data exists
            .setImage(`https://rule34.xxx/images/${res.data[randomInt].directory}/${res.data[randomInt].image}`)
            .setTimestamp(new Date())
            //@ts-ignore yes data exists
            .setFooter(`Score: ${res.data[randomInt].score} | Rating: ${res.data[randomInt].rating}`, msg.author.avatarURL())
        return msg.say(emb);
    }
}