2018-03-31 13:32:44 -04:00
|
|
|
/****************************************
|
2018-03-25 11:44:22 -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-25 11:44:22 -04:00
|
|
|
*
|
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-16 15:14:25 -04:00
|
|
|
const DBL = require("dblapi.js");
|
2018-04-15 15:46:01 -04:00
|
|
|
const client = new Discord.Client({
|
|
|
|
disableEveryone: true
|
|
|
|
});
|
2018-04-18 15:28:39 -04:00
|
|
|
const settings = require('./storage/settings.json')
|
2018-02-24 20:19:29 -05:00
|
|
|
const fs = require('fs');
|
2018-04-18 18:47:40 -04:00
|
|
|
const api = require('./tokens.json');
|
|
|
|
const dbl = new DBL(api.dbltoken, client);
|
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}`);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-20 16:58:07 -04:00
|
|
|
console.log(`AleeBot ${settings.abVersion}: Copyright (C) 2018 AleeCorp`);
|
2018-04-01 16:29:56 -04:00
|
|
|
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();
|
2018-02-24 20:19:29 -05:00
|
|
|
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.`);
|
2018-02-24 20:19:29 -05:00
|
|
|
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}".`);
|
2018-02-24 20:19:29 -05:00
|
|
|
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}"`);
|
2018-02-24 20:19:29 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
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-02-24 20:19:29 -05:00
|
|
|
}
|
|
|
|
});
|
2018-04-01 16:29:56 -04:00
|
|
|
log('[>] Command Loading complete!');
|
2018-02-24 20:19:29 -05:00
|
|
|
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}`);
|
2018-04-20 17:23:08 -04:00
|
|
|
log(`[i] Default Prefix: ${settings.prefix}`)
|
2018-04-16 11:17:29 -04:00
|
|
|
log(`[i] Bot ID: ${client.user.id}`);
|
2018-04-18 18:47:40 -04:00
|
|
|
log(`[i] Token: ${api.abtoken}`);
|
2018-04-18 15:28:39 -04:00
|
|
|
log('[i] Running version ' + settings.abVersion + ` and in ${client.guilds.size} guilds`);
|
2018-03-24 23:55:40 -04:00
|
|
|
|
2018-03-29 15:42:24 -04:00
|
|
|
client.setInterval(function() {
|
|
|
|
const games = [
|
2018-04-18 15:35:39 -04:00
|
|
|
'AleeBot ' + settings.abVersion + ' | ' + settings.prefix + 'help',
|
2018-03-29 15:42:24 -04:00
|
|
|
'Annoying Alee',
|
|
|
|
'Coding stuff',
|
|
|
|
'Drawing shapes',
|
|
|
|
'Fighting AstralMod',
|
|
|
|
];
|
2018-04-16 15:14:25 -04:00
|
|
|
setInterval(() => {
|
|
|
|
dbl.postStats(client.guilds.size, client.shards.Id, client.shards.total);
|
|
|
|
}, 1800000);
|
2018-03-29 15:42:24 -04:00
|
|
|
|
|
|
|
client.user.setPresence({
|
|
|
|
status: 'online',
|
|
|
|
afk: false,
|
|
|
|
game: {
|
|
|
|
type: 0,
|
|
|
|
name: games[Math.floor(Math.random() * games.length)],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}, 200000);
|
2018-02-24 20:19:29 -05:00
|
|
|
client.user.setStatus('online');
|
2018-01-26 17:38:08 -05:00
|
|
|
});
|
|
|
|
|
2018-02-24 20:19:29 -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
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-02-24 20:19:29 -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
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-02-24 20:19:29 -05:00
|
|
|
client.on('message', (msg) => {
|
2018-03-29 15:35:59 -04:00
|
|
|
if (msg.author.bot) return;
|
2018-04-20 16:58:07 -04:00
|
|
|
|
|
|
|
let prefixes = JSON.parse(fs.readFileSync("./storage/prefixes.json", "utf8"));
|
|
|
|
|
|
|
|
if(!prefixes[msg.guild.id]){
|
|
|
|
prefixes[msg.guild.id] = {
|
|
|
|
prefixes: settings.prefix
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let prefix = prefixes[msg.guild.id].prefixes
|
2018-04-20 17:23:08 -04:00
|
|
|
|
2018-04-20 16:58:07 -04:00
|
|
|
|
|
|
|
if (!msg.content.startsWith(prefix)) return;
|
|
|
|
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
|
2018-02-24 20:19:29 -05:00
|
|
|
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
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-04-02 18:19:24 -04:00
|
|
|
process.on('uncaughtException', function (exception) {
|
|
|
|
log(exception);
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on("error", error => {
|
|
|
|
log(error);
|
|
|
|
});
|
|
|
|
|
2018-04-18 18:47:40 -04:00
|
|
|
client.login(api.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
|
|
|
});
|