summaryrefslogtreecommitdiff
path: root/app.js
blob: 69f98bf3c2e6721bef0028246aaf7d7708a6c1e0 (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
const fs = require('fs');
const Discord = require('discord.js');
const config = require('./config.json');
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

    bot.commands.set(command.name, command);
}
 
bot.on('ready', () => { 
    console.log(`Started bot: ${bot.user.tag} (ID: ${bot.user.id})\nCurrently running on ${bot.guilds.size} server(s).`); // Startup dialouge in output console
    bot.user.setActivity('psycho~ uwu', { // Set status
        type: 'LISTENING'
    });

    // Outputs available commands in output console
    //commands = ['bot', 'help'];
    //console.log(commands);
});

// Outputs errors in console window
bot.on('error', console.error);

// Start Bot Commands
bot.on('message', async msg => {
    //console.log(msg.content.toLowerCase());
    //if (msg.channel.name === 'bots' || msg.channel.name === 'bot-commands' || msg.member.hasPermission('KICK_MEMBERS')) {
        var msgContent = msg.content.toLowerCase();
        if (prefixCheck()) {
            console.log(msg.member.user.tag, 'says', msgContent, 'in #' + msg.channel.name);
        }
        //console.log(config.prefixes.main);
 
        // 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; 
        }

        // Random edge case arguments
        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;
        }

        // Begin commands
        // if (command == 'ping') {
        //     bot.commands.get('ping').execute(bot, msg);
        // }
        try {
            bot.commands.get(command).execute(msg, args, bot);
            return;
        } catch (error) {
            console.error(error);
        }
    //} 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']);