From aec01905b5b08a0c7ec7f1133437f12907ae7153 Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Sun, 20 Oct 2024 14:26:45 -0400 Subject: [PATCH] Differentiate between checking if a user is banned by user or id --- src/commands/confess.ts | 2 +- src/commands/confessmod.ts | 2 +- src/main.ts | 4 ++-- src/storeman/client.ts | 20 +++++++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/commands/confess.ts b/src/commands/confess.ts index d858346..922b2c0 100644 --- a/src/commands/confess.ts +++ b/src/commands/confess.ts @@ -54,7 +54,7 @@ export async function execute(interaction: ChatInputCommandInteraction) { // instead because all of this is used in src/main.ts try { // If the user is banned in this guild, don't let them post - if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) { + if (dt.isBannedByUser(interaction.guild?.id!, interaction.user.id)) { return interaction.reply({ content: "You are banned from confessions in this server!", ephemeral: true diff --git a/src/commands/confessmod.ts b/src/commands/confessmod.ts index 510a3b4..80bdc67 100644 --- a/src/commands/confessmod.ts +++ b/src/commands/confessmod.ts @@ -67,7 +67,7 @@ export async function execute(interaction: ChatInputCommandInteraction) { if (interaction.options.getSubcommand() === "ban") { const confessionId = interaction.options.getString("id")!; - if (dt.isBanned(guildId, confessionId)) { + if (dt.isBannedById(guildId, confessionId)) { try { return interaction.reply({ content: "That user is already banned!", diff --git a/src/main.ts b/src/main.ts index d96e199..746dabc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -97,7 +97,7 @@ BotClient.on(Events.InteractionCreate, async interaction => { if (requestSubmit) { // Check if the user is banned from confessions before showing the modal - dt.isBanned(interaction.guild?.id!, interaction.user.id) + dt.isBannedByUser(interaction.guild?.id!, interaction.user.id) ? interaction.reply({ content: "You are banned from confessions in this server!", ephemeral: true @@ -118,7 +118,7 @@ BotClient.on(Events.InteractionCreate, async interaction => { ); try { - if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) { + if (dt.isBannedByUser(interaction.guild?.id!, interaction.user.id)) { return interaction.reply({ content: "You are banned from confessions in this server!", ephemeral: true diff --git a/src/storeman/client.ts b/src/storeman/client.ts index 7ff8536..26508d7 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -135,7 +135,7 @@ export class StoreMan { for (const guild of this.data) { if (guild.id === guildId) { // If the author's user ID is in the ban list, don't let them post a confession. - if (this.isBanned(guildId, author)) { + if (this.isBannedByUser(guildId, author)) { return false; } @@ -215,7 +215,7 @@ export class StoreMan { } // Check if a certain user is banned within a guild. - public isBanned(guildId: string, userId: string): boolean { + public isBannedByUser(guildId: string, userId: string): boolean { for (const guild of this.data) { if (guild.id === guildId) { for (const ban of guild.settings.bans) { @@ -229,6 +229,20 @@ export class StoreMan { return false; } + public isBannedById(guildId: string, confessionId: string): boolean { + for (const guild of this.data) { + if (guild.id === guildId) { + for (const ban of guild.settings.bans) { + if (ban.confessionId === confessionId) { + return true; + } + } + } + } + + return false; + } + public getBans(guildId: string): ConfessionBan[] { for (const guild of this.data) { if (guild.id === guildId) { @@ -247,7 +261,7 @@ export class StoreMan { if (guild.id === guildId) { if (confession) { // Only add the user to the ban list if they aren't banned already - !this.isBanned(guildId, confession.authorId) && + !this.isBannedByUser(guildId, confession.authorId) && guild.settings.bans.push({ user: confession.authorId, confessionId: confessionId