summaryrefslogtreecommitdiff
path: root/src/commands/zerotwo/darling.ts
blob: 2f52ed48ce89aaba35065f943b4cb351dea31050 (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
import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando';
//@ts-ignore no @types
import emoji from 'emoji-random';
import Darling from '../../models/darling.js';
import mongo from 'mongoose';
import config from '../../config.json';
mongo.connect(config['mongodburi'], { useNewUrlParser: true, useUnifiedTopology: true })

module.exports = class DarlingZeroTwo extends Command {
    constructor(client: CommandoClient) {
        super(client, {
            name: 'darling',
            group: 'zerotwo',
            memberName: 'darling',
            description: 'Allows you to set, change or delete uwufier\'s darling.',
            userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            examples: [
                'uwu!darling',
                'uwu!darling set',
                'uwu!darling remove'
            ],
            args: [
                {
                    key: 'darlingName',
                    prompt: 'Who should the darling be?',
                    type: 'string',
                    default: ''
                }
            ],
            throttling: {
                usages: 5,
                duration: 30
            },
            guildOnly: true
        });
    }
    //TODO: this
    //@ts-ignore this is not asnc
    async run(msg: CommandoMessage, { darlingName }: any) { // this is actually a string
        const darling = new Darling({
            _id: mongo.Types.ObjectId(),
            username: msg.author.username,
            userID: msg.author.id,
            guildname: msg.guild.name,
            guildID: msg.guild.id,
            time: msg.createdAt
        })
        // const guildExist = await Darling.findOne({ guildID: msg.guild.id })

        Darling.findOne({ guildID: msg.guild.id }, async (error, guild) => {
            if (error) {
                return console.log(error)
            } else if (guild && darlingName == 'remove') {
                // @ts-ignore linting error shows that channelID doesnt exist when it does
                if (msg.author.id == guild.userID || msg.author.id == msg.guild.owner.id) {
                    await Darling.findOneAndDelete({ guildID: msg.guild.id })
                    return msg.say('The current darling has been removed. ' + emoji.random())
                } else {
                    return msg.reply('Only my darling or the guild owner can remove the current darling. ' + emoji.random())
                }
            } else if (!guild && darlingName == 'remove') {
                return msg.reply('There is no darling set in this server. ' + emoji.random())
            } else if (guild && darlingName == 'set') {
                // @ts-ignore linting error shows that channelID doesnt exist when it does
                return msg.reply(`I already have a darling! It\'s <@${guild.userID}>! To set a new darling, either the current darling or the guild owner has to do \`uwu!darling remove\`. ` + emoji.random())
            } else if (!guild && darlingName == 'set') {
                await darling.save()
                .then(result => console.log(result))
                .catch(err => console.log(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!'
                ]
                let quoteNum = quotes[Math.floor(Math.random() * quotes.length)]
                return msg.reply(quoteNum)
            } else if (!guild) {
                return msg.reply('I haven\'t found my darling yet! To set one, do `uwu!darling set`. ' + emoji.random())
            } else if (guild) {
                // @ts-ignore linting error shows that channelID doesnt exist when it does
                return msg.reply(`My darling is <@${guild.userID}>. ` + emoji.random())
            }
        })

        // if (guildExist && darlingName == 'remove') {
        //     await Darling.findOneAndDelete({ guildID: msg.guild.id })
        //     msg.say('The current darling has been removed.')
        // } else if (!guildExist && darlingName == 'remove') {
        //     msg.reply('There is no darling set in this server.')
        // } else if (darlingName || darlingName == 'set') {
        //     await darling.save().then(result => console.log(result)).catch(err => console.log(err))

        //     var quoteNum = Math.floor((Math.random() * 3) + 1);
        //     switch (quoteNum) {
        //         case 1: var quoteResult = 'I think I have taken a liking to you. Won\'t you be my darling?'; break
        //         case 2: var quoteResult = 'I like the look in your eyes. It makes my heart race. You are now my darling!'; break
        //         case 3: var quoteResult = 'Wow, your taste makes my heart race. It bites and lingers... The taste of danger. You are now my darling!'; break
        //         default: var quoteResult = 'I think I have taken a liking to you. Won\'t you be my darling?'; break
        //     }
        //     msg.reply(quoteResult)
        // } else if (!guildExist) {
        //     msg.reply('I haven\'t found my darling yet!')
        // } else if (guildExist) {
        //     await Darling.findOne({ userID: msg.author.id }, (err) => {
        //         if (err) console.log(err)
        //     }).then(res => {
        //         msg.reply(`My darling is <@${res.userID}>`)
        //     })
        //     //msg.reply(`My darling is <@${result.userID}>`)
        // } else {
        //     console.error()
        // }
    }
};