summaryrefslogtreecommitdiff
path: root/src/bot.ts
blob: f5e09ab8b90f867f5fc6a1258341b942dc8dedf8 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import config from './config.json';
import { CommandoClient } from 'discord.js-commando';
// @ts-ignore no default import
import WS  from './server';
import Welcome from './models/welcome.js';
import Goodbye from './models/goodbye.js';
import mongoose from 'mongoose';
mongoose.connect('mongodb://sin:[email protected]:47107/heroku_4qrjvmb9', { useNewUrlParser: true, useUnifiedTopology: true })
import path from 'path';
// @ts-ignore emoji-random doesnt have types
import emoji from 'emoji-random';
import { MessageEmbed } from 'discord.js';
require('./models/MusicGuild.js')

const client = new CommandoClient({
    commandPrefix: 'uwu!',
    owner: '217348698294714370',
    invite: 'https://discord.gg/DVwXUwx'
});

const ws = new WS(process.env.PORT, client)

client.registry
    .registerDefaultTypes()
    .registerGroups([
        ['fun', 'Fun Command Group'],
        ['moderation', 'Moderation Command Group'],
        ['server', 'Server Command Group'],
        ['voice', 'Voice Command Group'],
        ['nsfw', 'NSFW Command Group'],
        ['anime', 'Anime Command Group'],
        ['crypto', 'Crypto Command Group'],
        ['zerotwo', 'Zero Two Command Group'],
        ['bot', 'Bot Command Group'],
        ['user', 'User Command Group'],
        ['utility', 'Utility Command Group'],
        ['minecraft', 'Minecraft Command Group'],
        ['animals', 'Animal Command Group'],
        ['roleplay', 'Roleplay Command Group']
    ])
    .registerDefaultGroups()
    .registerDefaultCommands({
        help: true,
        //eval: false
    })
    .registerCommandsIn(path.join(__dirname, 'commands'));

client.once('ready', async () => { 
    //console.log(`Started bot: ${client.user.tag} (ID: ${client.user.id})\nCurrently running on ${client.guilds.cache.size} server(s).`);
    console.log('\x1b[0m' + 'Bot online!')
    console.log('\x1b[31m' + ` _   _                 __ _           
| | | |               / _(_)          
| | | |_      ___   _| |_ _  ___ _ __ 
| | | \\ \\ /\\ / / | | |  _| |/ _ \\ '__|
| |_| |\\ V  V /| |_| | | | |  __/ |   
 \\___/  \\_/\\_/  \\__,_|_| |_|\\___|_|   
                                      
                                      `)
    console.log('\x1b[0m' + 'discord.js Version: ' + '\x1b[36m' + '2.11')
    console.log('\x1b[0m' + 'Node.js Version: ' + '\x1b[36m' + process.version)
    console.log('\x1b[0m' + 'OS Version: ' + '\x1b[36m' + process.platform)
    console.log('\x1b[0m' + 'Name: ' + '\x1b[36m' + `${client.user?.tag}`)
    console.log('\x1b[0m' + 'ID: ' + '\x1b[36m' + `${client.user?.id}`)
    console.log('\x1b[0m' + 'Servers: ' + '\x1b[36m' + `${client.guilds.cache.size}` + '\x1b[0m')
    console.log()
    
    // i would use a set interval in the main msg body but this is better for now because during maintenance you tend to refresh refresh a lot
    // kinda crap if you forget to change uppity's status off of maintainence... 2020/05/05, 17:29
    if ((await client.users.fetch('705537104339402815')).presence.activities[0].name == 'maintenance') {
        client.user?.setActivity('uwu!help | Maintenance', {
            type: 'WATCHING'
        });
    } else {
        client.user?.setActivity('uwu!help | v' + config['version'], {
            type: 'WATCHING'
        });
    }
});

client.on('error', console.error);
//client.on('debug', console.debug);
client.on('warn', console.warn)

client.on('guildCreate', guild => {
    console.log(`Joined server: ${guild.name}`)
    let embed = new MessageEmbed()
        .setDescription(`Hi! Thank you for inviting uwufier to your server! To view the complete list of commands, do \`uwu!help\`. If you want to contact the lead developer for possible suggestions or to report a bug, please join the [support server](https://discord.com/invite/DVwXUwx). You can also do \`uwu!suggest<thing>\`. If you like the bot, please support the bot on our [top.gg page](https://top.gg/bot/699473263998271489/vote) or our [DBL page](https://discordbotlist.com/bots/699473263998271489/upvote)! ${emoji.random()}`)
    guild.owner?.send(embed)
    //@ts-ignore
    client.guilds.cache.get('704032355987488791')?.channels.cache.get('706818034999754792')?.send(`Joined server: **${guild.name}**.`)
})
client.on('guildDelete', guild => {
    console.log(`Left server: ${guild.name}`)
    //@ts-ignore
    client.guilds.cache.get('704032355987488791')?.channels.cache.get('706818034999754792')?.send(`Joined server: **${guild.name}**.`)
})

client.on('guildMemberAdd', member => {
    Welcome.findOne({ guildID: member.guild.id }, async (error, guild) => {
        if (error) {
            console.log(error)
        } else if (!guild) {
            return
        } else if (guild) {
            // @ts-ignore linting error shows that channelID doesnt exist when it does
            member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has joined **${member.guild.name}** the server! ` + emoji.random())
        } else {
            return
        }
    })
})
client.on('guildMemberRemove', member => {
    Goodbye.findOne({ guildID: member.guild.id }, async (error, guild) => {
        if (error) {
            console.log(error)
        } else if (!guild) {
            return
        } else if (guild) {
            // @ts-ignore linting error shows that channelID doesnt exist when it does
            member.guild.channels.cache.get(guild.channelID)?.send(`<@${member.id}> has left **${member.guild.name}** the server! ` + emoji.random())
        } else {
            return
        }
    })
})

client.on('message', async msg => {
    var msgContent = msg.content.toLowerCase();
    function prefixCheck() {
        if (msgContent.startsWith('uwu!')) {
            return true;
        }
    }
    if (prefixCheck()) {
        if (msg.channel.type == 'dm') {
            console.log(msg.author.tag, 'says', msgContent, 'in a DM');
            //@ts-ignore
            client.guilds.cache.get('704032355987488791')?.channels.cache.get('706818034999754792')?.send(`**${msg.author.tag}** says **${msgContent}** in a **DM.**`)
        } else {
            console.log(msg.member?.user.tag, 'says', msgContent, 'in #' + msg.channel.name + ' in ' + msg.guild?.name);
            //@ts-ignore
            client.guilds.cache.get('704032355987488791')?.channels.cache.get('706818034999754792')?.send(`**${msg.author.tag}** says **${msgContent}** in **#${msg.channel.name}** in **${msg.guild?.name}**.`)
        }
    }
    
    if (msg.mentions.everyone) {
        msg.react(emoji.random());
    }
});

client.login(config['secret']);