From 1049e1da2111c350b0fa5f3fd54f0c5b604fe994 Mon Sep 17 00:00:00 2001 From: Shadow Date: Wed, 7 Aug 2024 15:48:17 -0400 Subject: [PATCH 1/2] fix(moderate): note/report replies, actions not working on nonguild users --- src/discord/commands/guild/d.moderate.ts | 83 +++++++++++++++--------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/src/discord/commands/guild/d.moderate.ts b/src/discord/commands/guild/d.moderate.ts index c7ac2c024..bca2624ed 100644 --- a/src/discord/commands/guild/d.moderate.ts +++ b/src/discord/commands/guild/d.moderate.ts @@ -839,43 +839,50 @@ export async function modResponse( create: { discord_id: userId }, update: {}, }); - - actionRow.addComponents( - modButtonNote(userId), - ); - let banVerb = 'ban'; - let userBan = {} as GuildBan; - try { - userBan = await interaction.guild.bans.fetch(userId); - } catch (err: unknown) { - // log.debug(F, `Error fetching ban: ${err}`); - } - if (userBan.guild) { + if (showModButtons) { actionRow.addComponents( - modButtonUnBan(userId), + modButtonNote(userId), ); - banVerb = 'un-ban'; - } else { + + let userBan = {} as GuildBan; + try { + userBan = await interaction.guild.bans.fetch(userId); + } catch (err: unknown) { + // log.debug(F, `Error fetching ban: ${err}`); + } + if (userBan.guild) { + actionRow.addComponents( + modButtonUnBan(userId), + ); + banVerb = 'un-ban'; + } else { + actionRow.addComponents( + modButtonBan(userId), + ); + } + actionRow.addComponents( - modButtonBan(userId), + modButtonInfo(userId), ); } - actionRow.addComponents( - modButtonInfo(userId), - ); - - if (isReport(command)) { + if (isReport(command) && showModButtons) { modEmbedObj.setDescription(stripIndents` User ID '${userId}' is not in the guild, but I can still Note or ${banVerb} them!`); } else { log.debug(F, '[modResponse] generating user info'); const modlogEmbed = await userInfoEmbed(actor, targetObj, targetData, command, showModButtons); log.debug(F, `modlogEmbed: ${JSON.stringify(modlogEmbed, null, 2)}`); - actionRow.setComponents([ - modButtonInfo(userId), - ]); + if (showModButtons) { + actionRow.setComponents([ + modButtonInfo(userId), + ]); + } else { + actionRow.setComponents([ + modButtonReport(userId), + ]); + } if (isBan(command)) { actionRow.addComponents( modButtonUnBan(userId), @@ -1332,7 +1339,7 @@ export async function moderate( } let description = ''; - if (!isNote(command) && !isReport(command)) { + if (command !== 'NOTE' && command !== 'REPORT') { description = modalInt.fields.getTextInputValue('description'); } let internalNote = modalInt.fields.getTextInputValue('internalNote'); @@ -1699,7 +1706,7 @@ export async function moderate( > ${modalInt.fields.getTextInputValue('internalNote')} Message sent to user: - > ${modalInt.fields.getTextInputValue('description')}`, + > ${command !== 'NOTE' && command !== 'REPORT' ? modalInt.fields.getTextInputValue('description') : ''}`, inline: true, }, ); @@ -1864,11 +1871,7 @@ export async function modModal( .setCustomId('internalNote'); try { - // Ensure the label text is within the limit - const label = `Why are you ${verb} ${target}?`; - const truncatedLabelText = label.length > 45 ? `${label.substring(0, 41)}...?` : label; - - modalInputComponent.setLabel(truncatedLabelText); + modalInputComponent.setLabel(`Why are you ${verb} ${target}?`); } catch (err) { log.error(F, `Error: ${err}`); log.error(F, `Verb: ${verb}, Target: ${target}`); @@ -1952,6 +1955,20 @@ export async function modModal( return; } await i.deferReply({ ephemeral: true }); + try { + if (command === 'REPORT' || command === 'NOTE') { + await moderate(interaction, i); + const reportResponseEmbed = embedTemplate() + .setColor(command === 'REPORT' ? Colors.Yellow : Colors.Green) + .setTitle(command === 'REPORT' ? 'Your report was sent!' : 'Your note was added!') + .setDescription(command === 'REPORT' ? 'The moderators have received your report and will look into it. Thanks!' : `Your note was successfully added to ${target}'s thread.`); + await i.editReply({ + embeds: [reportResponseEmbed], + }); + } + } catch (err) { + log.info(F, `[modModal ModalSubmitInteraction]: ${err}`); + } // const internalNote = i.fields.getTextInputValue('internalNote'); // eslint-disable-line // // Only these commands actually have the description input, so only pull it if it exists @@ -2043,7 +2060,9 @@ export async function modModal( // log.error(F, `Error: ${err}`); } } - await i.editReply(await moderate(interaction, i)); + if (command !== 'REPORT' && command !== 'NOTE') { + await i.editReply(await moderate(interaction, i)); + } }) .catch(async err => { // log.error(F, `Error: ${JSON.stringify(err as DiscordErrorData, null, 2)}`); From 722c2beb2b6bd64141b6a3ed3fb4433cc7f2aba8 Mon Sep 17 00:00:00 2001 From: Shadow Date: Wed, 7 Aug 2024 17:43:11 -0400 Subject: [PATCH 2/2] fix(moderate): re-add label length fix --- src/discord/commands/guild/d.moderate.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/discord/commands/guild/d.moderate.ts b/src/discord/commands/guild/d.moderate.ts index bca2624ed..eca082147 100644 --- a/src/discord/commands/guild/d.moderate.ts +++ b/src/discord/commands/guild/d.moderate.ts @@ -1871,7 +1871,11 @@ export async function modModal( .setCustomId('internalNote'); try { - modalInputComponent.setLabel(`Why are you ${verb} ${target}?`); + // Ensure the label text is within the limit + const label = `Why are you ${verb} ${target}?`; + const truncatedLabelText = label.length > 45 ? `${label.substring(0, 41)}...?` : label; + + modalInputComponent.setLabel(truncatedLabelText); } catch (err) { log.error(F, `Error: ${err}`); log.error(F, `Verb: ${verb}, Target: ${target}`);