From 49c756bd62d3cfad644fc590553c50eadb00f548 Mon Sep 17 00:00:00 2001 From: Supositware Date: Sun, 30 Jun 2024 20:05:09 +0200 Subject: [PATCH] Enable guild block list --- commands/owner/ublacklist.js | 20 +++++++++++++++----- events/client/interactionCreate.js | 16 +++++++++------- events/client/messageCreate.js | 16 +++++++++------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/commands/owner/ublacklist.js b/commands/owner/ublacklist.js index 24eb741..5bbda47 100644 --- a/commands/owner/ublacklist.js +++ b/commands/owner/ublacklist.js @@ -32,12 +32,22 @@ export default { if (!blacklist) { const body = { type:command, uid: userid, reason: reason }; Blacklists.create(body); - let user = userid; - await client.users.fetch(userid); - user = client.users.resolve(userid).username; + if (command === 'guild') { + let guildid = userid; + await client.guilds.fetch(guildid); + const guild =client.guilds.resolve(guildid).name; + + return interaction.editReply(`The guild ${guild} (${guildid}) has been blacklisted with the following reason \`${reason}\``); - - return interaction.editReply(`${user} (${userid}) has been blacklisted from ${command} with the following reason \`${reason}\``); + } + else { + let user = userid; + await client.users.fetch(userid); + user = client.users.resolve(userid).username; + + + return interaction.editReply(`${user} (${userid}) has been blacklisted from ${command} with the following reason \`${reason}\``); + } } else { const row = new ActionRowBuilder() diff --git a/events/client/interactionCreate.js b/events/client/interactionCreate.js index 25a44e2..88a9364 100644 --- a/events/client/interactionCreate.js +++ b/events/client/interactionCreate.js @@ -12,18 +12,20 @@ export default { const client = interaction.client; if (interaction.type !== InteractionType.ApplicationCommand) return; - const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:interaction.user.id } }); - // const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:interaction.guild.id } }); + const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:interaction.user.id } }) const commandBlacklist = await db.Blacklists.findOne({ where: { type:interaction.commandName, uid:interaction.user.id } }); + + if (interaction.guild) { + const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:interaction.guild.id } }); + if (serverBlacklist) { + interaction.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true }); + return interaction.guild.leave(); + } + } if (globalBlacklist) { return interaction.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true }); } - /* Server blacklist is untested - else if (serverBlacklist) { - return interaction.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true }); - } - */ else if (commandBlacklist) { return interaction.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true }); } diff --git a/events/client/messageCreate.js b/events/client/messageCreate.js index 38a1896..b90bcae 100644 --- a/events/client/messageCreate.js +++ b/events/client/messageCreate.js @@ -282,17 +282,19 @@ export default { if (!command) return; const globalBlacklist = await db.Blacklists.findOne({ where: { type:'global', uid:message.author.id } }); - // const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:message.guild.id } }); const commandBlacklist = await db.Blacklists.findOne({ where: { type:commandName, uid:message.author.id } }); + if (message.guild) { + const serverBlacklist = await db.Blacklists.findOne({ where: { type:'guild', uid:message.guild.id } }); + if (serverBlacklist) { + message.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true }); + return message.guild.leave(); + } + } + if (globalBlacklist) { return message.reply({ content: `You are globally blacklisted for the following reason: \`${globalBlacklist.reason}\``, ephemeral: true }); - } - /* Server blacklist is untested - else if (serverBlacklist) { - return message.reply({ content: `This guild has been blacklisted for the following reason: \`${serverBlacklist.reason}\``, ephemeral: true }); - } - */ + } else if (commandBlacklist) { return message.reply({ content: `You are blacklisted for the following reason: \`${commandBlacklist.reason}\``, ephemeral: true }); }