@@ -3,8 +3,10 @@ import { CronJob } from 'cron'
3
3
import { createDefaultEmbed } from '@/utils'
4
4
5
5
export function startThreadCheckCron ( client : Client ) {
6
+ const debug = process . env . CRON_DEBUG_MODE === '1'
7
+
6
8
const job = new CronJob (
7
- ' 0 * * * *', // run every hour
9
+ debug ? '*/10 * * * * *' : ' 0 * * * *', // run every hour on prod, every 10 sec on debug
8
10
async function ( ) {
9
11
console . log ( '[Cron] Checking inactive threads...' )
10
12
@@ -13,7 +15,13 @@ export function startThreadCheckCron(client: Client) {
13
15
const active = await guild . channels . fetchActiveThreads ( )
14
16
15
17
for ( const [ , thread ] of active . threads ) {
18
+ // Ignore threads that are not in #community-support
16
19
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
+ }
17
25
18
26
// Last message
19
27
const lastMessage = thread . lastMessageId
@@ -23,16 +31,17 @@ export function startThreadCheckCron(client: Client) {
23
31
const inactiveFor = lastMessage ? Date . now ( ) - lastMessage . createdTimestamp : Infinity
24
32
25
33
// 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)
28
36
29
37
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 } ` )
31
40
32
41
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
+ } )
36
45
37
46
await thread . send ( { embeds : [ embed ] } )
38
47
await thread
@@ -53,7 +62,8 @@ export function startThreadCheckCron(client: Client) {
53
62
)
54
63
55
64
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 } ` )
57
67
await thread . send ( warningMsg ) . catch ( ( ) => { } )
58
68
}
59
69
}
0 commit comments