From 43a3fe4c2580ec71b9cd64b6f9d070a5f632b73a Mon Sep 17 00:00:00 2001 From: Ashley Graves Date: Thu, 10 Oct 2024 11:19:08 +0200 Subject: [PATCH] re-add nsfw --- src/commands/fun/gelbooru.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/commands/fun/gelbooru.js b/src/commands/fun/gelbooru.js index e820404..e554c72 100644 --- a/src/commands/fun/gelbooru.js +++ b/src/commands/fun/gelbooru.js @@ -56,14 +56,14 @@ function notEmpty(str) { const regexCutTags = /[\S\s]{1,75}[^,]{0,25}/; function formatTags(tags) { - const tagString = decode(tags.join(', ')) + const tagString = decode(tags.join(', ')); if (tagString.length < 100) { - return tagString + return tagString; } - const tagCutMatch = tagString.match(regexCutTags) ?? [] - return `${escapeMarkdown(tagCutMatch[0] ?? '')}...` + const tagCutMatch = tagString.match(regexCutTags) ?? []; + return `${escapeMarkdown(tagCutMatch[0] ?? '')}, ...`; } const ratingEmojis = { @@ -88,10 +88,6 @@ function formatScore(score) { } } -function isNSFWPost(post) { - return !['s', 'g'].includes(post.rating) -} - function formatTime(time) { return `${(Number(time) / 1e6).toFixed(2)}ms` } @@ -114,16 +110,16 @@ module.exports = { const booru = interaction.options.getString("booru") ?? defaultBooru; const nsfw = interaction.options.getBoolean("nsfw") ?? false; - //await interaction.deferReply(); - console.log(booru, tags); + await interaction.reply("Searching, please wait..."); + tags = [...(nsfw ? [] : ["-rating:explicit", "-rating:questionable"]), ...tags]; const startTime = process.hrtime.bigint(); var post = null; while (post == null) { - var newPost = (await Booru.search(booru, ["-rating:explicit", ...tags], { limit: 1, random: true, credentials: credentials[booru] ?? null }))[0]; + var newPost = (await Booru.search(booru, tags, { limit: 1, random: true, credentials: credentials[booru] ?? null }))[0]; if (newPost == null) { - await interaction.reply("Could not find any post matching tags."); + await interaction.editReply("Could not find any post matching tags."); return; } if (/*!nsfw && isNSFWPost(newPost) || */isAIPost(newPost)) continue; @@ -177,9 +173,9 @@ module.exports = { iconURL: `https://${post.booru.domain}/favicon.ico`, }) - await interaction.reply({ embeds: [embed.data] }); + await interaction.editReply({ embeds: [embed.data] }); } else { - await interaction.reply( + await interaction.editReply( '>>> ' + bold(`[Post #${post.id}](<${post.postView}>)`) + "\n" + description + "\n" + footerText