@@ -364,19 +364,27 @@ export class HelpChanModule extends Module {
364
364
else askHelpChannel . send ( newMessageText ) ;
365
365
}
366
366
367
+ private async getChannelMember ( channel : TextChannel ) {
368
+ return (
369
+ HelpUser . findOneOrFail ( {
370
+ channelId : channel . id ,
371
+ } )
372
+ . then ( helpUser => {
373
+ // Clear from the cache in case they've left the server
374
+ channel . guild . members . cache . delete ( helpUser . userId ) ;
375
+ return channel . guild . members . fetch ( {
376
+ user : helpUser . userId ,
377
+ } ) ;
378
+ } )
379
+ // Do nothing, member left the guild
380
+ . catch ( ( ) => undefined )
381
+ ) ;
382
+ }
383
+
367
384
private async markChannelAsDormant ( channel : TextChannel ) {
368
385
this . busyChannels . add ( channel . id ) ;
369
386
370
- const memberPromise = HelpUser . findOneOrFail ( {
371
- channelId : channel . id ,
372
- } )
373
- . then ( helpUser =>
374
- channel . guild . members . fetch ( {
375
- user : helpUser . userId ,
376
- } ) ,
377
- )
378
- // Do nothing, member left the guild
379
- . catch ( ( ) => undefined ) ;
387
+ const memberPromise = this . getChannelMember ( channel ) ;
380
388
381
389
const pinnedPromise = channel . messages . fetchPinned ( ) ;
382
390
@@ -411,13 +419,23 @@ export class HelpChanModule extends Module {
411
419
412
420
private async checkDormantPossibilities ( ) {
413
421
for ( const channel of this . getOngoingChannels ( ) ) {
414
- const messages = await channel . messages . fetch ( ) ;
422
+ const [ messages , member ] = await Promise . all ( [
423
+ channel . messages . fetch ( ) ,
424
+ this . getChannelMember ( channel ) ,
425
+ ] ) ;
415
426
416
427
const diff =
417
428
Date . now ( ) - ( messages . first ( ) ?. createdAt . getTime ( ) ?? 0 ) ;
418
429
419
- if ( diff > dormantChannelTimeout )
430
+ if ( ! member ) {
431
+ await channel . send (
432
+ 'Asker has left the server, closing channel...' ,
433
+ ) ;
434
+ }
435
+ if ( ! member || diff > dormantChannelTimeout ) {
420
436
await this . markChannelAsDormant ( channel ) ;
437
+ continue ;
438
+ }
421
439
}
422
440
}
423
441
0 commit comments