blocklist works
This commit is contained in:
parent
66807a01fc
commit
8c214b8704
2 changed files with 97 additions and 8 deletions
87
bot/commands/Configuration/blocklist.js
Normal file
87
bot/commands/Configuration/blocklist.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
module.exports = class {
|
||||
constructor (name, category) {
|
||||
this.name = name,
|
||||
this.category = category,
|
||||
this.enabled = true,
|
||||
this.devOnly = false,
|
||||
this.aliases = [],
|
||||
this.userPerms = ['administrator'],
|
||||
this.botPerms = [],
|
||||
this.cooldown = 2000,
|
||||
this.help = {
|
||||
description: 'Add, remove or list users on the blocklist for this server. User\'s on the blocklist cannot use my commands.',
|
||||
usage: 'blocklist <add | remove | list> <user>',
|
||||
examples: 'blocklist list\nblocklist add @Veemo\nblocklist remove emily'
|
||||
};
|
||||
}
|
||||
|
||||
async run (client, message, [action, ...user], data) {
|
||||
if (!action || action.toLowerCase() === 'list') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.length === 0) return message.channel.createMessage(
|
||||
`${client.constants.emojis.userError} You didn\'t specify a user. Usage: \`${this.help.usage}\``
|
||||
);
|
||||
|
||||
let member = message.mentions[0];
|
||||
|
||||
if (!member) member = await message.channel.guild.searchMembers(user.join(' '), 2);
|
||||
|
||||
if (member.length > 1) return message.channel.createMessage(
|
||||
`${client.constants.emojis.userError} Found more than one user, try refining your search or pinging the user instead.`
|
||||
);
|
||||
|
||||
member = message.channel.guild.members.get(member.id);
|
||||
|
||||
action = action.toLowerCase();
|
||||
|
||||
const blocklist = data.guild.blocklist;
|
||||
|
||||
if (action === 'add') {
|
||||
if (member.id === message.channel.guild.ownerID) return message.channel.createMessage(
|
||||
`${client.constants.emojis.userError} You can't block the owner, silly!`
|
||||
);
|
||||
|
||||
if (client.helpers.highestRole(member).position >= client.helpers.highestRole(message.member).position && message.member.id !== message.channel.guild.ownerID) {
|
||||
return message.channel.createMessage(`${client.constants.emojis.userError} This user has a higher role than you, you can't add them to the blocklist!`);
|
||||
}
|
||||
|
||||
if (blocklist.includes(member.id)) return message.channel.createMessage(
|
||||
`${client.constants.emojis.userError} This user is already on the blocklist, you can't add them twice!`
|
||||
);
|
||||
|
||||
blocklist.push(member.id);
|
||||
|
||||
client.db.updateGuild(message.channel.guild.id, 'blocklist', blocklist).then(() => {
|
||||
message.channel.createMessage(`${client.constants.emojis.success} Added \`${member.username}#${member.discriminator}\` to the blocklist.`);
|
||||
}).catch(error => {
|
||||
client.logger.error('GUILD_UPDATE_ERROR', error);
|
||||
message.channel.createMessage(`${client.constants.emojis.botError} An error occured while adding this user to the blocklist, please try again! **Error:** ${error}`);
|
||||
}) ;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === 'remove') {
|
||||
if (client.helpers.highestRole(member).position >= client.helpers.highestRole(message.member).position && message.member.id !== message.channel.guild.ownerID) {
|
||||
return message.channel.createMessage(`${client.constants.emojis.userError} This user has a higher role than you, you can't remove them to the blocklist!`);
|
||||
}
|
||||
|
||||
if (!blocklist.includes(member.id)) return message.channel.createMessage(
|
||||
`${client.constants.emojis.userError} This user isn't on the blocklist.`
|
||||
);
|
||||
|
||||
blocklist.remove(member.id);
|
||||
|
||||
client.db.updateGuild(message.channel.guild.id, 'blocklist', blocklist).then(() => {
|
||||
message.channel.createMessage(`${client.constants.emojis.success} Removed \`${member.username}#${member.discriminator}\` from the blocklist.`);
|
||||
}).catch(error => {
|
||||
client.logger.error('GUILD_UPDATE_ERROR', error);
|
||||
message.channel.createMessage(`${client.constants.emojis.botError} An error occured while removing this user from the blocklist, please try again! **Error:** ${error}`);
|
||||
}) ;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -15,7 +15,7 @@ class MessageHandler {
|
|||
data.member = await this.client.db.getMember(message.channel.guild.id, message.author.id);
|
||||
|
||||
// Ignore users on the guild blocklist
|
||||
if (data.guild.blacklist.includes(message.author.id)) return;
|
||||
if (data.guild.blocklist.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}>`) {
|
||||
|
@ -57,32 +57,34 @@ class MessageHandler {
|
|||
|
||||
// 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(
|
||||
'This command has been disabled by a server administrator.'
|
||||
this.client.constants.emojis.permError + ' This command has been disabled by a server administrator.'
|
||||
);
|
||||
|
||||
if (data.guild.disabledcategories.includes(command.category)) return message.channel.createMessage(
|
||||
'The category this command is apart of has been disabled by a server administrator.'
|
||||
this.client.constants.emojis.permError + ' 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);
|
||||
if (missingUserPerms) return message.channel.createMessage(
|
||||
`You can't use this command because you lack these permissions: \`${missingUserPerms.join('`, `')}\``
|
||||
`${this.client.constants.emojis.permError} You can't use this command because you lack these permissions: \`${missingUserPerms.join('`, `')}\``
|
||||
);
|
||||
|
||||
const missingBotPerms = this.client.helpers.checkPermissions(message.channel, this.client.user.id, command.botPerms);
|
||||
if (missingBotPerms) return message.channel.createMessage(
|
||||
`I can't run this command because I lack these permissions: \`${missingBotPerms.join('`, `')}\``
|
||||
`${this.client.constants.emojis.permError} I can't run this command because I lack these permissions: \`${missingBotPerms.join('`, `')}\``
|
||||
);
|
||||
|
||||
// Return if the command is disabled globally
|
||||
if (command.enabled === false) return message.channel.createMessage(
|
||||
'This command has been disabled by my developers.'
|
||||
this.client.constants.emojis.permError + ' 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) {
|
||||
return message.channel.send('This command\'s usage is restricted to developers only. Sorry!');
|
||||
return message.channel.send(
|
||||
this.client.constants.emojis.permError + ' This command\'s usage is restricted to developers only. Sorry!'
|
||||
);
|
||||
}
|
||||
|
||||
// Cooldown
|
||||
|
@ -92,7 +94,7 @@ class MessageHandler {
|
|||
const cooldown = command.cooldown / 1000;
|
||||
const timePassed = Math.floor((currentTime - timestamp) / 1000);
|
||||
return message.channel.createMessage(
|
||||
`⏲️ ${message.author.mention}, you need to wait ${cooldown - timePassed} seconds before using this command again.`
|
||||
`${this.client.constants.emojis.wait} ${message.author.mention}, you need to wait ${cooldown - timePassed} seconds before using this command again.`
|
||||
);
|
||||
} else {
|
||||
this.client.cooldowns.get(command.name).set(message.author.id, new Date());
|
||||
|
|
Loading…
Reference in a new issue