Skip to content

Commit e43536c

Browse files
committed
restart timeout
1 parent f2cb590 commit e43536c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/modules/helpchan.ts

+6-5
Original file line numberDiff line numberDiff 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' })

0 commit comments

Comments
 (0)