Skip to content

Commit a51af75

Browse files
committed
fix: prevent threadStaleCheck from touching already solved threads
1 parent 228b431 commit a51af75

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/cron/threadCheck.ts renamed to src/cron/threadStaleCheck.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type { Client } from 'discord.js'
22
import { CronJob } from 'cron'
33
import { createDefaultEmbed } from '@/utils'
44

5-
export function startThreadCheckCron(client: Client) {
5+
export function startThreadStaleCheckCron(client: Client) {
66
const debug = process.env.CRON_DEBUG_MODE === '1'
77

88
const job = new CronJob(
99
debug ? '*/10 * * * * *' : '0 * * * *', // run every hour on prod, every 10 sec on debug
1010
async function () {
11-
console.log('[Cron] Checking inactive threads...')
11+
console.log('[Cron][ThreadStaleCheck] Checking inactive threads...')
1212

1313
for (const [, guild] of client.guilds.cache) {
1414
try {
@@ -19,7 +19,18 @@ export function startThreadCheckCron(client: Client) {
1919
if (thread.parentId !== process.env.COMMUNITY_SUPPORT_FORUM_ID) continue
2020
// Ignore threads that are pinned
2121
if (thread.flags.has('Pinned')) {
22-
debug && console.log(`[Debug][Cron] Skipping thread ${thread.id} is pinned`)
22+
debug &&
23+
console.log(
24+
`[Debug][Cron][ThreadStaleCheck] Skipping thread ${thread.id} is pinned`,
25+
)
26+
continue
27+
}
28+
// Ignore threads that are already solved
29+
if (thread.appliedTags.includes(process.env.COMMUNITY_SUPPORT_FORUM_SOLVED_TAG_ID!)) {
30+
debug &&
31+
console.log(
32+
`[Debug][Cron][ThreadStaleCheck] Skipping thread ${thread.id} is solved`,
33+
)
2334
continue
2435
}
2536

@@ -36,7 +47,9 @@ export function startThreadCheckCron(client: Client) {
3647

3748
if (inactiveFor > archiveThreshold) {
3849
debug &&
39-
console.log(`[Debug][Cron] Marking inactive thread as solved: ${thread.name}`)
50+
console.log(
51+
`[Debug][Cron][ThreadStaleCheck] Marking inactive thread as solved: ${thread.name}`,
52+
)
4053

4154
const embed = createDefaultEmbed({
4255
title: ':white_check_mark: Thread archived',

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createCommandRegistry, deployCommands, tryJoinThread } from '@/utils'
1010
import { db } from './db'
1111
import { createMessageHandlers, createReactionHandlers } from './types/listeners'
1212
import { startWebServer } from './web'
13-
import { startThreadCheckCron } from '@/cron/threadCheck'
13+
import { startThreadStaleCheckCron } from '@/cron/threadStaleCheck'
1414

1515
const DEBUG_COMMAND_IDS = process.argv.includes('--debug-command-ids')
1616

@@ -80,7 +80,7 @@ client.once(Events.ClientReady, async (readyClient) => {
8080
}
8181

8282
// TODO: Change this to more universal src/cron/index.ts
83-
startThreadCheckCron(client)
83+
startThreadStaleCheckCron(client)
8484
})
8585

8686
// Auto-join newly created threads in #community-support

0 commit comments

Comments
 (0)