mirror of
https://github.com/Alee14/AleeBot.git
synced 2025-01-22 11:11:46 -05:00
New command handler. DMme if there are any errors and what the error is. (#16)
This commit is contained in:
parent
7842d67fb2
commit
339108b2e4
6 changed files with 175 additions and 99 deletions
|
@ -1,4 +1,4 @@
|
|||
/*********************************************
|
||||
/** *******************************************
|
||||
*
|
||||
* AleeBot for Discord servers
|
||||
* Copyright (C) 2018 AleeCorp
|
||||
|
@ -7,71 +7,92 @@
|
|||
**********************************************/
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
const abVersion = "2.0.0 Beta";
|
||||
const prefix = "abb:";
|
||||
const fs = require("fs");
|
||||
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!`);
|
||||
console.log('Welcome to AleeBot NodeJS Terminal!');
|
||||
|
||||
client.commands = new Discord.Collection();
|
||||
client.aliases = 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);
|
||||
})
|
||||
console.log('[>] Success! All commands are loaded...')
|
||||
})
|
||||
fs.readdir('./commands', (err, files) => {
|
||||
if (err) console.error(err);
|
||||
console.log(`Attempting to load a total of ${files.length} commands into the memory.`);
|
||||
files.forEach(file => {
|
||||
try {
|
||||
const command = require(`./commands/${file}`);
|
||||
console.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);
|
||||
console.log(`Attempting to load "${alias}" as an alias for "${command.help.name}"`);
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.log('An error has occured trying to load a command. Here is the error.');
|
||||
console.log(err.stack);
|
||||
}
|
||||
});
|
||||
console.log('Command Loading complete!');
|
||||
console.log('\n');
|
||||
});
|
||||
|
||||
|
||||
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')
|
||||
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 => {
|
||||
client.on('guildCreate', guild => {
|
||||
|
||||
console.log(`[i] New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
|
||||
console.log(`[i] New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
|
||||
|
||||
});
|
||||
|
||||
|
||||
client.on("guildDelete", guild => {
|
||||
client.on('guildDelete', guild => {
|
||||
|
||||
console.log(`[i] I have been removed from: ${guild.name} (id: ${guild.id})`);
|
||||
console.log(`[i] I have been removed from: ${guild.name} (id: ${guild.id})`);
|
||||
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
client.on('message', (msg) => {
|
||||
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 (!message.content.startsWith(prefix)) return;
|
||||
|
||||
var cmd = client.commands.get(cont[0])
|
||||
if (cmd) cmd.run(client, message, args);
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
client.login(config.abtoken).catch(function() {
|
||||
console.log("[X] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.");
|
||||
console.log('[X] Login failed. Please contact Alee14#9928 or email him at alee14498@gmail.com.');
|
||||
});
|
||||
|
|
|
@ -1,16 +1,24 @@
|
|||
module.exports.run = async (client, message, args, abVersion) => {
|
||||
var embed = new Discord.RichEmbed()
|
||||
.setAuthor('AleeBot ' + abVersion + `Changelog`, "https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048")
|
||||
.setDescription("What's new in AleeBot?")
|
||||
.addField("+ Rewritten command handler", true)
|
||||
.addField("+ New uptime command (Thanks to Rain)", true)
|
||||
.addField("? Some commands are the same from 1.x", true)
|
||||
.setFooter("AleeCorp Copyright 2017")
|
||||
.setColor("#1fd619")
|
||||
message.channel.sendEmbed(embed);
|
||||
module.exports.run = async (client, message) => {
|
||||
const Discord = require('discord.js');
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setAuthor('AleeBot ' + '2.0.0 beta' + 'Changelog', 'https://cdn.discordapp.com/avatars/282547024547545109/6c147a444ae328c38145ef1f74169e38.png?size=2048')
|
||||
.setDescription('What\'s new in AleeBot?')
|
||||
.addField('+ Rewritten command handler', true)
|
||||
.addField('+ New uptime command (Thanks to Rain)', true)
|
||||
.addField('? Some commands are the same from 1.x', true)
|
||||
.setFooter('AleeCorp Copyright 2017')
|
||||
.setColor('#1fd619');
|
||||
message.channel.sendEmbed(embed);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.config = {
|
||||
command: "changelog"
|
||||
}
|
||||
exports.conf = {
|
||||
aliases: [],
|
||||
guildOnly: false,
|
||||
};
|
||||
exports.help = {
|
||||
name: 'changelog',
|
||||
description: 'What\'s new',
|
||||
usage: 'changelog',
|
||||
category: '- General Commands',
|
||||
};
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
module.exports.run = async (client, message, args, abVersion) => {
|
||||
message.author.send("I can see you want to contribute to this project.\nHere's the link: https://github.com/AleeCorp/AleeBot")
|
||||
}
|
||||
|
||||
module.exports.config = {
|
||||
command: "git"
|
||||
}
|
||||
module.exports.run = async (client, message) => {
|
||||
message.author.send('I can see you want to contribute to this project.\nHere\'s the link: https://github.com/AleeCorp/AleeBot');
|
||||
};
|
||||
|
||||
exports.conf = {
|
||||
aliases: [],
|
||||
guildOnly: false,
|
||||
};
|
||||
exports.help = {
|
||||
name: 'git',
|
||||
description: 'Get the git info.',
|
||||
usage: 'git',
|
||||
category: '- General Commands',
|
||||
};
|
||||
|
|
|
@ -1,15 +1,41 @@
|
|||
const Discord = require('discord.js');
|
||||
module.exports.run = async (client, message, args, abVersion) => {
|
||||
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\nchangelog", true)
|
||||
.setFooter("AleeCorp Copyright 2017")
|
||||
.setColor("#1fd619")
|
||||
message.channel.sendEmbed(embed);
|
||||
module.exports.run = async (client, message) => {
|
||||
const categories = [];
|
||||
const commands = Array.from(client.commands.keys());
|
||||
|
||||
}
|
||||
commands.forEach(function(x) {
|
||||
if (!categories.includes(client.commands.get(x).help.category)) {
|
||||
categories.push(client.commands.get(x).help.category);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
command: "help"
|
||||
}
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('AleeBot Help')
|
||||
.setAuthor('AleeBot 2.0.0' + ` 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 `' + require('../absettings.json').prefix + '`')
|
||||
.setColor('#1fd619')
|
||||
.setFooter('AleeCorp Copyright 2017');
|
||||
|
||||
categories.forEach(function(x) {
|
||||
let cat = '';
|
||||
commands.forEach(function(command) {
|
||||
if (client.commands.get(command).help.category == x) {
|
||||
cat = cat + command + '\n';
|
||||
}
|
||||
});
|
||||
embed.addField(x, cat);
|
||||
});
|
||||
|
||||
await message.channel.send({ embed });
|
||||
};
|
||||
|
||||
exports.conf = {
|
||||
aliases: ['h'],
|
||||
guildOnly: false,
|
||||
};
|
||||
exports.help = {
|
||||
name: 'help',
|
||||
description: 'Displays all the commands or a page with information for 1 command.',
|
||||
usage: 'help (command:command-name)',
|
||||
category: '- General Commands',
|
||||
};
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
module.exports.run = async (client, message, args, abVersion) => {
|
||||
message.reply("**PONG!** :ping_pong: " + Math.round(client.ping) + " ms");
|
||||
}
|
||||
module.exports.run = async (client, message) => {
|
||||
message.reply('**PONG!** :ping_pong: ' + Math.round(client.ping) + ' ms');
|
||||
};
|
||||
|
||||
module.exports.config = {
|
||||
command: "ping"
|
||||
}
|
||||
exports.conf = {
|
||||
aliases: [],
|
||||
guildOnly: false,
|
||||
};
|
||||
exports.help = {
|
||||
name: 'ping',
|
||||
description: 'Ping the bot.',
|
||||
usage: 'ping',
|
||||
category: '- General Commands',
|
||||
};
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
module.exports.run = async (client, message, args, abVersion) => {
|
||||
module.exports.run = async (client, message) => {
|
||||
|
||||
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.")
|
||||
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;
|
||||
message.channel.send(':clock3: AleeBot has been up for ' + hours + ' hours, ' + uptimeMinutes + ' minutes, and ' + uptimeSeconds + ' seconds.');
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.config = {
|
||||
command: "uptime"
|
||||
}
|
||||
exports.conf = {
|
||||
aliases: [],
|
||||
guildOnly: false,
|
||||
};
|
||||
exports.help = {
|
||||
name: 'uptime',
|
||||
description: 'Displays Uptime.',
|
||||
usage: 'uptime',
|
||||
category: '- General Commands',
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue