summaryrefslogtreecommitdiff
path: root/server/src/commands/anime/Darling.ts
blob: 286255b0c82344c87f2369dcf7382e4e9f204a9e (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
import { Command } from 'discord-akairo';
import { Message } from 'discord.js';
import Darling from '../../database/models/DarlingModel';
import mongoose from 'mongoose';
import { mongoDBUri } from '../../Config';
mongoose.connect(mongoDBUri, {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

export default class DarlingAnime extends Command {
    public constructor() {
        super('darling', {
            aliases: ['darling'],
            category: 'anime',
            description: {
                content: 'Allows you to set, check or delete the/ a server\'s darling.',
                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 current darling?',
                        retries: 3,
                        retry: 'Sorry, that was not a valid type.'
                    }
                }
            ],
            userPermissions: ['MANAGE_GUILD']
        });
    }
    
    public exec(msg: Message, { type }): Promise<Message> | any  {
        const darling = new Darling({
            _id: mongoose.Types.ObjectId(),
            username: msg.author.username,
            userID: msg.author.id,
            guildname: msg.guild.name,
            guildID: msg.guild.id,
            channelname: msg.channel,
            channelID: msg.channel.id,
            time: msg.createdAt
        });
        
        return Darling.findOne({ guildID: msg.guild.id }, async (error, guild) => {
            if (error) return console.error(error);
            
            if (guild) {
                if (type === 'remove') {
                    //@ts-ignore
                    if (msg.author.id !== guild.userID || msg.author.id !== msg.guild.owner.id)
                        return msg.reply('Only my darling or the guild owner can remove the current darling.');

                    await Darling.findOneAndDelete({ guildID: msg.guild.id });
                    return msg.channel.send('The current darling has been removed!');
                } else if (type === 'set') {
                    //@ts-ignore
                    return msg.channel.send(`I already have a darling! It's **${guild.username}**! To set a new darling, either the current darling or the guild owner has to do \`${this.client.commandHandler.prefix}darling remove\`.`);
                } else if (type === 'check') {
                    //@ts-ignore
                    return msg.channel.send(`My darling is **${msg.guild.members.resolve(guild.userID).user.tag}**.`);
                }
            } else if (!guild) {
                if (type === 'remove') {
                    return msg.channel.send('There is no darling set in this server.');
                } else if (type === 'set') {
                    await darling.save().catch(err => console.error(err));
                    const quotes = [
                        'I think I have taken a liking to you. Won\'t you be my darling?',
                        'I like the look in your eyes. It makes my heart race. You are now my darling!',
                        'Wow, your taste makes my heart race. It bites and lingers... The taste of danger. You are now my darling!'
                    ];
                    return msg.channel.send(quotes[Math.floor(Math.random() * quotes.length)]);
                } else if (type === 'check') {
                    return msg.reply(`I haven't found my darling yet! To set one, do ${this.client.commandHandler.prefix}darling set.`);
                }
            }
        });
    }
}