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
68
69
70
71
72
73
74
75
76
77
78
|
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<Message> {
//@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);
}
}
|