AleeBot/bot_discord.js

167 lines
4.9 KiB
JavaScript
Raw Normal View History

2018-03-31 13:32:44 -04:00
/****************************************
*
2018-03-31 13:32:44 -04:00
* AleeBot: Made for discord servers
* Copyright (C) 2018 AleeCorp
2018-01-26 17:38:08 -05:00
*
2018-03-31 13:32:44 -04:00
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
2018-01-26 17:38:08 -05:00
*
2018-03-31 13:32:44 -04:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2018-03-31 13:32:44 -04:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
2018-01-26 17:38:08 -05:00
const Discord = require('discord.js');
2018-03-25 15:56:46 -04:00
const economy = require('discord-eco');
2018-04-01 16:29:56 -04:00
const moment = require('moment');
2018-04-15 15:46:01 -04:00
const client = new Discord.Client({
disableEveryone: true
});
2018-04-16 10:49:36 -04:00
const abVersion = '2.8.0';
const prefix = 'ab:';
const fs = require('fs');
2018-01-26 17:38:08 -05:00
const config = require('./absettings.json');
2018-04-01 10:13:24 -04:00
2018-04-01 16:29:56 -04:00
const log = message => {
console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);
};
console.log('AleeBot: Copyright (C) 2018 AleeCorp');
console.log('This program comes with ABSOLUTELY NO WARRANTY; for details type `show w\'.');
2018-04-01 10:13:24 -04:00
console.log ('This is free software, and you are welcome to redistribute it');
console.log ('under certain conditions; type `show c\' for details.\n')
2018-01-26 17:38:08 -05:00
2018-04-15 10:09:31 -04:00
if (process.argv.indexOf("--debug") == -1) {
2018-04-15 11:13:06 -04:00
console.log("Running AleeBot without --debug command line flag. Debug output disabled.\n");
2018-04-15 10:09:31 -04:00
} else {
console.log('[!] Entering debug mode...')
client.on('debug', function(info) {
log(info);
});
client.on('warn', function(info) {
log(info);
});
}
2018-01-26 17:38:08 -05:00
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir('./commands', (err, files) => {
if (err) console.error(err);
2018-04-01 16:29:56 -04:00
log(`[!] Attempting to load a total of ${files.length} commands into the memory.`);
files.forEach(file => {
try {
const command = require(`./commands/${file}`);
2018-04-01 16:29:56 -04:00
log(`[!] Attempting to load the command "${command.help.name}".`);
client.commands.set(command.help.name, command);
command.conf.aliases.forEach(alias => {
client.aliases.set(alias, command.help.name);
2018-04-01 16:29:56 -04:00
log(`[!] Attempting to load "${alias}" as an alias for "${command.help.name}"`);
});
}
catch (err) {
2018-04-01 16:51:25 -04:00
log('[X] An error has occured trying to load a command. Here is the error.');
console.log(err.stack);
}
});
2018-04-01 16:29:56 -04:00
log('[>] Command Loading complete!');
console.log('\n');
});
2018-01-26 17:38:08 -05:00
client.on('ready', () => {
2018-04-01 16:29:56 -04:00
log('[>] AleeBot is now ready!');
2018-04-16 11:17:29 -04:00
log(`[i] Logged in as ${client.user.tag}`);
log(`[i] Bot ID: ${client.user.id}`);
log(`[i] Token: ${config.abtoken}`);
2018-04-01 16:29:56 -04:00
log('[i] Running version ' + abVersion + ` and in ${client.guilds.size} guilds`);
2018-03-29 15:42:24 -04:00
client.setInterval(function() {
const games = [
'AleeBot ' + abVersion + ' | ' + config.prefix + 'help',
'Annoying Alee',
'Coding stuff',
'Drawing shapes',
'Fighting AstralMod',
];
client.user.setPresence({
status: 'online',
afk: false,
game: {
type: 0,
name: games[Math.floor(Math.random() * games.length)],
},
});
}, 200000);
client.user.setStatus('online');
2018-01-26 17:38:08 -05:00
});
client.on('guildCreate', guild => {
2018-01-26 17:38:08 -05:00
2018-04-01 16:29:56 -04:00
log(`[i] New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
2018-01-26 17:38:08 -05:00
});
client.on('guildDelete', guild => {
2018-01-26 17:38:08 -05:00
2018-04-01 16:29:56 -04:00
log(`[i] I have been removed from: ${guild.name} (id: ${guild.id})`);
2018-01-26 17:38:08 -05:00
});
client.on('message', (msg) => {
2018-03-29 15:35:59 -04:00
if (msg.author.bot) return;
if (!msg.content.startsWith(prefix)) return;
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift();
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
}
if (cmd) {
if (cmd.conf.guildOnly == true) {
if (!msg.channel.guild) {
return msg.channel.createMessage('This command can only be ran in a guild.');
}
}
try {
cmd.run(client, msg, args);
}
catch (e) {
console.error(e);
}
}
2018-01-26 17:38:08 -05:00
});
2018-03-26 16:11:02 -04:00
process.on('unhandledRejection', function(err, p) {
2018-04-01 16:29:56 -04:00
log("[X | UNCAUGHT PROMISE] " + err.stack);
2018-03-26 16:11:02 -04:00
});
process.on('uncaughtException', function (exception) {
log(exception);
});
client.on("error", error => {
log(error);
});
2018-01-26 17:38:08 -05:00
client.login(config.abtoken).catch(function() {
2018-04-01 16:29:56 -04:00
log('[X] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.');
2018-01-26 17:38:08 -05:00
});