summaryrefslogtreecommitdiff
path: root/server/src/commands/emma/FanArt.ts
blob: e193ba3e13eaf75a21d3d69ac4c413bf9dd57fdb (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import { colour, emmaServer, prefix } from '../../Config';
import { TextChannel } from 'discord.js';

export default class FanArtEmma extends Command {
    public constructor() {
        super('fanart', {
            aliases: ['fanart', 'art'],
            category: 'emma',
            description: {
                content: 'Allows you to set, check or delete the/ a server fanart channel.',
                usage: '[type]',
                examples: [
                    '',
                    'set',
                    'remove',
                    'check'
                ]
            },
            ratelimit: 3,
            channel: 'guild',
            args: [
                {
                    id: 'type',
                    type: 'string',
                    prompt: {
                        start: 'Would you like to set, check or delete the fanart channel?',
                        retries: 3,
                        retry: 'Sorry, that was not a valid type.'
                    }
                },
                {
                    id: 'comment',
                    type: 'string'
                }
            ],
            userPermissions: ['MANAGE_GUILD']
        });
    }
    
    public async exec(msg: Message, { type, comment }): Promise<Message> {
        if (msg.guild.id.toString() !== emmaServer) return;
        const existing = this.client.settings.cache.guilds.get(msg.guild.id);
        if (!existing) {
            this.client.settings.new('guild', {
                id: msg.guild.id,
                premium: false,
                prefix,
            });
        }
        let hasFanart = true;
		if (existing.fanart === undefined) {
			hasFanart = false;
		} else {
			if (existing.fanart.length !== 18) hasFanart = false;
		}
    
        const validTypes = ['set', 'remove', 'check'];

        if (type === 'submit') {
            if (hasFanart) {
                let fanartServer = emmaServer; 
                let fanartChannel = existing.fanart;
                
                if (msg.attachments.size) {
                    msg.attachments.forEach(fanart => {
                        if (fanart.url) {
                            //@ts-ignore
                            return fanartServer.channels.cache.get(fanartChannel).send(`**New fanart submitted!**\nFanart by <@${msg.author.id}>.\n\n**Comment**\n${comment ? comment : 'None.'}\n\n**Video/ Image** ` + fanart.url)
                                .then(m => {
                                    m.react('😍');
                                    m.react('😂');
                                    m.react('😁');
                                    m.react('😳');
                                    m.react('😱');
                                });
                        } else {
                            return msg.reply(`No attachment was submitted! If you need help, please do \`${this.client.commandHandler.prefix}fanart help\`.`);
                        }
                    });
                } else {
                    return msg.reply(`No attachment was submitted! If you need help, please do \`${this.client.commandHandler.prefix}fanart help\`.`);
                }
            }
        } else if (type === 'help') {
            const embed = this.client.util.embed()
                .setTitle('Fanart - Help')
                .setColor(colour)
                .setDescription('How to submit fanart:')
                .setThumbnail(msg.guild.iconURL())
                .addField('#1', 'Go to the `#media` channel.')
                .addField('#2', 'Click on the add media button in the bottom left corner of your screen and select a video or image.')
                .addField('#3', 'In the message section, please put `uwu!art submit`.')
                .addField('#4 (Optional)', 'If you would like, you can also put a comment on your fanart, you can do this by adding an extra string to the end of your submit command. e.g. `uwu!art submit this is where the comment goes!`, if you followed the steps correctly, your comment should be `this is where the comment goes!')
                .addField('Admin Stuff', `If you are an admin or moderator who would like to set/ remove a fanart channel, you can do this by going to to the channel you would like to set as the new fanart channel and doing \`${this.client.commandHandler.prefix}fanart set\`, this will set the current channel as the fanart channel. To remove a fanart channel, just do \`${this.client.commandHandler.prefix}fanart remove\`.`)
                .addField('More Admin Info', 'You can only have **ONE** fanart channel (I think, I haven\'t tested it lol. If you change the name of the fanart channel, you will have to re-register with the bot by simply removing and re-setting the fanart channel');
            return msg.channel.send(embed);
        } else if (validTypes.includes(type)) {
            if (hasFanart) {
                if (type === 'remove') {
                    await this.client.settings.set('guild', { id: msg.guild.id }, { fanart: '' });
                    return msg.reply('The previous fanart channel has been un-set!');
                } else if (type === 'set') {
                    return msg.channel.send(`There already is a fanart channel set! It's <#${msg.guild.channels.cache.get(existing.fanart).id}>!`);
                } else if (type === 'check') {
                    return msg.channel.send(`The current fanart channel is <#${msg.guild.channels.cache.get(existing.fanart).id}>.`);
                }
            } else if (!hasFanart) {
                if (type === 'remove') {
                    return msg.reply('There is no fanart channel set in this server!');
                } else if (type === 'set') {
                    await this.client.settings.set('guild', { id: msg.guild.id }, { fanart: (msg.channel as TextChannel).id });
                    return msg.reply(`The fanart channel has been set to <#${msg.channel.id}>!`)
                } else if (type === 'check') {
                    return msg.reply(`There is no fanart channel set in this server! To set one, do \`${this.client.commandHandler.prefix}fanart set\`!`);
                }
            }
            
            undefined;
        }
    }
}