Skip to content

Commit ac215c4

Browse files
committed
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.
1 parent 72e9099 commit ac215c4

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

discord-scripts/thread-management/check-thread-archiving.ts

+19-28
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ const THREAD_CHECK_CADENCE = 12 * HOUR // 12 * HOUR
4343
* A helper to request follow-up action on a thread based on the id of the user
4444
* who will follow up and the initial requester of follow-up action.
4545
*/
46-
function requestFollowUpAction(
46+
47+
const getNickname = async (interaction: ButtonInteraction): Promise<string> => {
48+
const { user, guild } = interaction
49+
50+
if (!guild) {
51+
return user.username
52+
}
53+
const member = await guild.members.fetch(user.id)
54+
return member.nickname || user.username
55+
}
56+
57+
async function requestFollowUpAction(
4758
thread: ThreadChannel<boolean>,
4859
interaction: ButtonInteraction,
4960
followUpRequester: GuildMember | APIInteractionGuildMember | null,
@@ -55,6 +66,8 @@ function requestFollowUpAction(
5566
const currentTime = Date.now()
5667
const followUpDeadline = Math.floor((currentTime + 24 * HOUR) / 1000)
5768

69+
const nickname = await getNickname(interaction)
70+
5871
if (followUpUserId === requestingUserId) {
5972
// If the user designates themselves, delete the initial bot message to remove the dropdown
6073
interaction.deleteReply().catch((error) => {
@@ -65,7 +78,7 @@ function requestFollowUpAction(
6578
.followUp({
6679
content: `Thanks ${userMention(
6780
requestingUserId,
68-
)}, please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R> ❤️`,
81+
)}, please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R> ❤️)`,
6982
ephemeral: true,
7083
})
7184
.catch((error) => {
@@ -77,7 +90,7 @@ function requestFollowUpAction(
7790
.send({
7891
content: `${userMention(
7992
followUpUserId,
80-
)} please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R> ❤️`,
93+
)} please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R>) - ❤️ Love, ${nickname}`,
8194
})
8295
.catch((error) => {
8396
robot?.logger.info("Failed to send message in thread:", error)
@@ -89,16 +102,6 @@ function requestFollowUpAction(
89102
}
90103
}
91104

92-
const getNickname = async (interaction: ButtonInteraction): Promise<string> => {
93-
const { user, guild } = interaction
94-
95-
if (!guild) {
96-
return user.username
97-
}
98-
const member = await guild.members.fetch(user.id)
99-
return member.nickname || user.username
100-
}
101-
102105
const threadActions: {
103106
[action: string]: Pick<APIButtonComponentWithCustomId, "label"> & {
104107
handler: (thread: ThreadChannel, interaction: ButtonInteraction) => void
@@ -130,7 +133,6 @@ const threadActions: {
130133
extendAutoArchive: true,
131134
handler: async (thread, interaction) => {
132135
const posterSelectId = `task-poster-select-${interaction.id}`
133-
const nickname = await getNickname(interaction)
134136
await interaction.reply({
135137
ephemeral: true,
136138
content:
@@ -167,10 +169,7 @@ const threadActions: {
167169
userIdToTag,
168170
)
169171

170-
await interaction.message.edit({
171-
content: `${interaction.message.content}\n\n🔲 **Task capture requested** by ${nickname}`,
172-
components: [],
173-
})
172+
await interaction.message.delete()
174173
},
175174
},
176175
"check-thread-archiving-status-button": {
@@ -179,7 +178,6 @@ const threadActions: {
179178
extendAutoArchive: false,
180179
handler: async (thread, interaction) => {
181180
const posterSelectId = `status-poster-select-${interaction.id}`
182-
const nickname = await getNickname(interaction)
183181
await interaction.reply({
184182
ephemeral: true,
185183
content:
@@ -217,10 +215,7 @@ const threadActions: {
217215
userIdToTag,
218216
)
219217

220-
await interaction.message.edit({
221-
content: `${interaction.message.content}\n\n✍️ **Status requested** by ${nickname}`,
222-
components: [],
223-
})
218+
await interaction.message.delete()
224219
},
225220
},
226221
"check-thread-archiving-pending-decision-button": {
@@ -229,7 +224,6 @@ const threadActions: {
229224
extendAutoArchive: true,
230225
handler: async (thread, interaction) => {
231226
const posterSelectId = `decision-poster-select-${interaction.id}`
232-
const nickname = await getNickname(interaction)
233227
await interaction.reply({
234228
ephemeral: true,
235229
content:
@@ -267,10 +261,7 @@ const threadActions: {
267261
userIdToTag,
268262
)
269263

270-
await interaction.message.edit({
271-
content: `${interaction.message.content}\n\n🫵 **Decision requested** by ${nickname}`,
272-
components: [],
273-
})
264+
await interaction.message.delete()
274265
},
275266
},
276267
}

0 commit comments

Comments
 (0)