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

119 lines
5.3 KiB
JavaScript
Raw Normal View History

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.',
2020-10-29 08:20:45 +00:00
arguments: '<add | remove | list> <user>',
details: '',
2020-10-23 08:10:32 +00:00
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) {
2021-07-17 05:55:18 +00:00
const user = await client.users.fetch(userID);
2020-10-24 04:12:11 +00:00
list.push(`${user.username}#${user.discriminator}`);
2020-10-23 08:32:26 +00:00
}
if (list.length === 0) return message.channel.send('The server blocklist is currently empty. Use `blocklist add <user>` to add people to the blocklist!');
2020-10-24 04:12:11 +00:00
2021-07-17 05:55:18 +00:00
const embed = new client.MessageEmbed()
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(', ') + '```')
2021-07-17 05:55:18 +00:00
.setColor(client.functions.embedColor(message.guild));
2020-10-23 08:32:26 +00:00
2021-07-17 05:55:18 +00:00
message.channel.send({ embeds: [embed] });
2020-10-23 08:32:26 +00:00
2020-10-23 08:10:32 +00:00
return;
}
2021-03-06 14:15:07 +00:00
action = action.toLowerCase();
if (action !== 'add' & action !== 'remove') {
return message.channel.send(`${client.config.emojis.userError} You didn't specify a valid action. Usage: \`${this.help.usage}\``);
2021-03-03 08:20:26 +00:00
}
if (!user) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} You didn't specify a user. Usage: \`${message.prefix + this.help.usage}\``
2020-10-23 08:10:32 +00:00
);
2021-03-06 14:15:07 +00:00
let member;
2020-10-23 08:10:32 +00:00
2021-03-06 14:15:07 +00:00
if (message.mentions.length > 0) {
2021-07-17 05:55:18 +00:00
member = await message.guild.members.fetch(message.mentions[0].id);
2021-03-06 14:15:07 +00:00
} else {
2021-07-15 02:53:57 +00:00
member = await client.functions.validateUserID(message.guild, user[0]);
2020-10-23 08:10:32 +00:00
2021-03-06 14:15:07 +00:00
if (!member) {
2021-07-15 02:53:57 +00:00
member = await message.guild.searchMembers(user.join(' '), 2);
2021-03-06 14:15:07 +00:00
if (member.length === 0) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} No users found. Check for mispellings, or ping the user instead.`
2021-03-06 14:15:07 +00:00
);
if (member.length > 1) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} Found more than one user, try refining your search or pinging the user instead.`
2021-03-06 14:15:07 +00:00
);
member = member[0];
}
}
2020-10-24 05:40:12 +00:00
2020-10-23 08:10:32 +00:00
const blocklist = data.guild.blocklist;
if (action === 'add') {
2021-07-15 02:53:57 +00:00
if (member.id === message.guild.ownerID) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} You can't block the owner, silly!`
2020-10-23 08:10:32 +00:00
);
2021-07-15 02:53:57 +00:00
if (client.functions.highestRole(member).position >= client.functions.highestRole(message.member).position && message.member.id !== message.guild.ownerID) {
return message.channel.send(`${client.config.emojis.userError} This user has a higher role than you, you can't add them to the blocklist!`);
2020-10-23 08:10:32 +00:00
}
if (blocklist.includes(member.id)) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} This user is already on the blocklist, you can't add them twice!`
2020-10-23 08:10:32 +00:00
);
blocklist.push(member.id);
2021-07-15 02:53:57 +00:00
client.db.updateGuild(message.guild.id, 'blocklist', blocklist).then(() => {
message.channel.send(`${client.config.emojis.success} Added \`${member.username}#${member.discriminator}\` to the blocklist.`);
2020-10-23 08:10:32 +00:00
}).catch(error => {
client.logger.error('GUILD_UPDATE_ERROR', error);
message.channel.send(`${client.config.emojis.botError} An error occured while adding this user to the blocklist, please try again! **Error:** ${error}`);
2020-10-23 08:10:32 +00:00
}) ;
return;
}
if (action === 'remove') {
2021-07-15 02:53:57 +00:00
if (client.functions.highestRole(member).position >= client.functions.highestRole(message.member).position && message.member.id !== message.guild.ownerID) {
return message.channel.send(`${client.config.emojis.userError} This user has a higher role than you, you can't remove them to the blocklist!`);
2020-10-23 08:10:32 +00:00
}
if (!blocklist.includes(member.id)) return message.channel.send(
2021-07-15 02:26:42 +00:00
`${client.config.emojis.userError} This user isn't on the blocklist.`
2020-10-23 08:10:32 +00:00
);
blocklist.remove(member.id);
2021-07-15 02:53:57 +00:00
client.db.updateGuild(message.guild.id, 'blocklist', blocklist).then(() => {
message.channel.send(`${client.config.emojis.success} Removed \`${member.username}#${member.discriminator}\` from the blocklist.`);
2020-10-23 08:10:32 +00:00
}).catch(error => {
client.logger.error('GUILD_UPDATE_ERROR', error);
message.channel.send(`${client.config.emojis.botError} An error occured while removing this user from the blocklist, please try again! **Error:** ${error}`);
2020-10-23 08:10:32 +00:00
}) ;
return;
}
}
};