File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export class HelpChanModule extends Module {
6767 . setDescription ( DORMANT_MESSAGE ) ;
6868
6969 busyChannels : Set < string > = new Set ( ) ; // a lock to eliminate race conditions
70- ongoingEmptyTimeouts : Set < string > = new Set ( ) ; // a lock used to prevent multiple timeouts running on the same channel
70+ ongoingEmptyTimeouts : Map < string , NodeJS . Timeout > = new Map ( ) ; // a lock used to prevent multiple timeouts running on the same channel
7171
7272 private getChannelName ( guild : Guild ) {
7373 const takenChannelNames = guild . channels . cache
@@ -118,17 +118,18 @@ export class HelpChanModule extends Module {
118118 }
119119
120120 async startEmptyTimeout ( channel : TextChannel ) {
121- if ( this . ongoingEmptyTimeouts . has ( channel . id ) ) return ;
121+ const existingTimeout = this . ongoingEmptyTimeouts . get ( channel . id ) ;
122+ if ( existingTimeout ) clearTimeout ( existingTimeout ) ;
122123
123- this . ongoingEmptyTimeouts . add ( channel . id ) ;
124-
125- setTimeout ( async ( ) => {
124+ const timeout = setTimeout ( async ( ) => {
126125 this . ongoingEmptyTimeouts . delete ( channel . id ) ;
127126
128127 if ( await this . checkEmptyOngoing ( channel ) ) {
129128 await this . markChannelAsDormant ( channel ) ;
130129 }
131130 } , ongoingEmptyTimeout ) ;
131+
132+ this . ongoingEmptyTimeouts . set ( channel . id , timeout ) ;
132133 }
133134
134135 @listener ( { event : 'messageDelete' } )
You can’t perform that action at this time.
0 commit comments