summaryrefslogtreecommitdiff
path: root/app.js
blob: 216926a36e6ede6b146612c2fca1672d9f6a7dd2 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
const Discord = require('discord.js');
const config = require('./config.json');
const bot = new Discord.Client();
const isImageUrl = require('is-image-url');
const emoji = require('emoji-random');
const atquotes = require('at-quotes');
const ytdl = require('ytdl-core');

bot.on('ready', () => { 
    console.log(`Started bot: ${bot.user.tag} (ID: ${bot.user.id})\nCurrently running on ${bot.guilds.size} server(s).`);
    bot.user.setActivity('with squeaky toy :D', {
        type: 'PLAYING'
    });
});

bot.on('error', console.error);

// Start Bot Commands
bot.on('message', async msg => {
    //if (msg.channel.name === 'bots' || msg.channel.name === 'bot-commands' || msg.member.hasPermission('KICK_MEMBERS')) {
        const upTime = require('moment');
        require('moment-duration-format');
        const duration = upTime.duration(bot.uptime).format(" D [days], H [hrs], m [mins], s [secs]");

        var msgContent = msg.content.toLowerCase();
        if (prefixCheck()) {
            console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name);
        }
 
        // Check prefixies in config.json
        function prefixCheck() {
            if (msgContent.startsWith(config.prefixes.main)) {
                return "main";
            } else if (msgContent.startsWith(config.prefixes.alt)) {
                return "alt1";
            } else if (msgContent.startsWith(config.prefixes.alt2)) {
                return "alt2";
            } else if (msgContent.startsWith(config.prefixes.alt3)) {
                return "alt3";
            } else if (msgContent.startsWith(config.prefixes.alt4)) {
                return "alt4";
            } else if (msgContent.startsWith(config.prefixes.alt5)) {
                return "alt5";
            } else if (msgContent.startsWith(config.prefixes.alt6)) {
                return "alt6";
            } else if (msgContent.startsWith(config.prefixes.alt6b)) {
                return "alt6b";
            } 
        }
 
        if (prefixCheck() == "main") { 
            var args = msg.content.slice(config.prefixes.main.length).split(/ +/);
            var command = args.shift().toLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.main)) return; 
        } else if (prefixCheck() == "alt1") { 
            var args = msg.content.slice(config.prefixes.alt.length).split(/ +/);
            var command = args.shift().toLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt)) return; 
        } else if (prefixCheck() == "alt2") { 
            var args = msg.content.slice(config.prefixes.alt2.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt2)) return; 
        } else if (prefixCheck() == "alt3") { 
            var args = msg.content.slice(config.prefixes.alt3.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt3)) return; 
        } else if (prefixCheck() == "alt4") { 
            var args = msg.content.slice(config.prefixes.alt4.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt4)) return; 
        } else if (prefixCheck() == "alt5") {
            var args = msg.content.slice(config.prefixes.alt4.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt4)) return;
        } else if (prefixCheck() == "alt6") {
            var args = msg.content.slice(config.prefixes.alt4.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt4)) return;
        } else if (prefixCheck() == "alt6b") { 
            var args = msg.content.slice(config.prefixes.alt4b.length).split(/ +/);
            var command = args.shift().toLocaleLowerCase();

            if (msg.author.bot || !msg.content.startsWith(config.prefixes.alt4b)) return; 
        }

        // Returns ping of bot
        if (command == 'ping' || command == 'ms') { 
            const t = Date.now();

            msg.channel.send('plz wait..').then(m => {
                m.edit(`** **`);

                const n = Date.now();
                let emb = new Discord.RichEmbed()

                .setDescription(`pong! chesters's  is \`${n - t}ms\`. heartbeat \`${bot.ping}ms\`.`)
                .setColor(0xFFE4BA);

                msg.channel.send(RichEmbed = emb);
            });
        }

        function noArgs() {
            msg.channel.send(`invalid argument(s). type \`${config.prefixes.main}help\` for more information.`);
        }

        function noCommand() {
            msg.channel.send(`invalid or unspecified command. type \`${config.prefixes.main}help\`.`);
        }

        function perms(p) {
            if (msg.member.hasPermission(p)) return true;
        }

        // Say feature, bot repeats what you say
        if (command == 'say') {
            if (msg.member.hasPermission('KICK_MEMBERS')) {
                m = args.join(' ');
                msg.channel.send(m);
                msg.delete();
            }
        }

        if (command == 'leave') {
            if (msg.guild.voiceConnection) {
                msg.guild.voiceConnection.disconnect();
                msg.reply('succesfully left voice channel');
            } else {
                msg.reply('i\'m not in a voice channel');
            }
        }

        if (command == 'join') {
            if (!msg.guild.voiceConnection && msg.member.voiceChannel) {
                msg.member.voiceChannel.join();
                msg.reply('succesfully joined voice channel');
            } else if (msg.guild.voiceConnection) {
                msg.reply('i\'m already in voice channel');
            } else if (!msg.member.voiceChannel) {
                msg.reply('you\'re not in a voice channel');
            }
        }

        if (command == 'reboot' | command == 'r') {
            msg.member.voiceChannel.join();
            msg.member.voiceChannel.leave();
            msg.reply('reboot finished lol');
        }

        // Clear/ delete messages in bulk command
        if (command == 'clear' || command == 'delete' || command == 'del' || command == 'c') {
            if (msg.member.hasPermission('MANAGE_MESSAGES')) {
                if (!args) {
                    msg.reply('you haven\'t specified an amount of messages which should be deleted.').then(deleteNotificationMessage => {
                        deleteNotificationMessage.delete(1000);
                    });
                } else if (isNaN(args)) {
                    msg.reply('the amount parameter isn\'t a number.').then(deleteNotificationMessage => {
                        deleteNotificationMessage.delete(1000);
                    });
                } else if (args > 100) {
                    msg.reply('you can\'t delete more than 100 messages at once.').then(deleteNotificationMessage => {
                        deleteNotificationMessage.delete(1000);
                    });
                } else if (args < 1) {
                    msg.reply('you have to delete at least 1 message.').then(deleteNotificationMessage => {
                        deleteNotificationMessage.delete(1000);
                    });
                } /*else if (msg.createdTimestamp > 1209600) {
                    msg.reply('due to discord rules, bots can only bulk delete messages that are under 14 days old :(')
                } */
                else {
                    var clearAmount = parseInt(args[0]) + 1;
                    // It took me so long to figure out why this was not really working. It would delete but an insane amount at a time.
                    // I realized that because it was getting parsed as a string, it would just add 1 to it so if I tried to delete 1
                    // message, it would delete 11 lol. Fixed by parsing as integer THEN adding one. 02:30 2020/04/03/2020

                    await msg.channel.fetchMessages({ limit: clearAmount }).then(messages => { // I am on v11 discord.js
                        msg.channel.bulkDelete(messages);
                    });
                    msg.reply('it\'s been deleted ~bork').then(deleteNotificationMessage => {
                        deleteNotificationMessage.delete(1000);
                    });
                }
            } else {
                msg.reply('insufficent perms bruh');
            }
        }

        if (command == 'dm') {
            if (msg.author) { // TODO: fix discord not evaluating args[1]
                if (!msg.mentions.users.first() && !args[1]) {
                    msg.reply('you haven\'t specified a user or a message.');
                } else if (!args[1]) {
                    msg.reply('you haven\'t specified anything to send.');
                } else if (!msg.mentions.users.first()) {
                    msg.reply('you haven\'t specified anyone to send a dm to.');
                } else {
                    var sendTo = msg.mentions.users.first().id;
                    var d = new Date(msg.createdTimestamp);

                    msg.guild.fetchMember(sendTo, false).then(messageUser => {
                        messageUser.send(args[0]);

                        let emb = new Discord.RichEmbed()

                        //.setDescription(`to view the commands in each group use:\n\`s5n!commands <group>\``)
                        .addField(`message`, args[1], true)
                        .addField(`recipient`, args[0], true)
                        .addField(`time sent`, d)
                        .setColor(0xFFE4BA);

                        msg.channel.send(RichEmbed = emb);
                    });
                }
            } else {
                msg.reply('insufficent perms bruh');
            }
        }

        if (msg.mentions.everyone) {
            msg.react(':ArisaPing:695887537390223402');
        }

        if (msg.content == 'dog' | msg.content == 'dogs' | msg.content == 'bark' | msg.content == 'bork' | msg.content == 'woof') {
            var borkNum = Math.floor((Math.random() * 3) + 1);

            if (borkNum == 1) {
                msg.reply('bork');
            } else if (borkNum == 2) {
                msg.reply('bark');
            } else if (borkNum == 3) {
                msg.reply('woof');
            }
        }

        if (command == 'owner') {
            msg.reply('my owner is papa frozen');
        }

        if (command == 'uptime' || command == 'ut') {
            msg.reply(duration);
        }
    //} else if (msg.channel.name !== 'bots' && msg.content.startsWith(`${config.prefixes.main}`) && !msg.member.hasPermission('KICK_MEMBERS')) return; 
})

// Get bot token
bot.login(config['secret'])