summaryrefslogtreecommitdiff
path: root/src/commands/server/welcome.ts
blob: 08a291112ea14f09ac81afc88e74489c9c66924c (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
import { Command, CommandoMessage } from 'discord.js-commando';
import emoji from 'emoji-random';
import Welcome from '../../models/welcome.js';
import mongo from 'mongoose';
mongo.connect('mongodb://sin:[email protected]:47107/heroku_4qrjvmb9', { useNewUrlParser: true, useUnifiedTopology: true })

module.exports = class WelcomeServer extends Command {
    constructor(client) {
        super(client, {
            name: 'welcome',
            group: 'server',
            memberName: 'welcome',
            description: 'Allows you to set, change or delete a server welcome message.',
            userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'],
            examples: [
                'uwu!welcome',
                'uwu!welcome set',
                'uwu!welcome remove'
            ],
            args: [
                {
                    key: 'wType',
                    prompt: 'Would you like to set, remove or change the current welcome channel?',
                    type: 'string',
                    default: ''
                }
            ],
            throttling: {
                usages: 5,
                duration: 30
            },
            guildOnly: true
        });
    }
    async run(msg: CommandoMessage, { wType }) {
        const welcome = new Welcome({
            _id: mongo.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
        })
        const guildExist = await Welcome.findOne({ guildID: msg.guild.id })

        if (msg.member.hasPermission('MANAGE_GUILD')) {
            Welcome.findOne({ guildID: msg.guild.id }, async (error, guild) => {
                if (error) {
                    console.log(error)
                } else if (guild && wType == 'remove') {
                    await Welcome.findOneAndDelete({ guildID: msg.guild.id })
                    msg.say('The current welcome channel has been unset! ' + emoji.random()).then(mnotif => {
                        mnotif.delete({ timeout: 2000 })
                        msg.delete({ timeout: 2000 })
                    })
                } else if (!guild && wType == 'remove') {
                    msg.reply('There is no current welcome channel set for this guild! ' + emoji.random()).then(mnotif => {
                        mnotif.delete({ timeout: 2000 })
                        msg.delete({ timeout: 2000 })
                    })
                } else if (guild && wType == 'set') {
                    msg.reply(`There already is a welcome channel set! It's ${guild.channelname}! ` + emoji.random()).then(mnotif => {
                        mnotif.delete({ timeout: 2000 })
                        msg.delete({ timeout: 2000 })
                    })
                } else if (!guild && wType == 'set') {
                    await welcome.save()
                        .then(result => console.log(result))
                        .catch(err => console.log(err))

                    msg.reply(`The welcome channel has been set to ${msg.channel}! ` + emoji.random()).then(mnotif => {
                        mnotif.delete({ timeout: 2000 })
                        msg.delete({ timeout: 2000 })
                    })
                } else if (!guild) {
                    msg.reply('There is no current welcome channel set for this guild! To set one, do `uwu!welcome set` in the channel you want to set it in. ' + emoji.random())
                } else if (guild) {
                    msg.reply(`The current welcome channel is ${guild.channelname}. ` + emoji.random())
                }
            })
        } else {
            msg.reply('Insufficent permissions! ' + emoji.random())
        }
    }
};