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

module.exports = class VerifyEmma extends Command {
    constructor(client: CommandoClient) {
        super(client, {
            name: 'verify',
            group: 'emma',
            memberName: 'verify',
            description: 'Lists all the roles on the current server.',
            examples: ['uwu!verify set', 'uwu!verify remove'],
            throttling: {
                usages: 5,
                duration: 30
            },
            userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            guildOnly: true,
            args: [
                {
                    key: 'code',
                    prompt: 'What is the verification code?',
                    type: 'string'
                }
            ]
        });
    }
    //@ts-ignore this ok
    async run(msg: CommandoMessage, { code }: any) {
        if (msg.guild.id == '704032355987488791') return msg.reply(`You are not submitting from **Kat\'s Korner**! ${emoji.random()}`);
            Verify.findOne({ userID: msg.author.id }, async (error, member) => {
                if (error) return console.error(error)
                //@ts-ignore this exists
                if (msg.author.id == member.userID) {
                    //@ts-ignore this in-fact
                    if (code == member.key) {
                        await Verify.findOneAndDelete({ userID: msg.author.id });
                        const unverRole = '729928740359897101';
                        return msg.guild.member(msg.author.id)?.roles.remove(unverRole);
                    } else {
                        //@ts-ignore this exists
                        return msg.author.send(`That is not the correct key! Please try again with the correct key: \`${member.key}\`. ${emoji.random()}`);
                    }
                } else {
                    return msg.author.send(`You are already verified! ${emoji.random()}`)
                }
            })
    }
};