aboutsummaryrefslogtreecommitdiff
path: root/src/bot_discord.js
blob: f1818c26a5f70ac44d5cedd8c424ef1ea9de63b2 (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
/*********************************************
 *
 *	AleeBot for Discord servers
 *	Copyright (C) 2017 AleeCorp
 *	License: MIT
 *
 **********************************************/
const Discord = require('discord.js');
const client = new Discord.Client();
const abVersion = "2.0.0 Beta";
const prefix = "abb:";
const fs = require("fs");
const config = require('./absettings.json');
console.log(`Welcome to AleeBot NodeJS Terminal!`);

client.commands = new Discord.Collection();

fs.readdir(`./commands/`, (err, files) => {
    if(err) console.log(err);

    var jsfiles = files.filter(f => f.split('.').pop() === 'js');
    if(jsfiles.length <= 0) { return console.log('[X] No commands found...')}
    else { console.log('[i] ' + jsfiles.length + ' commands found.') }

    jsfiles.forEach((f, i) => {
        var cmds = require(`./commands/${f}`);
        console.log(`[i] Command ${f} loading...`);
        client.commands.set(cmds.config.command, cmds);
    })
})


client.on('ready', () => {
    console.log("[>] AleeBot is now ready!")
    console.log("[i] Running version " + abVersion + ` and in ${client.guilds.size} guilds`)
    client.user.setPresence({
        game: {
            name: 'AleeBot '+ abVersion + ' | ' + config.prefix +'help',
            type: 0
        }
    });
    client.user.setStatus('online')
});

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

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

});


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

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

});
/*
client.on('guildMemberAdd', member => {
    member.guild.channels.find("name", "welcomes-and-byes").sendMessage(member.toString() + " has joined the server");
});

client.on('guildMemberRemove', member => {
    member.guild.channels.find("name", "welcomes-and-byes").sendMessage(`**${member.user.username}** has left the server`);
}); */


client.on("message", function(message) {
    if (message.author.bot) return;
    if (message.channel.type === "dm") return;
    if (message.content.indexOf(config.prefix) !== 0) return;
    var msg = message.content;
    var cont = message.content.slice(prefix.length).split(" ");
    var args = cont.slice(1);


    if (!message.content.startsWith(prefix)) return;

    var cmd = bot.commands.get(cont[0])
    if (cmd) cmd.run(bot, message, args);

/*
    if (command === 'help') {
        var embed = new Discord.RichEmbed()
            .setAuthor('AleeBot ' + abVersion + ` Help and on ${client.guilds.size} servers`, "https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048")
            .setDescription("Every command you input into AleeBot is `" + config.prefix + "`")
            .addField("- General Commands", "ping\nuptime\ngit", true)
            .setFooter("AleeCorp Copyright 2017")
            .setColor("#1fd619")
        message.channel.sendEmbed(embed);
    }

    if (command === 'ping') {
        message.reply("**PONG!** :ping_pong: " + Math.round(client.ping) + " ms");
    }

    if (command === 'uptime') {
        var uptime = parseInt(client.uptime);
			uptime = Math.floor(uptime / 1000);
			var uptimeMinutes = Math.floor(uptime / 60);
			var minutes = uptime % 60;
			var hours = 0;
			while (uptimeMinutes >= 60) {
				hours++;
				uptimeMinutes = uptimeMinutes - 60;
			}
			var uptimeSeconds = minutes % 60;
        message.channel.send(":clock3: AleeBot has been up for " + hours + " hours, " + uptimeMinutes + " minutes, and " + uptimeSeconds + " seconds.")
    }

    if (command === 'git') {
        message.author.send("I can see you want to contribute to this project.\nHere's the link: https://github.com/AleeCorp/AleeBot")
    }
    */
});
client.login(config.abtoken).catch(function() {
    console.log("[X] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.");
});