@@ -3,8 +3,10 @@ import { CronJob } from 'cron'
33import { createDefaultEmbed } from '@/utils'
44
55export function startThreadCheckCron ( client : Client ) {
6+ const debug = process . env . CRON_DEBUG_MODE === '1'
7+
68 const job = new CronJob (
7- ' 0 * * * *', // run every hour
9+ debug ? '*/10 * * * * *' : ' 0 * * * *', // run every hour on prod, every 10 sec on debug
810 async function ( ) {
911 console . log ( '[Cron] Checking inactive threads...' )
1012
@@ -13,7 +15,13 @@ export function startThreadCheckCron(client: Client) {
1315 const active = await guild . channels . fetchActiveThreads ( )
1416
1517 for ( const [ , thread ] of active . threads ) {
18+ // Ignore threads that are not in #community-support
1619 if ( thread . parentId !== process . env . COMMUNITY_SUPPORT_FORUM_ID ) continue
20+ // Ignore threads that are pinned
21+ if ( thread . flags . has ( 'Pinned' ) ) {
22+ debug && console . log ( `[Debug][Cron] Skipping thread ${ thread . id } is pinned` )
23+ continue
24+ }
1725
1826 // Last message
1927 const lastMessage = thread . lastMessageId
@@ -23,16 +31,17 @@ export function startThreadCheckCron(client: Client) {
2331 const inactiveFor = lastMessage ? Date . now ( ) - lastMessage . createdTimestamp : Infinity
2432
2533 // thresholds
26- const warnThreshold = 1000 * 60 * 60 * 24 * 2 // 2 days
27- const archiveThreshold = 1000 * 60 * 60 * 24 * 4 // 4 days
34+ const warnThreshold = debug ? 1000 * 15 : 1000 * 60 * 60 * 24 * 2 // 2 days (prod), 15 sec (debug)
35+ const archiveThreshold = debug ? 1000 * 30 : 1000 * 60 * 60 * 24 * 4 // 4 days (prod), 30 sec (debug)
2836
2937 if ( inactiveFor > archiveThreshold ) {
30- console . log ( `[Cron] Marking inactive thread as solved: ${ thread . name } ` )
38+ debug &&
39+ console . log ( `[Debug][Cron] Marking inactive thread as solved: ${ thread . name } ` )
3140
3241 const embed = createDefaultEmbed ( {
33- title : ':lock : Thread archived' ,
34- description : 'This thread has been archived due to inactivity.' ,
35- } ) . setColor ( 0xffa347 )
42+ title : ':white_check_mark : Thread archived' ,
43+ description : 'This thread was resolved automatically after inactivity.' ,
44+ } )
3645
3746 await thread . send ( { embeds : [ embed ] } )
3847 await thread
@@ -53,7 +62,8 @@ export function startThreadCheckCron(client: Client) {
5362 )
5463
5564 if ( ! alreadyWarned ) {
56- console . log ( `[Cron] Warning in thread: ${ thread . name } ` )
65+ debug &&
66+ console . log ( `[Debug][Cron] Sending stale warning to the thread ${ thread . id } ` )
5767 await thread . send ( warningMsg ) . catch ( ( ) => { } )
5868 }
5969 }
0 commit comments