AleeBot/bot_discord.js

328 lines
11 KiB
JavaScript
Raw Normal View History

2018-03-31 13:32:44 -04:00
/****************************************
2018-11-11 21:19:01 -05:00
*
2018-03-31 13:32:44 -04:00
* AleeBot: Made for discord servers
* Copyright (C) 2017-2020 Alee Productions
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-11-11 21:19:01 -05:00
*
2018-03-31 13:32:44 -04:00
* *************************************/
2018-01-26 17:38:08 -05:00
const Discord = require('discord.js');
2018-04-01 16:29:56 -04:00
const moment = require('moment');
2018-04-22 15:09:16 -04:00
const readline = require('readline');
2018-06-01 22:17:04 -04:00
const colors = require('colors');
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')
const fs = require('fs');
2018-04-18 18:47:40 -04:00
const api = require('./tokens.json');
const dbl = new DBL(api.dbltoken, client);
const active = new Map();
const ownerID = "242775871059001344";
2018-04-01 10:13:24 -04:00
2018-04-01 16:29:56 -04:00
const log = message => {
2018-06-01 22:17:04 -04:00
console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`.white);
2018-04-01 16:29:56 -04:00
};
2018-04-22 15:09:16 -04:00
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
2018-06-01 22:17:04 -04:00
prompt: '> '.gray
2018-04-22 15:09:16 -04:00
});
console.log(`AleeBot ${settings.abVersion}: Copyright (C) 2017-2020 Alee Productions`.gray);
2018-06-01 22:17:04 -04:00
console.log('This program comes with ABSOLUTELY NO WARRANTY; for details type `show w\'.'.gray);
console.log ('This is free software, and you are welcome to redistribute it'.gray);
console.log ('under certain conditions; type `show c\' for details.\n'.gray)
2018-01-26 17:38:08 -05:00
2018-04-15 10:09:31 -04:00
if (process.argv.indexOf("--debug") == -1) {
2018-06-01 22:17:04 -04:00
console.log("Running AleeBot without --debug command line flag. Debug output disabled.\n".yellow);
2018-04-15 10:09:31 -04:00
} else {
2018-06-01 22:17:04 -04:00
console.log('[!] Entering debug mode...'.yellow)
2018-04-15 10:09:31 -04:00
client.on('debug', function(info) {
2018-06-01 22:17:04 -04:00
log(info.gray);
2018-04-15 10:09:31 -04:00
});
client.on('warn', function(info) {
2018-06-01 22:17:04 -04:00
log(info.red);
2018-04-15 10:09:31 -04:00
});
}
2018-07-04 16:48:56 -04:00
if (process.argv.indexOf("--beta") == -1) {
client.login(api.abtoken).catch(function() {
console.log('[X] Login failed. The token that you put in is invalid, please put in a new one...'.red);
process.exit(0);
2018-07-04 16:48:56 -04:00
});
2018-11-11 21:19:01 -05:00
2018-07-04 16:48:56 -04:00
} else {
client.login(api.abbtoken).catch(function() {
console.log('[X] Login failed. The token that you put in is invalid, please put in a new one...'.red);
process.exit(0);
2018-11-11 21:19:01 -05:00
});
2018-07-04 16:48:56 -04:00
}
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-06-01 22:17:04 -04:00
log(`[!] Attempting to load a total of ${files.length} commands into the memory.`.cyan);
files.forEach(file => {
try {
const command = require(`./commands/${file}`);
2018-06-01 22:17:04 -04:00
log(`[!] Attempting to load the command "${command.help.name}".`.cyan);
client.commands.set(command.help.name, command);
command.conf.aliases.forEach(alias => {
client.aliases.set(alias, command.help.name);
2018-06-01 22:17:04 -04:00
log(`[!] Attempting to load "${alias}" as an alias for "${command.help.name}"`.cyan);
});
}
catch (err) {
2018-06-01 22:17:04 -04:00
log('[X] An error has occured trying to load a command. Here is the error.'.red);
2018-04-01 16:51:25 -04:00
console.log(err.stack);
}
});
2018-06-01 22:17:04 -04:00
log('[>] Command Loading complete!'.green);
console.log('\n');
});
2018-01-26 17:38:08 -05:00
2018-04-22 15:09:16 -04:00
rl.on('line', function(cmd){
var args = cmd.split(" ");
switch(args[0]) {
case "guilds":
if (client.guilds.size === 0) {
2018-06-01 22:17:04 -04:00
console.log(('[!] No guilds found.'.yellow));
2018-04-22 15:09:16 -04:00
} else {
console.log('[i] Here\'s the servers that AleeBot is connected to:')
for ([id, guild] of client.guilds) {
2018-06-01 22:17:04 -04:00
console.log(` Guild Name: ${guild.name} - ID: ${guild.id}`.blue);
2018-04-22 15:09:16 -04:00
}
}
break;
2018-04-22 18:22:11 -04:00
case "channels":
if (!args[1]) {
2018-06-01 22:17:04 -04:00
console.log('[!] Please insert the guild\'s ID.'.yellow)
2018-04-22 18:22:11 -04:00
} else {
var guild = client.guilds.get(args[1]);
2018-06-01 22:17:04 -04:00
console.log('[i] Here\'s the channels that this guild have:'.blue)
2018-04-22 18:22:11 -04:00
for ([id, channel, guild] of guild && client.channels) {
2018-06-01 22:17:04 -04:00
console.log(` Channel: #${channel.name} - ID: ${channel.id}`.blue);
2018-04-22 18:22:11 -04:00
}
}
break;
2018-04-22 15:09:16 -04:00
case "leave":
if (!args[1]) {
2018-06-01 22:17:04 -04:00
console.log('[!] Please insert the guild\'s ID.'.yellow);
2018-04-22 15:09:16 -04:00
} else {
var guild = client.guilds.get(args[1]);
guild.leave();
}
break;
case "broadcast":
if (!args[1]) {
2018-06-01 22:17:04 -04:00
console.log('[!] Usage: broadcast [guildID] [channelID].'.yellow);
2018-04-22 15:09:16 -04:00
} else {
let broadcast = args.join(" ").slice(48);
var guild = null;
guild = client.guilds.get(args[1]);
var channel = null;
channel = guild.channels.get(args[2])
if (channel != null) {
channel.send(broadcast);
}
}
break;
2018-04-22 16:03:43 -04:00
case "uptime":
let uptime = parseInt(client.uptime);
uptime = Math.floor(uptime / 1000);
let uptimeMinutes = Math.floor(uptime / 60);
const minutes = uptime % 60;
let hours = 0;
while (uptimeMinutes >= 60) {
hours++;
uptimeMinutes = uptimeMinutes - 60;
}
const uptimeSeconds = minutes % 60;
2018-06-01 22:17:04 -04:00
console.log(`[i] AleeBot has been up for ${hours} hours, ${uptimeMinutes} minutes, and ${uptimeSeconds} seconds.`.blue);
2018-04-22 16:03:43 -04:00
break;
2018-04-22 15:09:16 -04:00
case "exit":
2018-06-01 22:17:04 -04:00
console.log('[i] AleeBot will now exit!'.blue)
client.destroy();
2018-04-22 15:09:16 -04:00
process.exit(0);
break;
case "help":
var msg = (`AleeBot `+ settings.abVersion +` Console Help\n\n`);
msg += (`guilds - Shows all guilds that AleeBot's on.\n`)
2018-04-22 18:22:11 -04:00
msg += (`channels - Shows all the channels that the guilds have.\n`)
2018-04-22 15:09:16 -04:00
msg += (`leave - Leaves a guild.\n`)
msg += (`broadcast - Broadcasts a message to a server.\n`)
2018-04-22 16:03:43 -04:00
msg += (`uptime - Shows the uptime for AleeBot.\n`)
2018-04-22 15:09:16 -04:00
msg += (`help - Shows this command.\n`)
msg += (`exit - Exits AleeBot.\n`)
2018-06-01 22:17:04 -04:00
console.log(msg.cyan);
2018-04-22 15:09:16 -04:00
break;
default:
console.log('Unknown command, type \'help\' to list the commands...'.yellow)
2018-04-22 15:09:16 -04:00
}
rl.prompt();
});
2018-01-26 17:38:08 -05:00
client.on('ready', () => {
2018-06-01 22:17:04 -04:00
log('[>] AleeBot is now ready!'.green);
log(`[i] Logged in as ${client.user.tag}`.green);
log(`[i] Default Prefix: ${settings.prefix}`.green)
log(`[i] Bot ID: ${client.user.id}`.green);
log(`[i] Token: ${api.abtoken}`.green);
log(`[i] Running version ${settings.abVersion} and in ${client.guilds.size} guilds`.green);
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);
2018-06-24 11:35:42 -04:00
}, 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);
client.user.setStatus('online');
2020-01-03 01:41:56 -05:00
//client.channels.find('id', '606602551634296968').send("**AleeBot Status:** AleeBot has started.");
2018-04-22 15:09:16 -04:00
rl.prompt();
2018-01-26 17:38:08 -05:00
});
client.on('guildCreate', guild => {
2018-01-26 17:38:08 -05:00
2018-06-01 22:17:04 -04:00
log(`[i] New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`.blue);
2018-01-26 17:38:08 -05:00
});
client.on('guildDelete', guild => {
2018-01-26 17:38:08 -05:00
2018-06-01 22:17:04 -04:00
log(`[i] I have been removed from: ${guild.name} (id: ${guild.id})`.red);
2018-01-26 17:38:08 -05:00
});
2018-07-07 22:24:53 -04:00
dbl.on('posted', () => {
log('Server count posted!'.blue);
});
2018-07-07 22:24:53 -04:00
dbl.on('error', e => {
log(`[X | DBL ERROR] ${e}`.red);
});
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;
2018-11-11 21:19:01 -05:00
2018-07-04 16:48:56 -04:00
if (msg.mentions != null && msg.mentions.users != null) {
if (msg.mentions.users.has("282547024547545109")){
if (msg.content.toLowerCase().includes("hello") || (msg.content.toLowerCase().includes("hi"))) {
2018-07-07 20:17:38 -04:00
msg.reply(`Hello ${msg.author.username}!`);
2018-07-04 16:48:56 -04:00
} else {
if (msg.content.toLowerCase().includes("shut") && msg.content.toLowerCase().includes("up")) {
switch (Math.floor(Math.random() * 1000) % 3) {
case 0:
msg.reply("Excuse me? Can you not speak to me in that tone...")
break;
case 1:
msg.reply("NO! I can talk as much I can!");
break;
case 2:
msg.reply("Nah I won't....");
break;
}
} else if (msg.content.toLowerCase().includes("how") && msg.content.toLowerCase().includes("are") && msg.content.toLowerCase().includes("you")) {
2018-07-07 20:17:38 -04:00
msg.reply("I'm doing OK, I suppose...");
} else if (msg.content.toLowerCase().includes("ok") && msg.content.toLowerCase().includes("google")) {
msg.reply("Erm... I am not google, if you want to use Google here's the link: https://www.google.com");
} else if (msg.content.toLowerCase().includes("f") && msg.content.toLowerCase().includes("off")) {
msg.reply("Do you want a hammer? :hammer:");
} else if (msg.content.toLowerCase().includes("aleearmy")) {
msg.reply("Oh yeah.. that thing Alee made...");
2018-07-04 16:48:56 -04:00
}
}
}
2018-07-07 20:17:38 -04:00
};
2018-07-04 16:48:56 -04:00
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-11-11 21:19:01 -05: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);
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 {
let ops = {
ownerID: ownerID,
active: active
}
cmd.run(client, msg, args, ops);
}
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-06-01 22:17:04 -04:00
log("[X | UNCAUGHT PROMISE] " + err.stack.red);
2018-03-26 16:11:02 -04:00
});
client.on('reconnecting', function() {
log("[!] AleeBot has disconnected from Discord and is now attempting to reconnect.".yellow);
});
client.on('disconnect', function() {
log("[X] AleeBot has disconnected from Discord and will not attempt to reconnect.".red);
console.log("At this point, you'll need to restart AleeBot.".red);
2018-11-11 21:19:01 -05:00
});