From a4912660fa887ad93d3635fd6c4af559ad142431 Mon Sep 17 00:00:00 2001 From: Kristofer Date: Fri, 15 Dec 2023 11:50:01 +0100 Subject: [PATCH] Hide receipient in Discord feed when DISCORD_BOT_PRAISE_NOTIFICATIONS_ENABLED is disabled --- .../src/utils/embeds/praiseSuccessEmbed.ts | 14 ++++++++++---- packages/discord-bot/src/utils/givePraise.ts | 13 +++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/discord-bot/src/utils/embeds/praiseSuccessEmbed.ts b/packages/discord-bot/src/utils/embeds/praiseSuccessEmbed.ts index 298ceed7f..ef34e70dc 100644 --- a/packages/discord-bot/src/utils/embeds/praiseSuccessEmbed.ts +++ b/packages/discord-bot/src/utils/embeds/praiseSuccessEmbed.ts @@ -5,11 +5,17 @@ export const praiseSuccessEmbed = async ( user: User, receivers: string[], reason: string, - host: string + host: string, + praiseNotificationsEnabled = true ): Promise => { - const msg = ((await getSetting('PRAISE_SUCCESS_MESSAGE', host)) as string) - .replace('{@receivers}', `${receivers.join(', ')}`) - .replace('{reason}', reason); + let msg = (await getSetting('PRAISE_SUCCESS_MESSAGE', host)) as string; + + if (!praiseNotificationsEnabled) { + msg = msg.replace('{@receivers}', '[HIDDEN]'); + } else { + msg = msg.replace('{@receivers}', `${receivers.join(', ')}`); + } + msg = msg.replace('{reason}', reason); const embed = new EmbedBuilder().setColor(0xe6007e).setDescription(msg); return embed; diff --git a/packages/discord-bot/src/utils/givePraise.ts b/packages/discord-bot/src/utils/givePraise.ts index 98a951715..a900af912 100644 --- a/packages/discord-bot/src/utils/givePraise.ts +++ b/packages/discord-bot/src/utils/givePraise.ts @@ -69,6 +69,11 @@ export const givePraise = async ( }) ); + const praiseNotificationsEnabled = (await getSetting( + 'DISCORD_BOT_PRAISE_NOTIFICATIONS_ENABLED', + host + )) as boolean; + let praiseItems: Praise[] = []; if (receivers.length !== 0) { await interaction.editReply({ @@ -78,7 +83,8 @@ export const givePraise = async ( interaction.user, validReceiverIds.map((id) => `<@!${id}>`), reason, - host + host, + praiseNotificationsEnabled ), ], components: [], @@ -105,11 +111,6 @@ export const givePraise = async ( ? process.env?.FRONTEND_URL || 'undefined:/' : `https://${host}`; - const praiseNotificationsEnabled = (await getSetting( - 'DISCORD_BOT_PRAISE_NOTIFICATIONS_ENABLED', - host - )) as boolean; - if (praiseNotificationsEnabled) { await Promise.all( praiseItems.map(async (praise) => {