oops redunant code
This commit is contained in:
parent
30ae1cdcb7
commit
e2b42d8f95
1 changed files with 39 additions and 25 deletions
|
@ -4,8 +4,9 @@ class MessageHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handle (message) {
|
async handle (message) {
|
||||||
if (message.author.bot) return; // Ignore bots
|
// Ignore messages from bots, and messages in DM's
|
||||||
if (!message.guild) return; // Ignore DM's
|
if (message.author.bot) return;
|
||||||
|
if (!message.channel.guild) return;
|
||||||
|
|
||||||
// Request all the data we need from the database
|
// Request all the data we need from the database
|
||||||
const data = {};
|
const data = {};
|
||||||
|
@ -13,7 +14,15 @@ class MessageHandler {
|
||||||
data.guild = await this.client.db.getGuild(message.channel.guild.id);
|
data.guild = await this.client.db.getGuild(message.channel.guild.id);
|
||||||
data.member = await this.client.db.getMember(message.channel.guild.id, message.author.id);
|
data.member = await this.client.db.getMember(message.channel.guild.id, message.author.id);
|
||||||
|
|
||||||
if (data.guild.blacklist.includes(message.author.id)) return; // Ignore users on the guild blocklist
|
// Ignore users on the guild blocklist
|
||||||
|
if (data.guild.blacklist.includes(message.author.id)) return;
|
||||||
|
|
||||||
|
// If a user pings Woomy, respond to them with the prefixes they can use
|
||||||
|
if (message.content === `<@${this.client.user.id}>` || message.content === `<@!${this.client.user.id}>`) {
|
||||||
|
return message.channel.createMessage(
|
||||||
|
`Hi! Your personal prefix is \`${data.user.prefix}\`. You can also ping me ^-^`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// All the prefixes Woomy will respond to
|
// All the prefixes Woomy will respond to
|
||||||
const prefixes = [
|
const prefixes = [
|
||||||
|
@ -25,7 +34,7 @@ class MessageHandler {
|
||||||
|
|
||||||
let prefix;
|
let prefix;
|
||||||
|
|
||||||
// Check the message content to see if there
|
// Check the message content to see if it starts with one of our prefixes
|
||||||
for (const thisPrefix of prefixes) {
|
for (const thisPrefix of prefixes) {
|
||||||
if (message.content.startsWith(thisPrefix)) {
|
if (message.content.startsWith(thisPrefix)) {
|
||||||
prefix = thisPrefix;
|
prefix = thisPrefix;
|
||||||
|
@ -33,15 +42,20 @@ class MessageHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore the message if it doesn't start with a valid prefix
|
||||||
if (!prefix) return;
|
if (!prefix) return;
|
||||||
|
|
||||||
|
// Turn the message content into an array (excluding the prefix)
|
||||||
const args = message.content.slice(prefix.length).trim().split(/ +/g);
|
const args = message.content.slice(prefix.length).trim().split(/ +/g);
|
||||||
|
|
||||||
|
// Find the command
|
||||||
const commandName = args.shift().toLowerCase();
|
const commandName = args.shift().toLowerCase();
|
||||||
const command = this.client.commands.get(commandName) || this.client.commands.get(this.client.aliases.get(commandName));
|
const command = this.client.commands.get(commandName) || this.client.commands.get(this.client.aliases.get(commandName));
|
||||||
|
|
||||||
|
// Return if a command (or its aliases) are not found
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
|
|
||||||
if (message.channel.guild) {
|
// Both of these blocks check if the command is disabled/in a disabled category
|
||||||
if (data.guild.disabledcommands.includes(command.name)) return message.channel.createMessage(
|
if (data.guild.disabledcommands.includes(command.name)) return message.channel.createMessage(
|
||||||
'This command has been disabled by a server administrator.'
|
'This command has been disabled by a server administrator.'
|
||||||
);
|
);
|
||||||
|
@ -50,6 +64,7 @@ class MessageHandler {
|
||||||
'The category this command is apart of has been disabled by a server administrator.'
|
'The category this command is apart of has been disabled by a server administrator.'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Both of these blocks check the permissions of the user, and reply with missing perms if any are found
|
||||||
const missingUserPerms = this.client.helpers.checkPermissions(message.channel, message.author.id, command.userPerms);
|
const missingUserPerms = this.client.helpers.checkPermissions(message.channel, message.author.id, command.userPerms);
|
||||||
if (missingUserPerms) return message.channel.createMessage(
|
if (missingUserPerms) return message.channel.createMessage(
|
||||||
`You can't use this command because you lack these permissions: \`${missingUserPerms.join('`, `')}\``
|
`You can't use this command because you lack these permissions: \`${missingUserPerms.join('`, `')}\``
|
||||||
|
@ -59,18 +74,17 @@ class MessageHandler {
|
||||||
if (missingBotPerms) return message.channel.createMessage(
|
if (missingBotPerms) return message.channel.createMessage(
|
||||||
`I can't run this command because I lack these permissions: \`${missingBotPerms.join('`, `')}\``
|
`I can't run this command because I lack these permissions: \`${missingBotPerms.join('`, `')}\``
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (command.enabled === false) return message.channel.createMessage('This command has been disabled by my developers.');
|
// Return if the command is disabled globally
|
||||||
|
if (command.enabled === false) return message.channel.createMessage(
|
||||||
|
'This command has been disabled by my developers.'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return if the command is restricted to developers (and the user is not a developer)
|
||||||
if (command.devOnly === true && this.client.helpers.isDeveloper(message.author.id) !== true) {
|
if (command.devOnly === true && this.client.helpers.isDeveloper(message.author.id) !== true) {
|
||||||
return message.channel.send('This command\'s usage is restricted to developers only. Sorry!');
|
return message.channel.send('This command\'s usage is restricted to developers only. Sorry!');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.guildOnly === true && !message.channel.guild) {
|
|
||||||
return message.channel.createMessage('This command is unavailable in DM\'s, try running it in a server instead!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cooldown
|
// Cooldown
|
||||||
if (this.client.cooldowns.get(command.name).has(message.author.id)) {
|
if (this.client.cooldowns.get(command.name).has(message.author.id)) {
|
||||||
const timestamp = this.client.cooldowns.get(command.name).get(message.author.id);
|
const timestamp = this.client.cooldowns.get(command.name).get(message.author.id);
|
||||||
|
|
Loading…
Reference in a new issue