woomy-v2/bot/commands/Configuration/blocklist.js

104 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-10-23 08:32:26 +00:00
const Embed = require('../../util/embed');
2020-10-23 08:10:32 +00:00
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') {
2020-10-23 08:32:26 +00:00
const list = [];
2020-10-24 04:12:11 +00:00
for (const userID of data.guild.blocklist) {
2020-10-25 02:10:05 +00:00
const user = await client.functions.getUser(userID);
2020-10-24 04:12:11 +00:00
list.push(`${user.username}#${user.discriminator}`);
2020-10-23 08:32:26 +00:00
}
2020-10-24 05:40:12 +00:00
if (list.length === 0) return message.channel.createMessage('The server blocklist is currently empty. Use `blocklist add <user>` to add people to the blocklist!');
2020-10-24 04:12:11 +00:00
2020-10-23 08:32:26 +00:00
const embed = new Embed()
2020-10-24 04:12:11 +00:00
.setTitle('Users on blocklist: ' + data.guild.blocklist.length)
2020-10-24 05:40:12 +00:00
.setDescription('```' + list.join(', ') + '```')
2020-10-24 04:12:11 +00:00
.setColor('PINK');
2020-10-23 08:32:26 +00:00
message.channel.createMessage({ embed: embed });
2020-10-23 08:10:32 +00:00
return;
}
2020-10-24 05:40:12 +00:00
if (!user) return message.channel.createMessage(
2020-10-24 04:12:11 +00:00
`${client.constants.emojis.userError} You didn't specify a user. Usage: \`${this.help.usage}\``
2020-10-23 08:10:32 +00:00
);
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.`
);
action = action.toLowerCase();
2020-10-24 05:40:12 +00:00
member = member[0];
2020-10-23 08:10:32 +00:00
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!`
);
2020-10-25 02:10:05 +00:00
if (client.functions.highestRole(member).position >= client.functions.highestRole(message.member).position && message.member.id !== message.channel.guild.ownerID) {
2020-10-23 08:10:32 +00:00
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') {
2020-10-25 02:10:05 +00:00
if (client.functions.highestRole(member).position >= client.functions.highestRole(message.member).position && message.member.id !== message.channel.guild.ownerID) {
2020-10-23 08:10:32 +00:00
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;
}
}
};