@@ -82,6 +82,9 @@ ${owner} This thread is for your question; when it's resolved, please type \`!cl
82
82
See <#${ howToGetHelpChannel } > for info on how to get better help.
83
83
` ;
84
84
85
+ // The rate limit for thread naming is 2 time / 10 mins, tracked per thread
86
+ const titleSetCooldown = 5 * 60 * 1000 ;
87
+
85
88
export class HelpThreadModule extends Module {
86
89
@listener ( { event : 'messageCreate' } )
87
90
async onNewQuestion ( msg : Message ) {
@@ -256,13 +259,33 @@ export class HelpThreadModule extends Module {
256
259
) ;
257
260
if ( ! title )
258
261
return sendWithMessageOwnership ( msg , ':warning: Missing title' ) ;
259
- let username = msg . member ?. nickname ?? msg . author . username ;
260
- if ( msg . channel . name !== username )
262
+ const thread = msg . channel ;
263
+ const threadData = ( await HelpThread . findOne ( thread . id ) ) ! ;
264
+ if (
265
+ msg . author . id !== threadData . ownerId &&
266
+ ! msg . member ! . roles . cache . has ( trustedRoleId )
267
+ )
268
+ return sendWithMessageOwnership (
269
+ msg ,
270
+ ':warning: Only the asker and helpers can set the title' ,
271
+ ) ;
272
+ const titleSetAllowedAfter =
273
+ + ( threadData . titleSetTimestamp ?? 0 ) + titleSetCooldown ;
274
+ if ( threadData . titleSetTimestamp && Date . now ( ) < titleSetAllowedAfter )
261
275
return sendWithMessageOwnership (
262
276
msg ,
263
- ':warning: Already set thread name' ,
277
+ `:warning: You can set the title again <t:${ Math . ceil (
278
+ titleSetAllowedAfter / 1000 ,
279
+ ) } :R>`,
264
280
) ;
265
- msg . channel . setName ( `${ username } - ${ title } ` ) ;
281
+ const owner = await msg . guild ! . members . fetch ( threadData . ownerId ) ;
282
+ const username = owner . nickname ?? owner . user . username ;
283
+ await Promise . all ( [
284
+ HelpThread . update ( thread . id , {
285
+ titleSetTimestamp : Date . now ( ) + '' ,
286
+ } ) ,
287
+ msg . channel . setName ( `${ username } - ${ title } ` ) ,
288
+ ] ) ;
266
289
}
267
290
268
291
@command ( )
0 commit comments