From 819d09a7a85746e2c27be074a23d9e9cd97466d8 Mon Sep 17 00:00:00 2001 From: Erik Zuuring Date: Tue, 3 Dec 2024 13:42:36 +0200 Subject: [PATCH 1/5] Thread decision fixes ### Notes This resolves a few issues with the thread decisions: - Let's make sure when an interaction is pressed. the text output corresponds to that action (i.e status update) - We edit the original interaction to remove the buttons when clicked as well as marked with the action taken, and by who. --- .../check-thread-archiving.ts | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/discord-scripts/thread-management/check-thread-archiving.ts b/discord-scripts/thread-management/check-thread-archiving.ts index 272679ee..0739592d 100644 --- a/discord-scripts/thread-management/check-thread-archiving.ts +++ b/discord-scripts/thread-management/check-thread-archiving.ts @@ -99,10 +99,19 @@ const threadActions: { emoji: "☑️", extendAutoArchive: false, handler: async (thread, interaction) => { + const user = interaction.user await interaction.reply({ content: "Sounds like this thread is ready to archive, doing that now!", + ephemeral: true, + }) + await thread.setArchived(true) + + await interaction.message.edit({ + content: `${interaction.message.content}\n\n☑️ **Archived** by ${userMention( + user.id, + )}`, + components: [], }) - thread.setArchived(true) }, }, "check-thread-archiving-task-button": { @@ -147,6 +156,13 @@ const threadActions: { "capture the task(s) associated with", userIdToTag, ) + + await interaction.message.edit({ + content: `${interaction.message.content}\n\n🔲 **Task capture requested** by ${userMention( + interaction.user.id, + )}`, + components: [], + }) }, }, "check-thread-archiving-status-button": { @@ -189,9 +205,16 @@ const threadActions: { thread, interaction, interaction.member, - "capture the task(s) associated with", + "post a status associated with", userIdToTag, ) + + await interaction.message.edit({ + content: `${interaction.message.content}\n\n✍️ **Status requested** by ${userMention( + interaction.user.id, + )}`, + components: [], + }) }, }, "check-thread-archiving-pending-decision-button": { @@ -234,9 +257,16 @@ const threadActions: { thread, interaction, interaction.member, - "capture the task(s) associated with", + "make a decision for", userIdToTag, ) + + await interaction.message.edit({ + content: `${interaction.message.content}\n\n🫵 **Decision requested** by ${userMention( + interaction.user.id, + )}`, + components: [], + }) }, }, } From 7957d8b89e46b726c5edacfe6d11e20c3825af8c Mon Sep 17 00:00:00 2001 From: Erik Zuuring Date: Tue, 3 Dec 2024 13:48:47 +0200 Subject: [PATCH 2/5] Prettier fixes --- .../check-thread-archiving.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/discord-scripts/thread-management/check-thread-archiving.ts b/discord-scripts/thread-management/check-thread-archiving.ts index 0739592d..3968146b 100644 --- a/discord-scripts/thread-management/check-thread-archiving.ts +++ b/discord-scripts/thread-management/check-thread-archiving.ts @@ -99,7 +99,7 @@ const threadActions: { emoji: "☑️", extendAutoArchive: false, handler: async (thread, interaction) => { - const user = interaction.user + const { user } = interaction await interaction.reply({ content: "Sounds like this thread is ready to archive, doing that now!", ephemeral: true, @@ -107,9 +107,9 @@ const threadActions: { await thread.setArchived(true) await interaction.message.edit({ - content: `${interaction.message.content}\n\n☑️ **Archived** by ${userMention( - user.id, - )}`, + content: `${ + interaction.message.content + }\n\n☑️ **Archived** by ${userMention(user.id)}`, components: [], }) }, @@ -158,7 +158,9 @@ const threadActions: { ) await interaction.message.edit({ - content: `${interaction.message.content}\n\n🔲 **Task capture requested** by ${userMention( + content: `${ + interaction.message.content + }\n\n🔲 **Task capture requested** by ${userMention( interaction.user.id, )}`, components: [], @@ -210,9 +212,9 @@ const threadActions: { ) await interaction.message.edit({ - content: `${interaction.message.content}\n\n✍️ **Status requested** by ${userMention( - interaction.user.id, - )}`, + content: `${ + interaction.message.content + }\n\n✍️ **Status requested** by ${userMention(interaction.user.id)}`, components: [], }) }, @@ -262,9 +264,9 @@ const threadActions: { ) await interaction.message.edit({ - content: `${interaction.message.content}\n\n🫵 **Decision requested** by ${userMention( - interaction.user.id, - )}`, + content: `${ + interaction.message.content + }\n\n🫵 **Decision requested** by ${userMention(interaction.user.id)}`, components: [], }) }, From e2c59a164b04b55b1908557fa538ff627f6ca762 Mon Sep 17 00:00:00 2001 From: Erik Zuuring Date: Tue, 3 Dec 2024 16:30:23 +0200 Subject: [PATCH 3/5] Add `autoArchiveDuration` & `nickname` This adds the threads `autoArchiveDuration` to the messages triggered by the interactions as well as setting the nickname instead of tagging the user. --- .../check-thread-archiving.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/discord-scripts/thread-management/check-thread-archiving.ts b/discord-scripts/thread-management/check-thread-archiving.ts index 3968146b..918339bb 100644 --- a/discord-scripts/thread-management/check-thread-archiving.ts +++ b/discord-scripts/thread-management/check-thread-archiving.ts @@ -52,6 +52,8 @@ function requestFollowUpAction( robot?: Robot, ) { const requestingUserId = followUpRequester?.user.id + const currentTime = Date.now() + const followUpDeadline = Math.floor((currentTime + 24 * HOUR) / 1000) if (followUpUserId === requestingUserId) { // If the user designates themselves, delete the initial bot message to remove the dropdown @@ -63,7 +65,7 @@ function requestFollowUpAction( .followUp({ content: `Thanks ${userMention( requestingUserId, - )}, please ${requestedAction} this thread or it will be archived in 24 hours ❤️`, + )}, please ${requestedAction} this thread or it will be archived in ( ❤️`, ephemeral: true, }) .catch((error) => { @@ -75,7 +77,7 @@ function requestFollowUpAction( .send({ content: `${userMention( followUpUserId, - )} please ${requestedAction} this thread or it will be archived in 24 hours ❤️`, + )} please ${requestedAction} this thread or it will be archived in ( ❤️`, }) .catch((error) => { robot?.logger.info("Failed to send message in thread:", error) @@ -87,6 +89,16 @@ function requestFollowUpAction( } } +const getNickname = async (interaction: ButtonInteraction): Promise => { + const { user, guild } = interaction + + if (!guild) { + return user.username + } + const member = await guild.members.fetch(user.id) + return member.nickname || user.username +} + const threadActions: { [action: string]: Pick & { handler: (thread: ThreadChannel, interaction: ButtonInteraction) => void @@ -99,7 +111,7 @@ const threadActions: { emoji: "☑️", extendAutoArchive: false, handler: async (thread, interaction) => { - const { user } = interaction + const nickname = await getNickname(interaction) await interaction.reply({ content: "Sounds like this thread is ready to archive, doing that now!", ephemeral: true, @@ -109,7 +121,7 @@ const threadActions: { await interaction.message.edit({ content: `${ interaction.message.content - }\n\n☑️ **Archived** by ${userMention(user.id)}`, + }\n\n☑️ **Archived** by ${nickname}`, components: [], }) }, @@ -120,7 +132,7 @@ const threadActions: { extendAutoArchive: true, handler: async (thread, interaction) => { const posterSelectId = `task-poster-select-${interaction.id}` - + const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -160,9 +172,7 @@ const threadActions: { await interaction.message.edit({ content: `${ interaction.message.content - }\n\n🔲 **Task capture requested** by ${userMention( - interaction.user.id, - )}`, + }\n\n🔲 **Task capture requested** by ${nickname}`, components: [], }) }, @@ -173,7 +183,7 @@ const threadActions: { extendAutoArchive: false, handler: async (thread, interaction) => { const posterSelectId = `status-poster-select-${interaction.id}` - + const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -214,7 +224,7 @@ const threadActions: { await interaction.message.edit({ content: `${ interaction.message.content - }\n\n✍️ **Status requested** by ${userMention(interaction.user.id)}`, + }\n\n✍️ **Status requested** by ${nickname}`, components: [], }) }, @@ -225,7 +235,7 @@ const threadActions: { extendAutoArchive: true, handler: async (thread, interaction) => { const posterSelectId = `decision-poster-select-${interaction.id}` - + const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -266,7 +276,7 @@ const threadActions: { await interaction.message.edit({ content: `${ interaction.message.content - }\n\n🫵 **Decision requested** by ${userMention(interaction.user.id)}`, + }\n\n🫵 **Decision requested** by ${nickname}`, components: [], }) }, From 72e909970b05a377be380074c1570c3eca783697 Mon Sep 17 00:00:00 2001 From: Erik Zuuring Date: Wed, 4 Dec 2024 10:21:32 +0200 Subject: [PATCH 4/5] Fix lint error --- .../thread-management/check-thread-archiving.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/discord-scripts/thread-management/check-thread-archiving.ts b/discord-scripts/thread-management/check-thread-archiving.ts index 918339bb..0ba726e4 100644 --- a/discord-scripts/thread-management/check-thread-archiving.ts +++ b/discord-scripts/thread-management/check-thread-archiving.ts @@ -119,9 +119,7 @@ const threadActions: { await thread.setArchived(true) await interaction.message.edit({ - content: `${ - interaction.message.content - }\n\n☑️ **Archived** by ${nickname}`, + content: `${interaction.message.content}\n\n☑️ **Archived** by ${nickname}`, components: [], }) }, @@ -170,9 +168,7 @@ const threadActions: { ) await interaction.message.edit({ - content: `${ - interaction.message.content - }\n\n🔲 **Task capture requested** by ${nickname}`, + content: `${interaction.message.content}\n\n🔲 **Task capture requested** by ${nickname}`, components: [], }) }, @@ -222,9 +218,7 @@ const threadActions: { ) await interaction.message.edit({ - content: `${ - interaction.message.content - }\n\n✍️ **Status requested** by ${nickname}`, + content: `${interaction.message.content}\n\n✍️ **Status requested** by ${nickname}`, components: [], }) }, @@ -274,9 +268,7 @@ const threadActions: { ) await interaction.message.edit({ - content: `${ - interaction.message.content - }\n\n🫵 **Decision requested** by ${nickname}`, + content: `${interaction.message.content}\n\n🫵 **Decision requested** by ${nickname}`, components: [], }) }, From ac215c4491cdc66d96f3e02d445c06ba7b586322 Mon Sep 17 00:00:00 2001 From: Erik Zuuring Date: Thu, 5 Dec 2024 14:03:51 +0200 Subject: [PATCH 5/5] Tweak decision behavior This changes the flow so that we remove the original button interaction when an action is taken then also send that in a message to the decision taker with a nickname from the person who made the interaction. --- .../check-thread-archiving.ts | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/discord-scripts/thread-management/check-thread-archiving.ts b/discord-scripts/thread-management/check-thread-archiving.ts index 0ba726e4..16eeff62 100644 --- a/discord-scripts/thread-management/check-thread-archiving.ts +++ b/discord-scripts/thread-management/check-thread-archiving.ts @@ -43,7 +43,18 @@ const THREAD_CHECK_CADENCE = 12 * HOUR // 12 * HOUR * A helper to request follow-up action on a thread based on the id of the user * who will follow up and the initial requester of follow-up action. */ -function requestFollowUpAction( + +const getNickname = async (interaction: ButtonInteraction): Promise => { + const { user, guild } = interaction + + if (!guild) { + return user.username + } + const member = await guild.members.fetch(user.id) + return member.nickname || user.username +} + +async function requestFollowUpAction( thread: ThreadChannel, interaction: ButtonInteraction, followUpRequester: GuildMember | APIInteractionGuildMember | null, @@ -55,6 +66,8 @@ function requestFollowUpAction( const currentTime = Date.now() const followUpDeadline = Math.floor((currentTime + 24 * HOUR) / 1000) + const nickname = await getNickname(interaction) + if (followUpUserId === requestingUserId) { // If the user designates themselves, delete the initial bot message to remove the dropdown interaction.deleteReply().catch((error) => { @@ -65,7 +78,7 @@ function requestFollowUpAction( .followUp({ content: `Thanks ${userMention( requestingUserId, - )}, please ${requestedAction} this thread or it will be archived in ( ❤️`, + )}, please ${requestedAction} this thread or it will be archived in ( ❤️)`, ephemeral: true, }) .catch((error) => { @@ -77,7 +90,7 @@ function requestFollowUpAction( .send({ content: `${userMention( followUpUserId, - )} please ${requestedAction} this thread or it will be archived in ( ❤️`, + )} please ${requestedAction} this thread or it will be archived in () - ❤️ Love, ${nickname}`, }) .catch((error) => { robot?.logger.info("Failed to send message in thread:", error) @@ -89,16 +102,6 @@ function requestFollowUpAction( } } -const getNickname = async (interaction: ButtonInteraction): Promise => { - const { user, guild } = interaction - - if (!guild) { - return user.username - } - const member = await guild.members.fetch(user.id) - return member.nickname || user.username -} - const threadActions: { [action: string]: Pick & { handler: (thread: ThreadChannel, interaction: ButtonInteraction) => void @@ -130,7 +133,6 @@ const threadActions: { extendAutoArchive: true, handler: async (thread, interaction) => { const posterSelectId = `task-poster-select-${interaction.id}` - const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -167,10 +169,7 @@ const threadActions: { userIdToTag, ) - await interaction.message.edit({ - content: `${interaction.message.content}\n\n🔲 **Task capture requested** by ${nickname}`, - components: [], - }) + await interaction.message.delete() }, }, "check-thread-archiving-status-button": { @@ -179,7 +178,6 @@ const threadActions: { extendAutoArchive: false, handler: async (thread, interaction) => { const posterSelectId = `status-poster-select-${interaction.id}` - const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -217,10 +215,7 @@ const threadActions: { userIdToTag, ) - await interaction.message.edit({ - content: `${interaction.message.content}\n\n✍️ **Status requested** by ${nickname}`, - components: [], - }) + await interaction.message.delete() }, }, "check-thread-archiving-pending-decision-button": { @@ -229,7 +224,6 @@ const threadActions: { extendAutoArchive: true, handler: async (thread, interaction) => { const posterSelectId = `decision-poster-select-${interaction.id}` - const nickname = await getNickname(interaction) await interaction.reply({ ephemeral: true, content: @@ -267,10 +261,7 @@ const threadActions: { userIdToTag, ) - await interaction.message.edit({ - content: `${interaction.message.content}\n\n🫵 **Decision requested** by ${nickname}`, - components: [], - }) + await interaction.message.delete() }, }, }