AleeBot/aleebot.js

120 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-05-31 16:26:45 -04:00
/****************************************
2017-07-29 15:46:00 -04:00
*
* AleeBot for AleeArmy Community and other servers
* Copyright (C) 2017 AleeCorp
2017-05-31 16:26:45 -04:00
*
2017-08-13 20:59:45 -04:00
* 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:
2017-07-29 15:46:00 -04:00
*
2017-08-13 20:59:45 -04:00
* 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.
*
*
**************************************/
2017-05-31 16:09:24 -04:00
const Discord = require('discord.js');
const moment = require('moment');
2017-08-16 01:22:34 -04:00
const blessed = require('blessed');
const fs = require('fs');
2017-05-31 16:09:24 -04:00
const client = new Discord.Client();
2017-07-29 17:57:02 -04:00
const config = require('./absettings.json');
const log = message => {
2017-08-20 17:09:09 -04:00
console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);
};
2017-07-29 15:46:00 -04:00
var logsChannel = "318874545593384970";
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
2017-08-20 17:09:09 -04:00
fs.readdir('./commands/', (err, files) => {
if (err) console.error(err);
log(`Loading a total of ${files.length} commands.`);
files.forEach(f => {
2017-08-20 17:09:09 -04:00
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);
});
});
2017-08-20 17:09:09 -04:00
});
client.on('ready', () => {
2017-08-20 17:09:09 -04:00
log("[>] AleeBot is now ready! Running version " + config.abversion + "!");
client.user.setPresence({
game: {
name: 'with version ' + config.abversion + '',
type: 0
}
});
client.user.setStatus('online')
});
2017-07-31 16:46:27 -04:00
client.on("guildCreate", guild => {
2017-08-20 17:09:09 -04:00
// This event triggers when the bot joins a guild.
2017-07-31 16:46:27 -04:00
2017-08-20 17:09:09 -04:00
log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
2017-07-31 16:46:27 -04:00
2017-08-20 17:09:09 -04:00
guild.defaultChannel.sendMessage(":wave: Hello I am AleeBot thanks for inviting me to your server for help type `" + config.prefix + "help`.")
2017-07-31 16:46:27 -04:00
});
client.on("guildDelete", guild => {
2017-08-20 17:09:09 -04:00
// this event triggers when the bot is removed from a guild.
2017-07-31 16:46:27 -04:00
2017-08-20 17:09:09 -04:00
log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
2017-07-31 16:46:27 -04:00
});
2017-08-20 17:09:09 -04:00
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);
} catch (err) {
message.reply(`:no_entry_sign: Error!\nThe command ${command} isn't found. (Reported to console.)`)
console.error(err);
}
2017-07-29 21:42:13 -04:00
});
2017-07-29 15:46:00 -04:00
2017-08-20 17:09:09 -04:00
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.");
});