aboutsummaryrefslogtreecommitdiff
path: root/aleebot.js
blob: af5990effa465e07cbd1b98000a47f77032e4445 (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
/****************************************
 *
 *   AleeBot 1.1.1 for AleeArmy Community and other servers
 *   Copyright (C) 2017 AleeCorp
 *
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 *   of this software and associated documentation files (the "Software"), to deal
 *   in the Software without restriction, including without limitation the rights
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *   copies of the Software, and to permit persons to whom the Software is
 *   furnished to do so, subject to the following conditions:
 *
 *   The above copyright notice and this permission notice shall be included in all
 *   copies or substantial portions of the Software.
 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *   SOFTWARE.
 *
 *
 **************************************/
const Discord = require('discord.js');
const moment = require('moment');
const blessed = require('blessed');
const fs = require('fs');
const client = new Discord.Client();
const config = require('./absettings.json');
const abversion = "1.1.1";
const log = message => {

    console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);

};

client.commands = new Discord.Collection();

client.aliases = new Discord.Collection();
fs.readdir('./commands/', (err, files) => {
    if (err) console.error(err);
    log(`Loading a total of ${files.length} commands.`);
    files.forEach(f => {
        let props = require(`./commands/${f}`);
        log(`Loading Command: ${props.help.name}. Done!`);
        client.commands.set(props.help.name, props);
        props.conf.aliases.forEach(alias => {
            client.aliases.set(alias, props.help.name);
        });
    });
});


client.on('ready', () => {
    log("[>] AleeBot is now ready! Running version " + abversion + "!");
    client.user.setPresence({
        game: {
            name: 'with version ' + abversion + '',
            type: 0
        }
    });
    client.user.setStatus('online')
});


client.on("guildCreate", guild => {

    // This event triggers when the bot joins a guild.

    log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);


    guild.defaultChannel.sendMessage(":wave: Hello I am AleeBot thanks for inviting me to your server for help type `" + config.prefix + "help`.")

});



client.on("guildDelete", guild => {

    // this event triggers when the bot is removed from a guild.

    log(`I have been removed from: ${guild.name} (id: ${guild.id})`);


});


client.on("message", function(message) {
    if (message.author.bot) return;
    if (message.channel.type === "dm") return;
    if (message.content.indexOf(config.prefix) !== 0) return;

    const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    try {
        let commandFile = require(`./commands/${command}.js`);
        commandFile.run(client, message, args, config, abversion);
    } catch (err) {
        message.reply(`:no_entry_sign: Error!\nThe command ${command} isn't found. (Reported to console.)`)
        console.error(err);
    }


});

process.on('unhandledRejection', function(err, p) {
    log("[X | UNCAUGHT PROMISE] " + err.stack);
});

client.login(config.abtoken).catch(function() {
    log("[X] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.");
});