From cf30d2e4b658e5552ccdb67cfbb66a9d733fa9db Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Thu, 10 Oct 2024 18:17:08 +0200 Subject: [PATCH] UEEZR1/kDPa9 --- src/commands/fun/blacklist.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/fun/blacklist.js b/src/commands/fun/blacklist.js index 4e971b5..06609f8 100644 --- a/src/commands/fun/blacklist.js +++ b/src/commands/fun/blacklist.js @@ -42,7 +42,11 @@ module.exports = { await interaction.deferReply({ ephemeral: true }); const command = interaction.options.getSubcommand(true); const tag = interaction.options.getString("tag").replaceAll(" ", "_"); - const blacklist = ((await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first()).blacklist ?? "").split(" "); + var result = await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first(); + if (!result) + result = { blacklist: '' }; + + const blacklist = (result.blacklist ?? "").trim().split(" "); const data = { user: interaction.user.id, @@ -76,15 +80,18 @@ module.exports = { const value = interaction.options.getFocused() ?? ""; const command = interaction.options.getSubcommand(true); if (command == "remove") { - const blacklist = ((await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first()) ?? { blacklist: '' }).blacklist.trim().split(" "); + var result = await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first(); + if (!result) + result = { blacklist: '' }; + + const blacklist = (result.blacklist ?? "").trim().split(" "); const choices = []; for (const tag of blacklist) { - if (tag != "" && (value == "" || tag.startsWith(value.trim()))) + if (value == "" || tag.startsWith(value.trim())) choices.push(tag); } - if (choices.length == 0) - return; + console.log(choices); await interaction.respond(choices.map(choice => ({ name: choice, value: choice }))) }