Skip to content

Commit

Permalink
Re-enable setAutoArchiveDuration + isWeekend check (#333)
Browse files Browse the repository at this point in the history
### Notes
Let's re-enable the `setAutoArchiveDuration` to 24 hours / `OneDay`
after the initial warning message is sent. This one also adds a
`isWeekend` check so that we don't send thread decision reminders during
the weekend days.
  • Loading branch information
Shadowfiend authored Jan 28, 2025
2 parents 887f442 + 38a03b4 commit 35e6bd1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions discord-scripts/thread-management/check-thread-archiving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ const THREAD_CHECK_CADENCE = 12 * HOUR // 12 * HOUR
// Use a ThreadAutoArchiveDuration as we'll still lean on Discord to
// auto-archive after issuing the warning, so we want the value to be
// one that we can update auto-archiving to.
// const AUTO_ARCHIVE_WARNING_LEAD_MINUTES: ThreadAutoArchiveDuration = ThreadAutoArchiveDuration.OneDay
const AUTO_ARCHIVE_WARNING_LEAD_MINUTES: ThreadAutoArchiveDuration =
ThreadAutoArchiveDuration.OneDay

// Let's grab if it's the weekend, 0 = sunday, 6 = saturday
const isWeekend = (): boolean => [0, 6].includes(new Date().getDay())

/**
* A helper to request follow-up action on a thread based on the id of the user
Expand Down Expand Up @@ -369,6 +373,11 @@ async function checkThreadStatus(
robot: Robot,
discordClient: Client,
): Promise<void> {
if (isWeekend()) {
robot.logger.info("Skipping thread status checks on the weekend.")
return
}

const threadMetadataByThreadId = getAllThreadMetadata(robot.brain)

Object.entries(threadMetadataByThreadId)
Expand Down Expand Up @@ -474,7 +483,8 @@ async function checkThreadStatus(
},
],
})

// Let's add back setting the thread autoArchive to 24hr after the message is sent
await thread.setAutoArchiveDuration(AUTO_ARCHIVE_WARNING_LEAD_MINUTES)
// Use robot brain to store the warning event data
robot.brain.set(warningKey, warningMessage.id)
robot.logger.info(
Expand Down

0 comments on commit 35e6bd1

Please sign in to comment.