Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread decision fixes #332

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions discord-scripts/thread-management/check-thread-archiving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const { user, guild } = interaction

if (!guild) {
return user.username
}
const member = await guild.members.fetch(user.id)
return member.nickname || user.username
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return member.nickname || user.username
return member.nickname ?? user.username

}

async function requestFollowUpAction(
thread: ThreadChannel<boolean>,
interaction: ButtonInteraction,
followUpRequester: GuildMember | APIInteractionGuildMember | null,
Expand All @@ -52,6 +63,10 @@ function requestFollowUpAction(
robot?: Robot,
) {
const requestingUserId = followUpRequester?.user.id
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
Expand All @@ -63,7 +78,7 @@ function requestFollowUpAction(
.followUp({
content: `Thanks ${userMention(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop the user mention here, since you're just mentioning yourself?

requestingUserId,
)}, please ${requestedAction} this thread or it will be archived in 24 hours ❤️`,
)}, please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R> ❤️)`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)}, please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R> ❤️)`,
)}, please ${requestedAction} this thread or it will be archived in <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R>) ❤️`,

ephemeral: true,
})
.catch((error) => {
Expand All @@ -75,7 +90,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 <t:${followUpDeadline}:F> (<t:${followUpDeadline}:R>) - ❤️ Love, ${nickname}`,
})
.catch((error) => {
robot?.logger.info("Failed to send message in thread:", error)
Expand All @@ -99,10 +114,17 @@ const threadActions: {
emoji: "☑️",
extendAutoArchive: false,
handler: async (thread, interaction) => {
const nickname = await getNickname(interaction)
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 ${nickname}`,
components: [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does sending this interaction unarchive the thread?

})
thread.setArchived(true)
},
},
"check-thread-archiving-task-button": {
Expand All @@ -111,7 +133,6 @@ const threadActions: {
extendAutoArchive: true,
handler: async (thread, interaction) => {
const posterSelectId = `task-poster-select-${interaction.id}`

await interaction.reply({
ephemeral: true,
content:
Expand Down Expand Up @@ -147,6 +168,8 @@ const threadActions: {
"capture the task(s) associated with",
userIdToTag,
)

await interaction.message.delete()
},
},
"check-thread-archiving-status-button": {
Expand All @@ -155,7 +178,6 @@ const threadActions: {
extendAutoArchive: false,
handler: async (thread, interaction) => {
const posterSelectId = `status-poster-select-${interaction.id}`

await interaction.reply({
ephemeral: true,
content:
Expand Down Expand Up @@ -189,9 +211,11 @@ const threadActions: {
thread,
interaction,
interaction.member,
"capture the task(s) associated with",
"post a status associated with",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHOMP

userIdToTag,
)

await interaction.message.delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we always delete the interaction message, should we do it in the caller?

},
},
"check-thread-archiving-pending-decision-button": {
Expand All @@ -200,7 +224,6 @@ const threadActions: {
extendAutoArchive: true,
handler: async (thread, interaction) => {
const posterSelectId = `decision-poster-select-${interaction.id}`

await interaction.reply({
ephemeral: true,
content:
Expand Down Expand Up @@ -234,9 +257,11 @@ const threadActions: {
thread,
interaction,
interaction.member,
"capture the task(s) associated with",
"make a decision for",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whomp again lolol.

userIdToTag,
)

await interaction.message.delete()
},
},
}
Expand Down
Loading