Leave all blacklisted guilds when blacklist is used

This commit is contained in:
Dragon Fire
2021-02-14 09:59:43 -05:00
parent a746003886
commit bfd9f6e763
2 changed files with 29 additions and 2 deletions
+5 -2
View File
@@ -147,8 +147,11 @@ client.on('message', async msg => {
client.on('guildCreate', async guild => {
if (client.blacklist.guild.includes(guild.id) || client.blacklist.user.includes(guild.ownerID)) {
guild.leave();
return;
try {
await guild.leave();
} finally {
return;
}
}
if (guild.systemChannel && guild.systemChannel.permissionsFor(client.user).has('SEND_MESSAGES')) {
try {
+24
View File
@@ -33,6 +33,30 @@ module.exports = class BlacklistCommand extends Command {
if (this.client.blacklist[type].includes(target)) return msg.say(`🔨 \`${target}\` is already blacklisted.`);
this.client.blacklist[type].push(target);
this.client.exportBlacklist();
if (type === 'guild') {
try {
const guild = await this.client.guilds.fetch(target, false);
await guild.leave();
} catch {
await msg.say('🔨 Failed to leave guild.');
}
}
if (type === 'user') {
let guildsLeft = 0;
const failedToLeave = [];
for (const guild of this.client.guilds.cache.values()) {
if (guild.ownerID === target) {
try {
await guild.leave();
guildsLeft++;
} catch {
failedToLeave.push(guild.id);
}
}
}
const formatFailed = failedToLeave.length ? failedToLeave.map(id => `\`${id}\``).join(', ') : '_None_';
await msg.say(`🔨 Left ${guildsLeft} guilds owner by this user. Failed to leave: ${formatFailed}`);
}
return msg.say(`🔨 Blacklisted ${type} \`${target}\`.`);
}
};