0ckCCZYC2tT9

This commit is contained in:
Ashley Graves 2024-10-10 18:21:41 +02:00
parent d5d7f41f2a
commit e5ba09e315
2 changed files with 12 additions and 4 deletions

View file

@ -26,6 +26,11 @@ const data = new SlashCommandBuilder()
.setDescription("Tag to unblacklist") .setDescription("Tag to unblacklist")
.setAutocomplete(true) .setAutocomplete(true)
)) ))
.addSubcommand((builder) =>
builder //
.setName("list")
.setDescription("List current blacklist")
)
.setContexts([ .setContexts([
InteractionContextType.Guild, InteractionContextType.Guild,
InteractionContextType.BotDM, InteractionContextType.BotDM,
@ -41,7 +46,6 @@ module.exports = {
async execute(interaction) { async execute(interaction) {
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
const command = interaction.options.getSubcommand(true); const command = interaction.options.getSubcommand(true);
const tag = interaction.options.getString("tag").replaceAll(" ", "_");
var result = await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first(); var result = await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first();
if (!result) if (!result)
result = { blacklist: '' }; result = { blacklist: '' };
@ -50,10 +54,13 @@ module.exports = {
const data = { const data = {
user: interaction.user.id, user: interaction.user.id,
blacklist: [...blacklist].join(" ").trim() blacklist: blacklist.join(" ").trim()
} }
switch (command) { switch (command) {
case "add" || "remove":
const tag = interaction.options.getString("tag").replaceAll(" ", "_");
case "add": case "add":
if (blacklist.includes(tag)) { if (blacklist.includes(tag)) {
await interaction.followUp("This tag is already blacklisted."); await interaction.followUp("This tag is already blacklisted.");
@ -67,6 +74,9 @@ module.exports = {
data.blacklist = data.blacklist.split(" ").filter(i => i != tag).join(" ").trim(); data.blacklist = data.blacklist.split(" ").filter(i => i != tag).join(" ").trim();
await interaction.followUp("Successfully removed!"); await interaction.followUp("Successfully removed!");
break; break;
case "list":
await interaction.followUp(`Current blacklist:\n\`\`${blacklist.join(", ").replaceAll("`", "`" + String.fromCharCode(8203))}\`\``);
return;
default: default:
break; break;
} }

View file

@ -137,11 +137,9 @@ module.exports = {
const tags = (interaction.options.getString("tags") ?? "").split(" "); const tags = (interaction.options.getString("tags") ?? "").split(" ");
const booru = interaction.options.getString("booru") ?? defaultBooru; const booru = interaction.options.getString("booru") ?? defaultBooru;
const rating = (interaction.options.getString("rating") ?? ratings[0]); const rating = (interaction.options.getString("rating") ?? ratings[0]);
console.log(rating);
const userBlacklist = ((await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first()).blacklist ?? "").split(" "); const userBlacklist = ((await knex.select("blacklist").from("blacklists").where("user", interaction.user.id).first()).blacklist ?? "").split(" ");
const searchTags = [rating, ...tags, ...[...blacklist, ...userBlacklist].map(i => "-" + i)]; const searchTags = [rating, ...tags, ...[...blacklist, ...userBlacklist].map(i => "-" + i)];
console.log(rating, searchTags);
const startTime = process.hrtime.bigint(); const startTime = process.hrtime.bigint();