@@ -85,6 +85,9 @@ See <#${howToGetHelpChannel}> for info on how to get better help.
85
85
// The rate limit for thread naming is 2 time / 10 mins, tracked per thread
86
86
const titleSetCooldown = 5 * 60 * 1000 ;
87
87
88
+ // Delay before fully closing the thread, in case of hasty closing
89
+ const threadCloseDelay = 60 * 1000 ;
90
+
88
91
export class HelpThreadModule extends Module {
89
92
@listener ( { event : 'messageCreate' } )
90
93
async onNewQuestion ( msg : Message ) {
@@ -95,7 +98,6 @@ export class HelpThreadModule extends Module {
95
98
name : msg . member ?. nickname ?? msg . author . username ,
96
99
autoArchiveDuration : ThreadAutoArchiveDuration . OneDay ,
97
100
} ) ;
98
- thread . setLocked ( true ) ;
99
101
thread . send ( helpThreadWelcomeMessage ( msg . member ! ) ) ;
100
102
await HelpThread . create ( {
101
103
threadId : thread . id ,
@@ -110,8 +112,8 @@ export class HelpThreadModule extends Module {
110
112
async onThreadExpire ( thread : ThreadChannel ) {
111
113
if (
112
114
! this . isHelpThread ( thread ) ||
113
- this . manuallyArchivedThreads . delete ( thread . id ) ||
114
- ! ( ( await thread . fetch ( ) ) as ThreadChannel ) . archived
115
+ ! ( ( await thread . fetch ( ) ) as ThreadChannel ) . archived ||
116
+ this . manuallyArchivedThreads . delete ( thread . id )
115
117
)
116
118
return ;
117
119
await thread . send ( { embeds : [ threadExpireEmbed ] } ) ;
@@ -129,13 +131,31 @@ export class HelpThreadModule extends Module {
129
131
':warning: This can only be run in a help thread' ,
130
132
) ;
131
133
132
- const threadData = ( await HelpThread . findOne ( msg . channel . id ) ) ! ;
134
+ let thread : ThreadChannel = msg . channel ;
135
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
133
136
134
137
if (
135
138
threadData . ownerId === msg . author . id ||
136
139
msg . member ?. permissions . has ( 'MANAGE_MESSAGES' )
137
140
) {
138
- await this . closeThread ( msg . channel ) ;
141
+ await msg . react ( '✅' ) ;
142
+ this . manuallyArchivedThreads . add ( thread . id ) ;
143
+ await thread . setArchived ( true ) ;
144
+ thread = ( await thread . fetch ( ) ) as ThreadChannel ;
145
+ let archiveTimestamp = thread . archiveTimestamp ;
146
+ setTimeout ( async ( ) => {
147
+ thread = ( await thread . fetch ( ) ) as ThreadChannel ;
148
+ console . log (
149
+ thread . archived ,
150
+ thread . archivedAt ,
151
+ archiveTimestamp ,
152
+ ) ;
153
+ if (
154
+ thread . archived &&
155
+ thread . archiveTimestamp == archiveTimestamp
156
+ )
157
+ this . closeThread ( thread ) ;
158
+ } , threadCloseDelay ) ;
139
159
} else {
140
160
return await sendWithMessageOwnership (
141
161
msg ,
@@ -145,8 +165,9 @@ export class HelpThreadModule extends Module {
145
165
}
146
166
147
167
private async closeThread ( thread : ThreadChannel ) {
168
+ if ( thread . archived ) await thread . setArchived ( false ) ;
148
169
this . manuallyArchivedThreads . add ( thread . id ) ;
149
- await thread . setArchived ( true ) ;
170
+ await thread . edit ( { archived : true , locked : true } ) ;
150
171
await HelpThread . delete ( thread . id ) ;
151
172
}
152
173
0 commit comments